Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-graph/tests/gpu_cloud_lane.rs

//! **graph2d on the shared GPU cloud lane, on a real adapter** (lane A item 2, 2026-09-29).
//!
//! The host installs facett-core's cloud renderer on its `RenderState` (what
//! `facet-wrapped`'s `install_gpu_lanes` does in the browser); a `GraphView` with
//! `with_gpu(true)` must then say `lane_flag: gpu`, `gpu: installed`, and the frame must
//! carry the node colours the GPU drew. Needs a GPU adapter (run on loki):
//!
//! ```bash
//! cargo test -p facett-graph --features wgpu --test gpu_cloud_lane
//! ```
#![cfg(feature = "wgpu")]

use egui_kittest::Harness;
use egui_kittest::wgpu::{WgpuTestRenderer, create_render_state};
use facett_core::{Facet, Scene};
use facett_graph::GraphView;

#[test]
fn graph2d_draws_its_cloud_on_the_gpu_when_the_host_installed_the_renderer() {
    // facett's adapter POLICY (the same selector every facett host uses), not kittest's
    // default setup: measured on the t14s 2026-09-29, the default handed out llvmpipe
    // while a Radeon 880M sat idle, which would prove the lane on a CPU rasteriser.
    let rs = create_render_state(facett_core::render::gpu::facett_wgpu_options().wgpu_setup, Default::default());
    let info = rs.adapter.get_info();
    eprintln!("adapter: {:?} ({:?})", info.name, info.device_type);
    assert_ne!(format!("{:?}", info.device_type), "Cpu", "a software adapter is not a GPU: {}", info.name);
    facett_core::render::gpu::graphcloud::cloud::install_cloud_renderer(&rs);

    let mut scene = Scene::new();
    let red = egui::Color32::from_rgb(255, 40, 40);
    for i in 0..24 {
        scene.node(format!("n{i}"), red);
    }
    for i in 1..24 {
        scene.edge(0, i);
    }
    let mut view = GraphView::new(scene).with_gpu(true);
    let mut h = Harness::builder()
        .with_size(egui::vec2(600.0, 400.0))
        .renderer(WgpuTestRenderer::from_render_state(rs))
        .build_ui_state(|ui, v: &mut GraphView| v.ui(ui), view);
    h.run_steps(3);
    let img = h.render().expect("a wgpu frame");
    view = std::mem::replace(h.state_mut(), GraphView::new(Scene::new()));
    let lane = &view.state_json()["lane"];
    eprintln!("lane: {lane}");
    assert_eq!(lane["gpu"], "installed");
    assert_eq!(lane["lane_flag"], "gpu", "the cloud went to the GPU: {lane}");
    assert_eq!(lane["gpu_cloud"], true);
    // The GPU lane drew the discs: strongly red pixels exist (the egui painter was skipped
    // for them, so they can only have come from the instanced callback).
    let reddish = img.pixels().filter(|p| p[0] > 150 && u16::from(p[0]) > u16::from(p[1]) + 80).count();
    eprintln!("red pixels: {reddish}");
    assert!(reddish > 100, "the GPU cloud painted the nodes: {reddish} red pixels");
    let frames = facett_core::render::lane::frames_of("facett_core::render::gpu::graphcloud::cloud::CloudRenderer");
    assert!(frames > 0, "the cloud renderer encoded no frame");
}