From 6641b9945c3e55dada65f684b7fb256fc6a78c97 Mon Sep 17 00:00:00 2001 From: KelboLive <168463230+KelboLive@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:24:55 -0500 Subject: [PATCH] d3d12-shader: one PSV0 name per element, as the validator regenerates it (SHADER-PSV0-NAMES) `psv()` wrote the PSV0 string table with one copy of a semantic name for all elements that shared it. The DXIL validator rebuilds PSV0 from the module and compares the parts for container layouts before 1.8, and that table holds a copy per element: a repeated arbitrary semantic (two TEXCOORDs, two clip distances) left the later element with an offset the regenerated table does not contain, so the program was refused with "Container part 'Pipeline State Validation' does not match expected for module". Write one copy per arbitrary element in element order, as DXC does; system values keep the empty name at offset 0. The regression test parses the emitted part and fails on the shared offset. On main the rectangle geometry-stage validator test is red with dxil.dll 1.7.2308; with this change the full crate suite is 429 passed, 0 failed, 6 ignored (without and with LEONIDA_DXIL pointing at 1.7.2308), and `cargo check --workspace --all-targets --locked` passes. No game data, no GPU. --- .../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 4f5e6dc19..75f93fe35 100644 --- a/d3d12/crates/leonida-shader/src/emit/container.rs +++ b/d3d12/crates/leonida-shader/src/emit/container.rs @@ -233,19 +233,19 @@ pub(crate) fn psv(p: &Psv) -> Vec { } } // Names of arbitrary semantics (system values use ""), then indices. + // One copy of each name per element, in element order: the validator + // compares this part with the one it computes from the module, whose + // name table has a copy per element, so sharing a name between two + // elements (two `TEXCOORD`s, say) leaves the later one with an offset + // that table does not have and the program is refused. let mut strings = vec![0u8]; let mut indices: Vec = Vec::new(); let mut elements = Vec::new(); for e in p.inputs.iter().chain(p.outputs).chain(p.prims) { let name = if e.kind == 0 { 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 +304,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 +471,71 @@ mod tests { .is_err()); } + #[test] + fn the_psv_name_table_holds_a_copy_of_a_name_per_element() { + // Two arbitrary inputs share the semantic name `TEXCOORD`, as a + // vertex shader's TEXCOORD0 and TEXCOORD1 do. DXC writes a copy of + // the name for each element; the validator rebuilds the PSV from the + // module and compares the parts, so one shared copy is rejected on + // every validator before 1.8 (`Pipeline State Validation does not + // match expected for module`). + 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(1), + ..texcoord.clone() + }; + let position = SigElement { + name: "SV_Position".into(), + kind: 3, + interp: 4, + row: Some(2), + ..texcoord.clone() + }; + let psv = psv(&Psv { + stage: 1, + flag: true, + inputs: &[texcoord, second, position], + outputs: &[], + prims: &[], + mesh: None, + geometry: None, + bindings: &[], + threads: [0; 3], + wave_size: None, + }); + let word = |at: usize| u32::from_le_bytes(psv[at..at + 4].try_into().unwrap()) as usize; + let mut at = 4 + word(0); // info after its size + at += 4; // binding count (none) + let names_len = word(at); + at += 4; + let names = &psv[at..at + names_len]; + at += names_len; + let indices = word(at); + at += 4 + 4 * indices; + assert_eq!(word(at), 16, "element stride"); + at += 4; + let name_of = |element: usize| word(at + 16 * element); + // Each arbitrary element names itself at its own offset; the system + // value has none (offset 0, the empty string). + let (first, second) = (name_of(0), name_of(1)); + assert_ne!(first, second, "the TEXCOORDs share a name offset"); + assert_eq!(&names[first..first + 9], b"TEXCOORD\0"); + assert_eq!(&names[second..second + 9], b"TEXCOORD\0"); + assert_eq!(name_of(2), 0, "the system value names the empty string"); + } + #[test] fn md5_core_matches_the_standard() { // Standard MD5 of "abc" with standard padding, through md5_block.