facett-core 0.1.19

facett — visual kernel: render a node/edge Scene into egui (wgpu fast path to come)
Documentation
//! **`gpu_probe`** — print, as data, exactly which GPU facett would render on.
//!
//! Run: `cargo run -p facett-core --features wgpu --example gpu_probe`
//!
//! It prints three things:
//!
//! 1. **the full enumeration** — every adapter wgpu can see, with the policy's
//!    score, so a BMC / software entry is visible even when it loses;
//! 2. **what the OLD naive calls returned** — `request_adapter` with
//!    `PowerPreference::default()` (what every headless probe in this workspace
//!    used to do) and with `HighPerformance` (what eframe defaults to). This is
//!    the "which adapter was facett REALLY using" measurement;
//! 3. **what the policy chooses**, plus the `state_json` fragment a robot reads.
//!
//! This is the reproducible evidence behind
//! `.nornir/gpu-adapter-selection-design.md`.

fn main() {
    #[cfg(not(feature = "wgpu"))]
    {
        eprintln!("build with --features wgpu");
    }
    #[cfg(feature = "wgpu")]
    run();
}

#[cfg(feature = "wgpu")]
fn run() {
    use facett_core::render::adapter::{adapter_score, AdapterSelection};
    use facett_core::render::gpu::adapter_wgpu::{facts_of, facts_of_all, preferred_backends};

    let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
        backends: preferred_backends(),
        flags: wgpu::InstanceFlags::from_build_config().with_env(),
        backend_options: wgpu::BackendOptions::from_env_or_default(),
        memory_budget_thresholds: wgpu::MemoryBudgetThresholds::default(),
        display: None,
    });

    let adapters = pollster::block_on(instance.enumerate_adapters(preferred_backends()));
    let facts = facts_of_all(&adapters);
    println!("== ENUMERATED {} adapter(s) ==", facts.len());
    for (i, f) in facts.iter().enumerate() {
        println!("  [{i}] score={:6}  {}", adapter_score(f), f.describe());
    }

    for (label, pref) in [
        ("request_adapter(PowerPreference::default())", wgpu::PowerPreference::default()),
        ("request_adapter(HighPerformance)", wgpu::PowerPreference::HighPerformance),
        ("request_adapter(LowPower)", wgpu::PowerPreference::LowPower),
    ] {
        let got = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
            power_preference: pref,
            force_fallback_adapter: false,
            compatible_surface: None,
        }));
        match got {
            Ok(a) => println!("== OLD PATH {label} -> {}", facts_of(&a.get_info()).describe()),
            Err(e) => println!("== OLD PATH {label} -> ERROR {e:?}"),
        }
    }

    match AdapterSelection::decide(&facts, facett_core::render::adapter::env_override().as_deref())
    {
        Some(sel) => {
            println!("== POLICY -> {}", sel.banner());
            println!(
                "== state_json:\n{}",
                serde_json::to_string_pretty(&sel.to_json()).unwrap_or_default()
            );
        }
        None => println!("== POLICY -> no adapters at all"),
    }
}