Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 32 additions & 2 deletions crates/leonida-shader/src/emit/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ pub(crate) fn signature(elements: &[SigElement], input: bool) -> Vec<u8> {
// 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<u32> = Vec::new();
let mut next = 8 + 32 * elements.len() as u32;
let mut names = Vec::new();
Expand All @@ -90,7 +91,7 @@ pub(crate) fn signature(elements: &[SigElement], input: bool) -> Vec<u8> {
}
}
let mut order: Vec<usize> = (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;
Expand Down Expand Up @@ -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);
}
}
21 changes: 21 additions & 0 deletions docs/fork-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down