Repository navigation
D3D12.X: cache direct-DXIL mesh shaders, coalesce shader builds, make MS/GS lazy, and cache two-pass/graphics PSO blobs - #1836
Conversation
|
Regression run for this PR: head main this PR: No device removals or crashes; 101 % of main's frames, 90 % of its peak commit. Not tested: the whole suite; world loading with this PR; whether the title reaches all of the changed code in these 60 s (default settings, so the direct DXIL path is off). Written with Claude Code (Claude Opus 5.5) from runs on this machine. |
|
I found a deterministic cache-key miss on exact head I added a 20-line synthetic regression that sets only those two padding bytes differently and checks the descriptors' semantic fields are equal. On unchanged #1836 + test, Windows returned 0 passed / 1 failed / 0 ignored as expected (key hashes I also ran a matched desktop-session RTX 3090 full workspace pair, This verifies cache-key identity and the broader synthetic suite; it does not measure a cold/warm graphics PSO driver hit, compilation-time improvement, or retail rendering. The PR author still needs the required exact-head smoke after integrating any runtime change. I have kept the patch local for your PR rather than opening a competing one. One-file patch (34 insertions, 1 deletion)diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs
index c16dc82..7e94dec 100644
--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -4259,7 +4259,18 @@ unsafe fn graphics_blob_key(
feed_pod(&mut h, ©.BlendState as *const _ as *const u8, std::mem::size_of::<D3D12_BLEND_DESC>());
feed_u32(&mut h, copy.SampleMask);
feed_pod(&mut h, ©.RasterizerState as *const _ as *const u8, std::mem::size_of::<D3D12_RASTERIZER_DESC>());
- feed_pod(&mut h, ©.DepthStencilState as *const _ as *const u8, std::mem::size_of::<D3D12_DEPTH_STENCIL_DESC>());
+ let depth = ©.DepthStencilState;
+ feed_u32(&mut h, depth.DepthEnable.0 as u32);
+ feed_u32(&mut h, depth.DepthWriteMask.0 as u32);
+ feed_u32(&mut h, depth.DepthFunc.0 as u32);
+ feed_u32(&mut h, depth.StencilEnable.0 as u32);
+ feed(&mut h, &[depth.StencilReadMask, depth.StencilWriteMask]);
+ for face in [&depth.FrontFace, &depth.BackFace] {
+ feed_u32(&mut h, face.StencilFailOp.0 as u32);
+ feed_u32(&mut h, face.StencilDepthFailOp.0 as u32);
+ feed_u32(&mut h, face.StencilPassOp.0 as u32);
+ feed_u32(&mut h, face.StencilFunc.0 as u32);
+ }
feed_u32(&mut h, copy.InputLayout.NumElements);
if copy.InputLayout.NumElements > 0 && !copy.InputLayout.pInputElementDescs.is_null() {
let elems = std::slice::from_raw_parts(copy.InputLayout.pInputElementDescs, copy.InputLayout.NumElements as usize);
@@ -4296,6 +4307,28 @@ unsafe fn graphics_blob_key(
mod graphics_blob_tests {
use super::*;
+ #[test]
+ fn graphics_blob_key_ignores_depth_stencil_padding() {
+ unsafe {
+ let mut a = D3D12_GRAPHICS_PIPELINE_STATE_DESC::default();
+ a.SampleDesc.Count = 1;
+ let mut b = a.clone();
+ let start = std::mem::offset_of!(D3D12_DEPTH_STENCIL_DESC, StencilWriteMask) + 1;
+ let end = std::mem::offset_of!(D3D12_DEPTH_STENCIL_DESC, FrontFace);
+ assert_eq!(end - start, 2);
+ let a_bytes = &mut a.DepthStencilState as *mut _ as *mut u8;
+ let b_bytes = &mut b.DepthStencilState as *mut _ as *mut u8;
+ std::ptr::write_bytes(a_bytes.add(start), 0, end - start);
+ std::ptr::write_bytes(b_bytes.add(start), 0xa5, end - start);
+ assert_eq!(a.DepthStencilState, b.DepthStencilState);
+ let ka = graphics_blob_key(&a, b"vs", Some(b"ps"), None, &[]);
+ let kb = graphics_blob_key(&b, b"vs", Some(b"ps"), None, &[]);
+ assert_eq!(ka, kb, "identical D3D12 states must share a driver-cache key");
+ b.DepthStencilState.DepthEnable = true.into();
+ assert_ne!(ka, graphics_blob_key(&b, b"vs", Some(b"ps"), None, &[]));
+ }
+ }
+
#[test]
fn graphics_blob_key_tracks_shaders_samplers_and_state() {
unsafe { |
… MS/GS lazy, and cache two-pass/graphics PSO blobs
c6c9825 to
04f34ce
Compare
|
@WebIdentity1 Thank you for catching that! You're completely right — Updated
|
|
Independent Windows check of 04f34ce on an RTX 3080 Ti (621.35), Windows 11 build 26300, Rust 1.99.1 MSVC, debug.
This run covered synthetic inputs. Retail world load and persistent cache hit rate were outside its scope. AI-assisted. Codex (GPT-6 family, exact variant unavailable) ran the tests and drafted this report. Graphics cache accounting follow-up on Two workers can both miss the same graphics PSO key before either acquires the insertion lock. I ran the original locked insertion with two synthetic results for one key. The map retained one 3-byte blob while the budget charged 5 bytes. That extra charge can cause later cache entries to be refused before the 256 MiB budget is actually used. The compute version is already tracked in #826. Graphics insertion on main A graphics-only local patch charges the bytes only when the key is vacant under the insertion lock. The new regression preserved the first blob and charged it once. Windows 11 build 26300, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC and DXC 1.8.2502.11. The offline locked release workspace build passed. AI-assisted. Codex (GPT-6 family, exact variant unavailable) prepared the local patch, ran the tests, and drafted this update. |
Hardware test report — commit
|
|
Test report for c6c9825 on NVIDIA. Tested
main: PR:
Not tested
AI use
|
|
@grahamster2 Thank you for running the 180 s RTX 3080 checks on
|
|
Test report: the graphics driver blobs on a 32-lane NVIDIA card, retail title, world load Tree: Hardware: NVIDIA GeForce RTX 4070 SUPER 12 GB (driver 616.92, 32-lane waves), Ryzen 7 5700X, 32 GB RAM, Windows 10 22H2 (19045), release build. Tests: Runs (same title, same scripted input, 420 s each, the same tree with and without this PR):
Without the PR the title's recording thread waited in Not tested: the PR's head alone, AMD, the HLSL path for compute ( AI use: Claude Code (Claude Opus 5.5) ran the builds, the tests and the runs, read the logs and wrote this report. |
Brings main to full parity with upstream/main (80f4819): - xcl-dev#1836: cache direct-DXIL mesh shaders, coalesce shader builds, make MS/GS lazy, and cache two-pass/graphics PSO blobs Conflict in crates/xcl/src/gpu/recomp/pso.rs resolved by keeping both xcl-dev#1836's Vertex|Pixel stage check + dxc::defer() guard and xcl-dev#1913's split_wave64 argument to direct_graphics. Assisted-by: Antigravity (Gemini 4)
Pulls in xcl-dev#1836 (graphics and two-pass PSO disk cache + lazy MS/GS + shader build coalescing), xcl-dev#1930 (DXIL CSE across discard), xcl-dev#1900, xcl-dev#1005, xcl-dev#1053, xcl-dev#1864, xcl-dev#1866, xcl-dev#1869, xcl-dev#1876, and xcl-dev#1898 while keeping our RDNA4 MSAA clamp (xcl-dev#1908), wave64 graphics Direct DXIL guard (xcl-dev#1913), atomic writable-range tracking, static-sampler cache keys, and 4M-group indirect dispatch clamp.
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
Speeds up PSO and direct-DXIL compilation throughput by caching direct-DXIL mesh shaders in
ShaderCache, coalescing concurrent identical shader builds, raisingShaderCache's entry cap to 4096 (bounded by the 64 MiB byte cap), making console MS/GS two-pass translation lazy on first use, and caching two-pass/graphics PSO driver blobs to disk.Part of #1269 and #1673.
What is in it
crates/xcl/src/gpu/recomp/pso.rs: addStage::Meshcaching toShaderCache, raiseSHADER_CACHE_MAX_ENTRIESto 4096 withcompact_lru, add per-ShaderKeyshader_flightcoalescing so concurrent threads share in-flight compilations, skip synchronous compilation whendxc::defer()is active during preload, and addshader_cache_coalesces_concurrent_same_key_compiles.crates/xcl/src/hle/d3d12x/real.rs: maketwo_pass_of/build_mesh_or_gstranslation lazy at first use instead of eagerly blocking preload, and addGRAPHICS_BLOBS(256 MiB bounded) + disk driver-blob caching (graphics_path,keep_graphics_blob,graphics_blob_key) alongsidekeep_compute_blob; hashD3D12_BLEND_DESC,D3D12_RASTERIZER_DESC, andD3D12_DEPTH_STENCIL_DESCfield-by-field (avoiding uninitialized struct padding bytes caught in review by @WebIdentity1), withgraphics_blob_key_tracks_shaders_samplers_and_stateandgraphics_blob_key_ignores_struct_padding_bytes.Tested
10.0.22631.0),rustc 1.99.1 (58cf8f9c3 2026-10-13), release & debug builds, rebased onto689f2db(04f34ce).04f34ce:cargo test -p xcl --lib hle::d3d12x::real::graphics_blob_tests: 2 passed, 0 failed (graphics_blob_key_ignores_struct_padding_bytes+graphics_blob_key_tracks_shaders_samplers_and_state);cargo test -p xcl --lib gpu::recomp::pso::: 14 passed, 0 failed; independent verification on RTX 3080 Ti (@thehollowedone:graphics_blob_key_2/2,shader_cache_coalesces_concurrent_same_key_compiles1/1,e2e3/3D3D12 debug-layer pass).c6c9825:cargo test -p xcl --test e2e -- --test-threads=1: 3 passed, 0 failed (0 D3D12 debug-layer errors), plus a clean RTX 3060 60 sscripts/smoke.ps1pair from @Anon64 (1493/1476frames,0removals/crashes).Regression run
main:
PR:
Not tested
04f34cepast the 60 s smoke window,scripts/smoke.ps1on NVIDIA or Intel GPUs on04f34ce, fullcargo test --workspacerun on04f34ce, wave32-only AMD adapters, and Linux/Wine/vkd3d-proton.AI use