Repository navigation
Shaders: cache HLSL mesh compute passes in ShaderCache and translated/v2 - #2040
Conversation
Route both the direct-DXIL path (including its HLSL fallback) and the default HLSL path of console_mesh through ShaderCache, shader_flight coalescing, and translated/v2 under Stage::Mesh. Previously only successful XCL_DIRECT_DXIL=1 mesh translations were cached, so default HLSL builds and direct-DXIL fallbacks re-translated and re-compiled the mesh compute pass on every (MS, PS) pairing. Part of xcl-dev#1269 Assisted-by: Antigravity (Gemini 4 Neon)
|
Diff audit passed on Remaining before merge: one independent AMD verification pass on |
|
Independent AMD check of exact Tested Windows 10 Home 19045, Ryzen 7 7800X3D, AMD Radeon(TM) Graphics iGPU driver The committed cache test never dispatches a shader. The added probe wraps a public synthetic NGG program in the same container helper, then calls
Not tested Full workspace suite, parent baseline, retail smoke/gameplay, rasterization of the returned mesh shader, concurrent compile coalescing under load, forced direct-to-HLSL fallback, discrete AMD or NVIDIA in this pass. These are compute-record checks, not pixel-output checks. No cold-driver PSO, peak-memory, or general speedup claim: the diagnostic wall timers include cache lookup and pass-through compilation, and the DXC/driver caches were not cleared. The explicit temporary translated-cache directory was fresh per probe; the wrapper's AI use — Codex (GPT-6) inspected the code, wrote this test-only probe using the project's existing synthetic NGG fixture pattern, ran native Windows checks, verified hashes/output, and drafted the report. Local test-only reproduction patch (one file)diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs
index 9b5a305..254271d 100644
--- a/crates/xcl/src/gpu/recomp/pso.rs
+++ b/crates/xcl/src/gpu/recomp/pso.rs
@@ -1392,13 +1392,17 @@ mod shader_cache_tests {
}
fn synthetic_mesh_container() -> Vec<u8> {
- use crate::gpu::xbox::tests::{container, dxil_part, fssm, CODE};
+ synthetic_mesh_code_container(&crate::gpu::xbox::tests::CODE, 32)
+ }
+
+ fn synthetic_mesh_code_container(code: &[u8], threads: u32) -> Vec<u8> {
+ use crate::gpu::xbox::tests::{container, dxil_part, fssm};
let mut psv_r = vec![0u8; 48];
psv_r[12..14].copy_from_slice(&3u16.to_le_bytes()); // max_vertices
psv_r[14..16].copy_from_slice(&1u16.to_le_bytes()); // max_primitives
psv_r[24] = 13; // mesh
psv_r[27] = 2; // triangles
- psv_r[36..40].copy_from_slice(&32u32.to_le_bytes());
+ psv_r[36..40].copy_from_slice(&threads.to_le_bytes());
psv_r[40..44].copy_from_slice(&1u32.to_le_bytes());
psv_r[44..48].copy_from_slice(&1u32.to_le_bytes());
let mut psv0 = 48u32.to_le_bytes().to_vec();
@@ -1416,7 +1420,7 @@ mod shader_cache_tests {
}
osg1.extend_from_slice(name);
- let f = fssm(&CODE, &[(7, 0)]);
+ let f = fssm(code, &[(7, 0)]);
container(&[
(b"SFI0", &[0; 8]),
(b"HASH", &[0; 20]),
@@ -1426,6 +1430,61 @@ mod shader_cache_tests {
])
}
+ #[test]
+ fn gpu_cached_mesh_compute_records_match() {
+ use super::super::{runner, MESH_HEADER};
+ use crate::gpu::rdna2::encode;
+ use std::sync::atomic::{AtomicUsize, Ordering};
+ // Local diagnostic: fail rather than silently skip the requested GPU verification.
+ println!("MESH_CACHE adapter={} native64={:?} mesh={:?}", runner::adapter().unwrap(), runner::wave64_supported(), runner::mesh_shaders_supported());
+ let split = runner::split_wave64();
+ let mut code = Vec::new();
+ let mut op = |n, e, f: &[(&str, u64)], l| code.extend(encode(n, e, f, l).unwrap());
+ op("V_MBCNT_LO_U32_B32", "ENC_VOP3", &[("VDST", 0), ("SRC0", 193), ("SRC1", 128)], None);
+ op("V_MBCNT_HI_U32_B32", "ENC_VOP3", &[("VDST", 0), ("SRC0", 193), ("SRC1", 256)], None);
+ op("S_MOV_B32", "ENC_SOP1", &[("SDST", 124), ("SSRC0", 255)], Some(1 << 12 | 3));
+ op("S_SENDMSG", "ENC_SOPP", &[("SIMM16", 9)], None);
+ op("V_CMPX_GT_U32", "ENC_VOPC", &[("SRC0", 131), ("VSRC1", 0)], None);
+ op("BUFFER_LOAD_DWORDX4", "ENC_MUBUF", &[("VDATA", 10), ("VADDR", 0), ("SRSRC", 4), ("SOFFSET", 128), ("IDXEN", 1)], None);
+ op("EXP", "ENC_EXP", &[("TGT", 12), ("EN", 15), ("VSRC0", 10), ("VSRC1", 11), ("VSRC2", 12), ("VSRC3", 13), ("DONE", 1)], None);
+ op("S_ENDPGM", "ENC_SOPP", &[], None);
+ let blob = synthetic_mesh_code_container(&code, 64);
+ let dir = std::env::temp_dir().join(format!("xcl-mesh-gpu-cache-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ let cache = Mutex::new(ShaderCache::new(64 << 20));
+ let cold = Mutex::new(ShaderCache::new(64 << 20));
+ let compiles = AtomicUsize::new(0);
+ let positions = [[-1.0f32, -1.0, 0.0, 1.0], [-1.0, 1.0, 0.0, 1.0], [0.0, -1.0, 0.0, 1.0]];
+ let mut mem = vec![0u32; 256];
+ for (v, pos) in positions.iter().enumerate() {
+ for (c, value) in pos.iter().enumerate() { mem[0x40 + 4 * v + c] = value.to_bits(); }
+ }
+ let mut state = runner::KernelState::default();
+ state.sgpr[16..20].copy_from_slice(&[0x100, 16 << 16, 3, 0]);
+ let mut first = None;
+ for (label, c) in [("first", &cache), ("ram", &cache), ("disk", &cold)] {
+ let start = std::time::Instant::now();
+ let pass = console_mesh_with(&blob, None, split, 1, &dir, c, |code, ms, wave64| {
+ assert!(wave64);
+ compiles.fetch_add(1, Ordering::SeqCst);
+ compile_console_mesh(&blob, code, ms, wave64, 1, split)
+ }).unwrap();
+ println!("MESH_CACHE {label} build_ms={:.3} compiles={} cs_bytes={}", start.elapsed().as_secs_f64()*1000.0, compiles.load(Ordering::SeqCst), pass.cs.len());
+ assert_eq!(compiles.load(Ordering::SeqCst), 1);
+ let out = runner::run(&pass.cs, &state, &mem).unwrap();
+ assert_eq!(&out.raw[..2], &[3, 1]);
+ for (v, pos) in positions.iter().enumerate() {
+ for (c, value) in pos.iter().enumerate() {
+ assert_eq!(out.raw[MESH_HEADER + v * pass.record.vert_dwords() + c], value.to_bits(), "{label} vertex {v} component {c}");
+ }
+ }
+ let record = out.raw[..pass.record.record_dwords()].to_vec();
+ if let Some((ref dxil, ref raw)) = first { assert_eq!(&pass.cs, dxil); assert_eq!(&record, raw); }
+ else { first = Some((pass.cs, record)); }
+ }
+ let _ = std::fs::remove_dir_all(&dir);
+ }
+
#[test]
fn console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk() {
use std::sync::atomic::{AtomicUsize, Ordering}; |
Part of #1269. Route the default HLSL path (and
XCL_DIRECT_DXIL=1HLSL fallback) ofconsole_meshthroughShaderCache,shader_flightcompile coalescing, and thetranslated/v2disk cache underStage::Mesh.After #1836,
console_meshcached its compute pass only inside theXCL_DIRECT_DXIL=1direct-translation branch. On the default HLSL path and on any direct-DXIL fallback, every(MS, PS)pipeline pairing sharing a mesh shader still re-rantranslate_meshanddxc::compile_cachedwithout touchingShaderCacheortranslated/v2. Unifying both paths throughcompile_console_mesh+console_mesh_withmatchescompile_console_shader's caching behaviour (withBackend::current()keeping HLSL and direct-DXIL disk entries in separatetranslated/v2namespaces).What is in it
crates/xcl/src/gpu/recomp/pso.rs:finish_two_pass_compiled(shared byfinish_two_passandconsole_mesh_with) andcompile_console_mesh(handlingXCL_DIRECT_DXIL=1withdxc::defer()and HLSL fallback, plus the default HLSL path).console_meshthroughconsole_mesh_withso both direct-DXIL and HLSL mesh compute passes shareShaderCache,shader_flightcoalescing, andtranslated/v2(Stage::Mesh) across(MS, PS)pairings.console_mesh_caches_hlsl_compute_pass_in_memory_and_on_diskusing a synthetic console MS container (PSV0kind 13 +OSG1SV_Position+ NGGFSSMhw 7) to verify in-memory cache reuse, cold-RAMtranslated/v2disk reuse, anddxc::cached_onlyhit on the publicconsole_meshentry point.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09)stable-x86_64-pc-windows-msvc, Windows SDK DXC 1.8.2502.11 (debug for workspace build/tests, release forsmoke.ps1).cargo build --workspace: ok.cargo test -p xcl --lib gpu::recomp::pso -- --test-threads=1at4b0af47: 16 passed, 0 failed, 1 ignored (0 skipped).cargo test --workspace -- --test-threads=4 --skip fuzz_validate_and_gpuat4b0af47: 1091 passed, 0 failed, 46 ignored across all workspace targets (xcllib:1042 passed, 0 failed, 26 ignored; integration + e2e targets:49 passed, 0 failed, 20 ignored, includinge2e:3/0/0).SKIPPEDon this adapter (wave32-only, Developer Mode off,XCL_HEAP_WINDOWSunset): wave64-only GPU tests (gpu::recomp::lower,gpu::recomp::lower_dxil,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware), per-lane wave32 f16/f32 conversion refusals,shaders::tests::pso_measurement_compiles_an_exact_synthetic_record, andheap_window_out_of_memory_falls_back_to_the_switch_form.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_{0..3}due to the pre-existing RTX 500x8007000ECreateComputePipelineStatefailure tracked by DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905.scripts/smoke.ps1release build at4b0af47vsmain(bf9eebd).Regression run
Not tested
XCL_DIRECT_DXIL=1fallback caching under a retail shader pack, Wine / Linux, and gameplay beyond the 60 s smoke window (the 60 s startup run does not isolate mesh-pipeline compile time).AI use
scripts/smoke.ps1regression runs were executed on the hardware listed above.