From 30a39948bc7a8e7dbe93bf6dd59e3fd9b2a08f2b Mon Sep 17 00:00:00 2001 From: Kalmarv <59708937+Kalmarv@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:34:58 -0500 Subject: [PATCH] D3D12.X: name persisted compute driver blobs for NodeMask 1 as node 0 Since efdebc82 the driver blob name carries the pipeline's NodeMask when it is nonzero, so linked-adapter nodes keep their blobs apart. A title creates its compute pipelines with NodeMask 1, while the offline precompile and the startup-preparation workers create them with 0. Both masks name the first node (D3D12 takes 0 as node 0), but the names differed ("-n1"), so in play every precompiled compute blob was absent and the driver compiled each one cold. On title: ea3b5e4d after a full precompile, a load into the world logged "driver blob absent" for programs whose blob the precompile had saved under the name without the node part. 323 compute pipelines were built cold in play, 65 of them of 256 KB or more DXIL (71 such compiles were started). They held the huge-pipeline slots, graphics queued behind them, and presents stopped at 231 s. The cache held 15,376 blobs without a node part and 378 with "-n1", all written by title runs. persisted_node_mask() maps mask 1 to 0 for the blob name (plain, chain and indirect-chain roots) and for the in-memory blob key. Masks 2 and up keep their own names. The desc passed to the driver is unchanged; a GPU test checks that the driver accepts a blob made with NodeMask 0 for a pipeline created with NodeMask 1. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/real.rs | 78 ++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 1c1c731864..5c0461a0d5 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -6325,6 +6325,13 @@ pub(crate) mod driver_cache { name_for_root_node(dxil, flags, chained, samplers, 0) } + /// The node a pipeline's NodeMask names, as persisted driver state is keyed: 0 and 1 both mean + /// the first node (D3D12 takes 0 as node 0), so a title's NodeMask 1 finds the blobs a + /// preparation pass made with 0. Other linked-adapter masks stay apart. + pub fn persisted_node_mask(node_mask: u32) -> u32 { + if node_mask == 1 { 0 } else { node_mask } + } + /// Include the linked-adapter node in persisted driver state. Node zero keeps legacy names. pub fn name_for_root_node(dxil: &[u8], flags: i32, chained: bool, samplers: &[StaticSampler], node_mask: u32) -> String { let ext = if chained { "chain.pso" } else { "pso" }; @@ -6348,6 +6355,7 @@ pub(crate) mod driver_cache { dxil: &[u8], flags: i32, samplers: &[StaticSampler], node_mask: u32, ext: &str, ) -> String { let mut base = format!("{:016x}-{:x}-{:x}", crate::gpu::shader::fnv64(dxil), dxil.len(), flags); + let node_mask = persisted_node_mask(node_mask); if node_mask != 0 { base += &format!("-n{node_mask:x}"); } @@ -6827,6 +6835,74 @@ pub(crate) mod driver_cache { ); } + /// A title creates its pipelines with NodeMask 1, preparation passes with 0: both are the + /// first node and must share one blob, in every root namespace and in the in-memory key. + #[test] + fn node_masks_zero_and_one_share_a_blob_name() { + let wrap = ([1, 2, 3, 4], false); + for samplers in [&[][..], &[wrap][..]] { + for chained in [false, true] { + assert_eq!( + name_for_root_node(b"same dxil", 3, chained, samplers, 1), + name_for_root_node(b"same dxil", 3, chained, samplers, 0) + ); + } + for root in [ChainRoot::DirectConstants, ChainRoot::IndirectCbv] { + assert_eq!( + name_for_chain_root_node(b"same dxil", 3, root, samplers, 1), + name_for_chain_root_node(b"same dxil", 3, root, samplers, 0) + ); + assert_ne!( + name_for_chain_root_node(b"same dxil", 3, root, samplers, 2), + name_for_chain_root_node(b"same dxil", 3, root, samplers, 0) + ); + } + } + assert_ne!(name_for_root_node(b"same dxil", 3, false, &[], 3), name_for_root_node(b"same dxil", 3, false, &[], 1)); + assert_eq!(super::super::compute_blob_key_for(b"same dxil", 7, 3, 1), super::super::compute_blob_key_for(b"same dxil", 7, 3, 0)); + assert_ne!(super::super::compute_blob_key_for(b"same dxil", 7, 3, 2), super::super::compute_blob_key_for(b"same dxil", 7, 3, 0)); + } + + /// The shared name holds only if the driver takes a blob made with NodeMask 0 for a + /// pipeline created with NodeMask 1 on a single-node device. + #[test] + fn a_node_zero_compute_blob_is_accepted_for_node_mask_one() { + use windows::Win32::Graphics::Direct3D12::*; + let Ok(dev) = crate::gpu::recomp::runner::device() else { + crate::gpu::recomp::runner::skip_test("no GPU"); + return; + }; + if crate::gpu::recomp::dxc::location().is_err() { + crate::gpu::recomp::runner::skip_test("no DXC"); + return; + } + if unsafe { dev.GetNodeCount() } != 1 { + crate::gpu::recomp::runner::skip_test("linked adapter (more than one node)"); + return; + } + let src = "#define RS \"UAV(u0)\"\nRWByteAddressBuffer o : register(u0);\n[RootSignature(RS)]\n[numthreads(64, 1, 1)]\nvoid main(uint l : SV_GroupThreadID) { o.Store(4u * l, l); }\n"; + unsafe { + let dxil = crate::gpu::recomp::dxc::compile(src, "main", "cs_6_0", &[]).unwrap(); + let rs: ID3D12RootSignature = dev.CreateRootSignature(0, &dxil).unwrap(); + let desc = |node_mask: u32, blob: &[u8]| D3D12_COMPUTE_PIPELINE_STATE_DESC { + pRootSignature: std::mem::transmute_copy(&rs), + CS: D3D12_SHADER_BYTECODE { pShaderBytecode: dxil.as_ptr().cast(), BytecodeLength: dxil.len() }, + NodeMask: node_mask, + CachedPSO: D3D12_CACHED_PIPELINE_STATE { + pCachedBlob: if blob.is_empty() { std::ptr::null() } else { blob.as_ptr().cast() }, + CachedBlobSizeInBytes: blob.len(), + }, + ..Default::default() + }; + let first: ID3D12PipelineState = dev.CreateComputePipelineState(&desc(0, &[])).unwrap(); + let blob = first.GetCachedBlob().unwrap(); + let blob = std::slice::from_raw_parts(blob.GetBufferPointer() as *const u8, blob.GetBufferSize()).to_vec(); + assert!(!blob.is_empty()); + let again: windows::core::Result = dev.CreateComputePipelineState(&desc(1, &blob)); + assert!(again.is_ok(), "the driver refused a NodeMask 0 blob for NodeMask 1: {:?}", again.err()); + } + } + #[test] fn direct_and_indirect_chain_roots_have_distinct_compatible_names() { let direct = name_for_chain_root_node(b"same dxil", 3, ChainRoot::DirectConstants, &[], 0); @@ -7115,7 +7191,7 @@ fn compute_blob_key_for(dxil: &[u8], rs: usize, flags: i32, node_mask: u32) -> ( use std::hash::{Hash, Hasher}; let mut h = std::collections::hash_map::DefaultHasher::new(); dxil.hash(&mut h); - node_mask.hash(&mut h); + driver_cache::persisted_node_mask(node_mask).hash(&mut h); (h.finish(), rs, flags) }