Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 77 additions & 1 deletion crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand All @@ -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}");
}
Expand Down Expand Up @@ -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<ID3D12PipelineState> = 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);
Expand Down Expand Up @@ -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)
}

Expand Down
Loading