Fix the startup crash on D3D12 with FXC: CPU fallback for the tessellation pipeline, FXC-friendly shader (#1098) (#1099)

* GPU tessellation: a pipeline the device cannot build falls back to CPU meshing instead of crashing (#1098)

Build the tessellation compute pipeline inside error scopes; TessGpu::new returns an error,
and the viewport logs it and meshes bodies on the CPU. A Windows CI job builds the pipeline
with D3D12's FXC on the WARP adapter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Tessellation shader: basis functions in one-dimensional local arrays, so D3D12's FXC compiles it (#1098)

FXC has to unroll loops that write an array inside a struct (Basis.n0/n1) or a 2-D array
(ndu) by a counter, and cannot with run-time trip counts (X3511). A2.2 basis functions in a
local 1-D array returned whole; derivatives from the degree p-1 functions; the pole step
offsets computed rather than indexed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bherbruckandClaude Opus 5.5 authored and GitHub committed 2026-10-14 10:40:24 -04:00
1 parent a6928abf48
commit ec64564f21
9 files changed
+329 -86

No files matched your search

+43 -3
View File
@@ -3316,8 +3316,8 @@ mod tests {
let proj = projection(&app, rect);
let e = proj.cam.eye().to_f32();
let eye = [e[0], e[1], e[2], if proj.cam.fov > 0.0 { 1.0 } else { 0.0 }];
let planned = scene.planned.len();
(planned, scene.tris.len(), crate::gpu::render_offscreen(scene, None, proj.vp.to_f32(), proj.cam.back().to_f32(), eye, SIZE, tess))
let (planned, shader) = (scene.planned.len(), tess.then_some(solidcraft_gpu::SHADER));
(planned, scene.tris.len(), crate::gpu::render_offscreen(scene, None, proj.vp.to_f32(), proj.cam.back().to_f32(), eye, SIZE, shader))
};
let (planned, gpu_tris, gpu) = render(true);
let (none, cpu_tris, cpu) = render(false);
@@ -3335,6 +3335,45 @@ mod tests {
assert!(differ * 100 < drawn, "{differ} of {drawn} model pixels differ");
}
/// A device that cannot build the tessellation pipeline (D3D12's FXC rejected the shader
/// at startup and the app panicked) still shows the model: the failure is caught, logged,
/// and bodies are built on the CPU and drawn. A shader the device rejects stands in for FXC.
/// Skipped without a GPU adapter.
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn bodies_are_built_on_the_cpu_when_the_tessellation_pipeline_fails() {
const REJECTED: &str = "
@group(0) @binding(1) var<storage, read_write> surfaces: array<u32>;
@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) gid: vec3<u32>) { surfaces[gid.x] = 1u; }
";
let Some(tess) = crate::gpu::offscreen_tessellates(REJECTED) else {
eprintln!("skipping: no GPU adapter");
return;
};
assert!(!tess, "the rejected shader built a pipeline");
let mut s = solidcraft_engine::Session::default();
s.run_script(&solidcraft_engine::sample::script()).unwrap();
let mut app = SolveApp::new(s, crate::Services::default());
app.viewport.no_pixels = true;
app.fit_view();
app.viewport.gpu = Some(GpuTarget { format: egui_wgpu::wgpu::TextureFormat::Rgba8Unorm, depth: None, samples: 1, tess });
const SIZE: u32 = 256;
let rect = Rect::from_min_size(Pos2::ZERO, vec2(SIZE as f32, SIZE as f32));
let scene = build_scene(&app);
assert!(scene.planned.is_empty(), "no body waits for the GPU evaluation");
assert!(!scene.tris.is_empty(), "the bodies are meshed on the CPU");
let proj = projection(&app, rect);
let e = proj.cam.eye().to_f32();
let eye = [e[0], e[1], e[2], if proj.cam.fov > 0.0 { 1.0 } else { 0.0 }];
let Some(img) = crate::gpu::render_offscreen(scene, None, proj.vp.to_f32(), proj.cam.back().to_f32(), eye, SIZE, Some(REJECTED)) else {
return;
};
let n = (SIZE * SIZE) as usize;
let drawn = img.chunks(4).filter(|p| p[..3] != [255, 255, 255]).count();
assert!(drawn > n / 20, "the model is drawn: {drawn} pixels");
}
/// A hovered face lights solidly over a body drawn from its display plan on the GPU: the
/// highlight uses the plan's triangles, not the reference mesh's other triangulation of the
/// same face, which fought the model at equal depth and shimmered in wedges. Every face of a
@@ -3362,7 +3401,8 @@ mod tests {
let proj = projection(&app, rect);
let e = proj.cam.eye().to_f32();
let eye = [e[0], e[1], e[2], if proj.cam.fov > 0.0 { 1.0 } else { 0.0 }];
crate::gpu::render_offscreen(scene, Some(highlight), proj.vp.to_f32(), proj.cam.back().to_f32(), eye, SIZE, tess)
let shader = tess.then_some(solidcraft_gpu::SHADER);
crate::gpu::render_offscreen(scene, Some(highlight), proj.vp.to_f32(), proj.cam.back().to_f32(), eye, SIZE, shader)
};
let lit = |plain: &[u8], hovered: &[u8]| -> Vec<bool> { plain.chunks(4).zip(hovered.chunks(4)).map(|(a, b)| a != b).collect() };
let (Some(gpu_plain), Some(cpu_plain)) = (render(true, None), render(false, None)) else {