diff --git a/crates/leonida-shader/src/emit/container.rs b/crates/leonida-shader/src/emit/container.rs index 3c346d9a6..5816c5ff2 100644 --- a/crates/leonida-shader/src/emit/container.rs +++ b/crates/leonida-shader/src/emit/container.rs @@ -72,7 +72,8 @@ pub(crate) fn signature(elements: &[SigElement], input: bool) -> Vec { // Validator 1.6 writes one name per element in element order, repeats // included, except that system values share theirs (it keys names by // the semantic's string, which is one static string per system value); - // the rows sorted by register (unallocated last). + // the rows sorted by register (unallocated last), then by name offset: in + // element order within a register, not by column. let mut offsets: Vec = Vec::new(); let mut next = 8 + 32 * elements.len() as u32; let mut names = Vec::new(); @@ -90,7 +91,7 @@ pub(crate) fn signature(elements: &[SigElement], input: bool) -> Vec { } } let mut order: Vec = (0..elements.len()).collect(); - order.sort_by_key(|&i| (elements[i].row.unwrap_or(u32::MAX), elements[i].col)); + order.sort_by_key(|&i| elements[i].row.unwrap_or(u32::MAX)); for i in order { let (e, offset) = (&elements[i], offsets[i]); let used = e.usage << e.col; @@ -416,4 +417,33 @@ mod tests { .collect(); assert_eq!(hex, "900150983cd24fb0d6963f7d28e17f72"); } + + fn element(name: &str, kind: u8, interp: u8, row: u32, col: u8, cols: u8) -> SigElement { + SigElement { + name: name.into(), + index: 0, + kind, + comp: 9, + interp, + row: Some(row), + col, + cols, + usage: (1 << cols) - 1, + half: false, + } + } + + #[test] + fn rows_of_one_register_keep_element_order() { + // As the console's containers list them: column 3 before column 0. + let els = [ + element("TEXCOORD", 0, 2, 0, 3, 1), + element("TANGENT", 0, 2, 0, 0, 3), + ]; + let part = signature(&els, false); + let name_offset = + |row: usize| u32::from_le_bytes(part[8 + 32 * row + 4..][..4].try_into().unwrap()); + assert_eq!(name_offset(0), 8 + 64); + assert_eq!(part[8 + 24], 0b1000); + } } diff --git a/docs/fork-notes.md b/docs/fork-notes.md index 0c836f1ec..d2d2b5c3d 100644 --- a/docs/fork-notes.md +++ b/docs/fork-notes.md @@ -5,6 +5,27 @@ The status summary is in [README.md](../README.md). ## Newest (2026-11-26) +**R-7: signature rows in the order the DXIL validator expects.** +`container::signature` sorted the rows of one register by column. The +validator expects them in element order, as the console's containers list +them, for example `TEXCOORD16` in column 3 before `TANGENT0` in column 0. +The rows are now sorted by register only, a stable sort that keeps element +order; no register or mask changes. On `2f952dc` that mismatch made 72 +programs fail with "Container part 'Program Input/Output Signature' does not +match" (33 pixel, 26 vertex, 13 mesh); their pipelines were never created, +so their draws were lost. + +Not fixed: 70 programs pack elements of different interpolation modes into +one register (a constant `COLOR` or `SV_IsFrontFace` beside linear +`TEXCOORD`s), which the validator refuses. Moving an element to another +register in one program alone is not safe: D3D12 links a stage's outputs to +the next stage's inputs by register and mask too (the debug layer's +`SHADER_LINKAGE_REGISTERINDEX` and `REGISTERMASK` checks), so both sides of +a link would have to move the same way. 71 mesh programs exceed the +32,768-byte vertex plus primitive output limit, and 3 pixel programs fail +with "out of bound coord must be undef". A unit test covers the row order. +No gameplay or frame-rate improvement is claimed. + **`scripts/measure-run.ps1` reads frame lines under Windows PowerShell 5.1.** The colour codes of `stderr.log` were stripped with the `` `e `` escape, which only PowerShell 7 knows; under 5.1 no frame line matched and