From 9152a1beefa059fecf07c0d62b89c805a7171d69 Mon Sep 17 00:00:00 2001 From: Saitken91 <98485913+SAitken91@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:48:42 -0600 Subject: [PATCH] Shaders: one interpolation mode per signature row The console packs elements of different interpolation modes into one signature row (a constant SV_IsFrontFace or uint beside a linear TEXCOORD), which the DXIL validator rejects: "signature element ... has interpolation mode that differs from another element packed into the same row". Before the signatures are written, each later mode of a row now moves to a free row of its own, shared by that row's elements of the mode. Code addresses elements by id and stages link by semantic, so only the signatures (metadata, ISG1/OSG1, PSV0) change. Elements without a mode are left in place, and programs without such rows are unchanged. translate --validate on shaders.rpf: vertex/pixel 12172 -> 12214 validated, mesh 8129 -> 8130; no interpolation-row errors remain. A few programs now report the signature-mismatch errors already in the list, which the packing error had hidden. Co-Authored-By: Claude Opus 5.5 --- crates/victory-shader/src/emit/container.rs | 72 +++++++++++++++++++++ crates/victory-shader/src/emit/shader.rs | 2 + 2 files changed, 74 insertions(+) diff --git a/crates/victory-shader/src/emit/container.rs b/crates/victory-shader/src/emit/container.rs index b0d30f9188..5e3e91c7e1 100644 --- a/crates/victory-shader/src/emit/container.rs +++ b/crates/victory-shader/src/emit/container.rs @@ -63,6 +63,47 @@ impl SigElement { } } +/// The console packs elements of different interpolation modes into one +/// row (a constant front face beside a linear coordinate, say); DXIL needs +/// one mode per row. Each later mode of a row moves to a free row of its +/// own, shared by that row's elements of the mode. Code addresses elements +/// by id and stages link by semantic, so only the signatures change. +/// Elements without a mode (0) are left where they are. +pub(crate) fn separate_interpolation(elements: &mut [SigElement]) { + let mut next = elements + .iter() + .filter_map(|e| e.row) + .max() + .map_or(0, |r| r + 1); + // (row, the row's first mode) + let mut first: Vec<(u32, u8)> = Vec::new(); + // ((old row, mode), new row) + let mut moved: Vec<((u32, u8), u32)> = Vec::new(); + for e in elements.iter_mut() { + let (Some(row), mode) = (e.row, e.interp) else { + continue; + }; + if mode == 0 { + continue; + } + match first.iter().find(|f| f.0 == row) { + None => first.push((row, mode)), + Some(&(_, m)) if m == mode => {} + Some(_) => { + let to = match moved.iter().find(|m| m.0 == (row, mode)) { + Some(&(_, to)) => to, + None => { + moved.push(((row, mode), next)); + next += 1; + next - 1 + } + }; + e.row = Some(to); + } + } + } +} + /// `ISG1`/`OSG1`: 32-byte rows, then the names. pub(crate) fn signature(elements: &[SigElement], input: bool) -> Vec { let mut out = Vec::new(); @@ -377,4 +418,35 @@ mod tests { .collect(); assert_eq!(hex, "900150983cd24fb0d6963f7d28e17f72"); } + + fn element(name: &str, row: u32, col: u8, interp: u8) -> SigElement { + SigElement { + name: name.into(), + index: 0, + kind: 0, + comp: 9, + interp, + row: Some(row), + col, + cols: 1, + usage: 1, + half: false, + } + } + + #[test] + fn rows_of_mixed_interpolation_are_separated() { + let mut e = vec![ + element("A", 0, 0, 2), + element("B", 0, 1, 1), + element("C", 1, 0, 2), + element("D", 0, 2, 1), + element("E", 0, 3, 2), + element("F", 1, 1, 0), + ]; + separate_interpolation(&mut e); + let rows: Vec = e.iter().map(|e| e.row.unwrap()).collect(); + // B and D (constant) share a new row; A and E stay; F has no mode. + assert_eq!(rows, [0, 2, 1, 2, 0, 1]); + } } diff --git a/crates/victory-shader/src/emit/shader.rs b/crates/victory-shader/src/emit/shader.rs index 8389c17bea..584b60bd1f 100644 --- a/crates/victory-shader/src/emit/shader.rs +++ b/crates/victory-shader/src/emit/shader.rs @@ -295,6 +295,8 @@ impl Shader { pub fn finish(mut self) -> Vec { let ud_size = (self.user_data * 4).next_multiple_of(16); self.fix_user_data_size(ud_size); + container::separate_interpolation(&mut self.inputs); + container::separate_interpolation(&mut self.outputs); let mut resources = None; let mut bindings = Vec::new(); let i32c = |s: &mut Self, v: u32| {