Repository navigation
D3D12.X: preserve rect-list GS when a cached graphics PSO blob is stale - #2044
Conversation
Do not invoke retry_without_rect_gs while copy.CachedPSO is still attached: previously a stale cached graphics blob caused retry_without_rect_gs to wipe copy.GS before clearing CachedPSO, so the uncached retry dropped the rect-list GS even when the driver accepted it. Also skip caching the resulting blob under the with-GS key when a genuine rect-list GS fallback clears copy.GS. Part of xcl-dev#1269 Assisted-by: Antigravity (Gemini 4 Neon)
|
Code review on
|
|
Independent RTX 3090 and AMD iGPU driver/pixel verification of exact Tested Windows 10 Home 19045, Ryzen 7 7800X3D, Rust/Cargo 1.98.1 x64 MSVC, DXC/DXIL 1.8.2502.11, debug. GPUs selected explicitly by The local 99-line test-only overlay below calls the unchanged Identical results on both GPUs:
Commands:
All 317 source hashes matched before/after and the local worktree; XCL recompiled. Runtime source is unchanged; no competing implementation. Not tested Full workspace, retail smoke/gameplay, actual disk eviction/write wiring, the outer translated-console-PSO path and rectangle-PSO registration, genuine hardware rejection of a valid rectangle GS, debug-layer validation, or compile time/memory. The helper's scheduling/timing wrapper is a trivial test callback and eviction is counted, not performed against disk. The no-GS cache-eligibility fallback remains covered by the author's mock unit test, not a deliberately invalid GS on hardware. Existing full-suite/retail gates remain separate. The local diagnostic requires its GPU; it is not proposed unchanged for GPU-less CI. AI use — Codex (GPT-6) inspected the source, wrote this test-only driver/pixel probe using existing project helpers, ran both GPUs, verified traces/pixels/source hashes, and drafted this report. The runtime fix remains the PR author's work. Local reproduction patch, 99 test-only linesdiff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs
index 07bbaa1..1f7a374 100644
--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -4364,6 +4364,105 @@ unsafe fn graphics_blob_key(
mod graphics_blob_tests {
use super::*;
+ #[test]
+ fn gpu_stale_rect_blob_preserves_full_rectangle() {
+ use crate::gpu::recomp::{dxc, emit, pso, runner};
+ use windows::Win32::Graphics::Dxgi::Common::*;
+ unsafe {
+ // Local diagnostic: require the selected real adapter rather than silently skip.
+ let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap();
+ let selector = crate::gpu::adapter::Selector::from_env_or("auto");
+ let (adapter, desc) = crate::gpu::adapter::candidates(&factory, &selector).into_iter().next().unwrap();
+ println!("RECT_CACHE adapter={}", crate::gpu::adapter::name(&desc));
+ let dev = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0).unwrap();
+ let rs = pso::abi_root_signature(&dev, true).unwrap();
+ let vs = dxc::compile("float4 main(float4 p : POSITION) : SV_Position { return p; }", "main", "vs_6_6", &[]).unwrap();
+ let ps = dxc::compile("float4 main() : SV_Target { return float4(1, 0.25, 0.5, 1); }", "main", "ps_6_6", &[]).unwrap();
+ let outputs = [crate::gpu::dxbc::SigElement {
+ name: "SV_Position".into(), index: 0, system_value: 1, component_type: 3,
+ register: 0, mask: 15, rw_mask: 15, stream: 0,
+ }];
+ let gs = dxc::compile(&emit::rect_list_gs(&outputs), "main", "gs_6_6", &[]).unwrap();
+ let input = [D3D12_INPUT_ELEMENT_DESC {
+ SemanticName: PCSTR(b"POSITION\0".as_ptr()), Format: DXGI_FORMAT_R32G32B32A32_FLOAT,
+ InputSlotClass: D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, ..Default::default()
+ }];
+ let make_desc = || {
+ let mut d = D3D12_GRAPHICS_PIPELINE_STATE_DESC {
+ pRootSignature: std::mem::transmute_copy(&rs), VS: bytecode(&vs), PS: bytecode(&ps), GS: bytecode(&gs),
+ SampleMask: u32::MAX,
+ InputLayout: D3D12_INPUT_LAYOUT_DESC { pInputElementDescs: input.as_ptr(), NumElements: 1 },
+ PrimitiveTopologyType: D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, NumRenderTargets: 1,
+ SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, ..Default::default()
+ };
+ d.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL.0 as u8;
+ d.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
+ d.RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
+ d.RasterizerState.DepthClipEnable = true.into();
+ d.RTVFormats[0] = DXGI_FORMAT_R32G32B32A32_FLOAT;
+ d
+ };
+ let vertices = [-1.0f32, 1.0, 0.0, 1.0, -1.0, -1.0, 0.0, 1.0, 1.0, -1.0, 0.0, 1.0];
+ let clear = [0.0f32; 4];
+ let draw = |pipeline: &ID3D12PipelineState| runner::draw_on(&dev, pipeline, &rs, &vertices, 16, &[], &[], 16, clear).unwrap();
+ let stale = [0xABu8; 32];
+ let mut cached = Vec::new();
+ for label in ["fresh", "stale", "valid"] {
+ let blob = match label { "fresh" => None, "stale" => Some(stale.as_slice()), _ => Some(cached.as_slice()) };
+ let mut d = make_desc();
+ let mut pipeline = None;
+ let mut attempts = Vec::new();
+ let mut evictions = 0;
+ let build = create_graphics_pso_cached(&mut d, blob, true, || evictions += 1,
+ |_, _, f| (f(), std::time::Duration::ZERO),
+ |c| {
+ let hr = match dev.CreateGraphicsPipelineState::<ID3D12PipelineState>(c) {
+ Ok(p) => { pipeline = Some(p); 0 }, Err(e) => e.code().0,
+ };
+ attempts.push((!c.CachedPSO.pCachedBlob.is_null(), !c.GS.pShaderBytecode.is_null(), hr));
+ hr
+ });
+ println!("RECT_CACHE {label} attempts={attempts:?} evictions={evictions} reused={} eligible={}", build.reused, build.cache_eligible);
+ assert!(build.hr >= 0);
+ assert!(!d.GS.pShaderBytecode.is_null());
+ assert_eq!(evictions, usize::from(label == "stale"));
+ assert_eq!(build.reused, label == "valid");
+ assert_eq!(build.cache_eligible, label != "valid");
+ assert_eq!(attempts.len(), if label == "stale" { 2 } else { 1 });
+ if label == "stale" { assert!(attempts[0].2 < 0); assert_eq!(attempts[1], (false, true, 0)); }
+ let pipeline = pipeline.unwrap();
+ let pixels = draw(&pipeline);
+ assert!(pixels.iter().all(|p| *p == [1.0, 0.25, 0.5, 1.0]), "{label}: incomplete rectangle");
+ println!("RECT_CACHE {label} correct_pixels={}", pixels.len());
+ if label == "fresh" {
+ let b = pipeline.GetCachedBlob().unwrap();
+ cached = std::slice::from_raw_parts(b.GetBufferPointer() as *const u8, b.GetBufferSize()).to_vec();
+ assert!(!cached.is_empty());
+ }
+ }
+ // Replay the old retry ordering; this is a local negative control, not a parent checkout.
+ let mut old = make_desc();
+ old.CachedPSO = D3D12_CACHED_PIPELINE_STATE { pCachedBlob: stale.as_ptr() as _, CachedBlobSizeInBytes: stale.len() };
+ let mut old_pipeline = None;
+ let mut calls = Vec::new();
+ let mut create = |c: &D3D12_GRAPHICS_PIPELINE_STATE_DESC| {
+ let hr = match dev.CreateGraphicsPipelineState::<ID3D12PipelineState>(c) {
+ Ok(p) => { old_pipeline = Some(p); 0 }, Err(e) => e.code().0,
+ };
+ calls.push((!c.CachedPSO.pCachedBlob.is_null(), !c.GS.pShaderBytecode.is_null(), hr));
+ hr
+ };
+ assert!(retry_without_rect_gs(&mut old, true, &mut create) < 0);
+ old.CachedPSO = D3D12_CACHED_PIPELINE_STATE::default();
+ assert!(retry_without_rect_gs(&mut old, true, &mut create) >= 0);
+ assert!(old.GS.pShaderBytecode.is_null());
+ let drawn = draw(&old_pipeline.unwrap()).iter().filter(|p| **p != clear).count();
+ println!("RECT_CACHE old_order attempts={calls:?} drawn_pixels={drawn}/256");
+ assert!(drawn > 256 / 3 && drawn < 256 * 2 / 3);
+ }
+ }
+
+
#[test]
fn graphics_blob_key_tracks_shaders_samplers_and_state() {
unsafe { |
Part of #1269. Fix two caching/retry bugs in
translated_graphics_pso_once(crates/xcl/src/hle/d3d12x/real.rs) introduced with graphics PSO blob caching in #1836:rect_gsbefore retrying uncached:retry_without_rect_gsran inside the firstdriver_compile_identifiedcall whilecopy.CachedPSOwas still attached. When a cached blob was stale or rejected,retry_without_rect_gsclearedcopy.GSimmediately and retried with the staleCachedPSOstill set; the subsequent uncached retry then compiled withoutrect_gseven when the driver acceptedrect_gs, andnote_rect_list_gsskipped registering the PSO.rect_gsfallback poisoned the with-GS blob cache: when the driver rejectedrect_gsandretry_without_rect_gssucceeded withcopy.GScleared, the no-GS driver blob was still cached in memory and on disk undergkey(which hashedrect_gs = Some(...)), causing future lookups to feed a no-GS blob into a with-GS pipeline description.What is in it
crates/xcl/src/hle/d3d12x/real.rs:create_graphics_pso_cached+GraphicsPsoBuildand call it fromtranslated_graphics_pso_once:create(copy)directly without strippingrect_gs; only on failure evict the stale blob, clearcopy.CachedPSO, and fall back toretry_without_rect_gswithcopy.GSintact.cache_eligiblefalse whenrect_gswas dropped during fallback (rect_gs && copy.GS.pShaderBytecode.is_null()), so the with-GSgkey/ disk entry is never overwritten with a no-GS blob.graphics_blob_tests:stale_cached_graphics_blob_preserves_rect_list_gs_on_retryrect_list_gs_fallback_does_not_cache_under_with_gs_keyvalid_cached_graphics_blob_reuses_without_retryTested
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 hle::d3d12x::real::graphics_blob_tests -- --test-threads=1at27b54e1: 5 passed, 0 failed, 0 ignored (0 skipped).cargo test --workspace -- --test-threads=4 --skip fuzz_validate_and_gpuat27b54e1: 1110 passed, 0 failed, 46 ignored across all workspace targets (xcllib:1061 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, 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 at27b54e1vsmain(3da2abb).Regression run
Not tested
AI use
scripts/smoke.ps1regression runs were executed on the hardware listed above.