From 0c39f33773c49bd01c54f0c89413eb21d6e84e02 Mon Sep 17 00:00:00 2001 From: Neutron-0 <174259662+Neutron-0@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:04:54 +0530 Subject: [PATCH] d3d12: the PSV0 part's name table holds a copy of a name per element (SHADER-PSV0-NAME-PER-ELEMENT) The validator compares the PSV0 part with the one it computes from the module, and that one's name table holds a copy of a semantic's name per element. Ours held one copy for all the elements that shared the name, so every later element's name offset differed from the module's and the validator refused the program with "Container part 'Pipeline State Validation' does not match expected for module". Every program with an arbitrary semantic (POSITION, TEXCOORD, ...) has one, so the 4 tests that validate such a program failed on Windows with any dxil.dll of DXC 1.5.2005 or newer. The validator block is #[cfg(windows)], so a Linux CI job cannot see it. Write one copy per element, as DXC writes it: the PSV0 of a geometry stage built by hand is now byte for byte the one DXC 1.7 writes for the same signature, apart from the dependency-mask table the validator does not compare. Test: the new test in emit/container.rs fails on main (both elements share the name offset 1) and passes with the change; the 4 validator tests pass with it (405 tests, 0 failed). Needs no game files and no GPU. AI-assisted: yes - MiniMax M3.1 Flash (OpenCode). --- .../leonida-shader/src/emit/container.rs | 83 ++++++++++++++++--- 1 file changed, 72 insertions(+), 11 deletions(-) diff --git a/d3d12/crates/leonida-shader/src/emit/container.rs b/d3d12/crates/leonida-shader/src/emit/container.rs index 4f5e6dc194..df3adca4c8 100644 --- a/d3d12/crates/leonida-shader/src/emit/container.rs +++ b/d3d12/crates/leonida-shader/src/emit/container.rs @@ -238,14 +238,15 @@ pub(crate) fn psv(p: &Psv) -> Vec { let mut elements = Vec::new(); for e in p.inputs.iter().chain(p.outputs).chain(p.prims) { let name = if e.kind == 0 { + // One copy of the name per element, in element order, as DXC + // writes it (the `ISG1`/`OSG1` part above does the same): the + // validator compares this part with the one it computes from the + // module, whose name table holds a copy per element, so a shared + // copy leaves every later element with a name offset the + // module's does not have and the validator refuses the program. let needle: Vec = e.name.bytes().chain([0]).collect(); - match find(&strings, &needle) { - Some(at) => at, - None => { - strings.extend(&needle); - strings.len() - needle.len() - } - } + strings.extend(&needle); + strings.len() - needle.len() } else { 0 }; @@ -304,10 +305,6 @@ pub(crate) fn psv(p: &Psv) -> Vec { out } -fn find(hay: &[u8], needle: &[u8]) -> Option { - hay.windows(needle.len()).position(|w| w == needle) -} - /// The container: parts in order, hashed. pub(crate) fn build(parts: &[(&[u8; 4], &[u8])]) -> Vec { let table = 0x20 + 4 * parts.len(); @@ -475,6 +472,70 @@ mod tests { .is_err()); } + /// The validator compares the `PSV0` part with the one it computes from + /// the module; that name table holds a copy of a semantic's name per + /// element, so a shared copy leaves the later elements with name + /// offsets the module's table does not have and the validator refuses + /// the program. + #[test] + fn the_psv_name_table_holds_a_copy_of_a_name_per_element() { + let texcoord = SigElement { + name: "TEXCOORD".into(), + index: 0, + kind: 0, + comp: 9, + interp: 2, + row: Some(0), + col: 0, + cols: 4, + usage: 15, + half: false, + }; + let second = SigElement { + index: 1, + row: Some(2), + ..texcoord.clone() + }; + let position = SigElement { + name: "SV_Position".into(), + kind: 3, + interp: 4, + row: Some(1), + ..texcoord.clone() + }; + let psv = psv(&Psv { + stage: 1, + flag: true, + inputs: &[texcoord, second], + outputs: &[position], + prims: &[], + mesh: None, + geometry: None, + bindings: &[], + threads: [0; 3], + wave_size: None, + }); + // The name table follows the 56-byte header, the index table the + // names, and the rows the indices; each row names its element in + // its first word. + let names_len = u32::from_le_bytes(psv[56..60].try_into().unwrap()) as usize; + let names = &psv[60..60 + names_len]; + let mut at = 60 + names_len; + let indices = u32::from_le_bytes(psv[at..at + 4].try_into().unwrap()) as usize; + at += 4 + 4 * indices; + assert_eq!(u32::from_le_bytes(psv[at..at + 4].try_into().unwrap()), 16); + at += 4; + let name_of = |row: usize| { + u32::from_le_bytes(psv[at + row * 16..at + row * 16 + 4].try_into().unwrap()) as usize + }; + // The two TEXCOORDs have a copy of the name each; the system value + // has none. + assert_ne!(name_of(0), name_of(1)); + assert_eq!(&names[name_of(0)..name_of(0) + 9], b"TEXCOORD\0"); + assert_eq!(&names[name_of(1)..name_of(1) + 9], b"TEXCOORD\0"); + assert_eq!(name_of(2), 0); + } + #[test] fn md5_core_matches_the_standard() { // Standard MD5 of "abc" with standard padding, through md5_block.