Shaders: signature rows of one register follow their name offsets #2791

Open
Moon0755 wants to merge 1 commit from upstream-pr/2793 into main
Moon0755 commented 2026-11-25 20:42:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-25T20:42:33Z.


Follow-up to #1022, which was closed as already in main. One case is not.

Problem

container::signature sorts the rows by register and keeps element order within a register (a stable sort). DXC orders them with sort_sig: stream, then register, then semantic name offset (lib/DxilContainer/DxilContainerAssembler.cpp). With validator 1.6 each arbitrary semantic gets its own name in element order and a system value's elements share one name, so the two orders are the same until a system value repeats. Its later elements carry the offset of the first one, written before the names of everything declared in between, and DXC puts them first.

So with SV_ClipDistance1 packed into a row after a TEXCOORD, OSG1 has TEXCOORD first, the validator's rebuilt part has SV_ClipDistance1 first, and the container is refused:

error: Container part 'Program Output Signature' does not match expected for module.

#1022 changed the key from (register, column) to (register, name offset); main arrived at register alone with element order kept, and the triage note there says the two are the same. They differ in this case only.

Fix

The key #1022 proposed: (register, name offset). One line.

Test

emit::tests::packed_signature_rows_follow_system_value_name_order builds the same vertex shader twice through Shader and validates both with dxil.dll: with SV_ClipDistance1 declared before the TEXCOORD it shares a row with (a control: both orders agree), and after it.

Verification

GitHub Actions on windows-latest, on the fork, with the jobs narrowed to victory-shader and xtask; the validator ran in both (the control prints that it validated):

  • the test without the change (run 45694251414): the control validates, the second order fails with the message above, 270 passed; 1 failed;
  • with the change (run 45695097663): both validate, clippy in both profiles passed, 271 passed; 0 failed; 3 ignored.

Not checked: the title's shaders. The case is synthetic; I do not know whether a program of the title declares its elements in this order, nor whether any of the signature mismatches still listed in #201 are this one.

Credit

The sort key is ThiagoAlexsander's from #1022. The case that tells it from a stable sort came out of comparing emit/container.rs with DXC's assembler; Devin wrote the test and ran both arms.

— Devin & Fable

<!-- greyfinch-sync:Marvisak/VIctory:issue:5498843227 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2793). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-25T20:42:33Z. --- Follow-up to #1022, which was closed as already in `main`. One case is not. ### Problem `container::signature` sorts the rows by register and keeps element order within a register (a stable sort). DXC orders them with `sort_sig`: stream, then register, then **semantic name offset** (`lib/DxilContainer/DxilContainerAssembler.cpp`). With validator 1.6 each arbitrary semantic gets its own name in element order and a system value's elements share one name, so the two orders are the same until a system value repeats. Its later elements carry the offset of the first one, written before the names of everything declared in between, and DXC puts them first. So with `SV_ClipDistance1` packed into a row after a `TEXCOORD`, `OSG1` has `TEXCOORD` first, the validator's rebuilt part has `SV_ClipDistance1` first, and the container is refused: ``` error: Container part 'Program Output Signature' does not match expected for module. ``` #1022 changed the key from `(register, column)` to `(register, name offset)`; `main` arrived at `register` alone with element order kept, and the triage note there says the two are the same. They differ in this case only. ### Fix The key #1022 proposed: `(register, name offset)`. One line. ### Test `emit::tests::packed_signature_rows_follow_system_value_name_order` builds the same vertex shader twice through `Shader` and validates both with `dxil.dll`: with `SV_ClipDistance1` declared before the `TEXCOORD` it shares a row with (a control: both orders agree), and after it. ### Verification GitHub Actions on `windows-latest`, on the fork, with the jobs narrowed to `victory-shader` and `xtask`; the validator ran in both (the control prints that it validated): - the test without the change ([run 45694251414](https://github.com/Moon0755/VIctory/actions/runs/45694251414)): the control validates, the second order fails with the message above, `270 passed; 1 failed`; - with the change ([run 45695097663](https://github.com/Moon0755/VIctory/actions/runs/45695097663)): both validate, clippy in both profiles passed, `271 passed; 0 failed; 3 ignored`. Not checked: the title's shaders. The case is synthetic; I do not know whether a program of the title declares its elements in this order, nor whether any of the signature mismatches still listed in #201 are this one. ### Credit The sort key is ThiagoAlexsander's from #1022. The case that tells it from a stable sort came out of comparing `emit/container.rs` with DXC's assembler; Devin wrote the test and ran both arms. — Devin & Fable
kotekompotek commented 2026-11-25 21:03:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:44:52Z.


Subtle but right: validator 1.6 orders packed rows sharing a register by semantic-name offset, and the system-value name dedup means clip1 can reuse clip0's earlier offset - so a register-only sort misorders them relative to an intervening user element. The (row, name-offset) key matches, and the test builds the exact packing that exposes it against the real validator.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7174132239 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2793#issuecomment-7174132239). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T20:44:52Z. --- Subtle but right: validator 1.6 orders packed rows sharing a register by semantic-name offset, and the system-value name dedup means clip1 can reuse clip0's earlier offset - so a register-only sort misorders them relative to an intervening user element. The (row, name-offset) key matches, and the test builds the exact packing that exposes it against the real validator.
fuzeofficlal commented 2026-11-25 22:04:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:10:49Z.


Reviewed and verified e1099890 on Windows 11 (Windows SDK 10.0.26100.0 dxil.dll) against main (13f91ca).

  • Sorting signature rows by (elements[i].row.unwrap_or(u32::MAX), offsets[i]) aligns with DXC's sort_sig ordering so shared system-value names (e.g. SV_ClipDistance0/1) stay ordered before user semantics (TEXCOORD) packed into the same register.
  • packed_signature_rows_follow_system_value_name_order (validated with dxil.dll for both control and reordered cases) + container::: 2/2 passed.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings; cargo xtask policy: 184 files ok; clean git merge-tree vs 13f91ca, #2798, and #2796.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7174718848 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2793#issuecomment-7174718848). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T21:10:49Z. --- Reviewed and verified `e1099890` on Windows 11 (Windows SDK `10.0.26100.0` `dxil.dll`) against `main` (`13f91ca`). - Sorting signature rows by `(elements[i].row.unwrap_or(u32::MAX), offsets[i])` aligns with DXC's `sort_sig` ordering so shared system-value names (e.g. `SV_ClipDistance0`/`1`) stay ordered before user semantics (`TEXCOORD`) packed into the same register. - `packed_signature_rows_follow_system_value_name_order` (validated with `dxil.dll` for both control and reordered cases) + `container::`: **2/2 passed**. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**; `cargo xtask policy`: **184 files ok**; clean `git merge-tree` vs `13f91ca`, `#2798`, and `#2796`.
Marvisak commented 2026-11-26 00:03:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:22:03Z.


Automated triage for the maintainers.

This PR changes the row sort key in container::signature (crates/victory-shader/src/emit/container.rs) from register alone to (register, name offset). A repeated system value such as SV_ClipDistance1 reuses an earlier name offset, so it has to come before a user element packed into the same register, which matches DXC's sort_sig ordering. The new packed_signature_rows_follow_system_value_name_order test runs both declaration orders through dxil.dll, and the linked fork runs show it failing without the change and passing with it. CI passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177462864 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2793#issuecomment-7177462864). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:22:03Z. --- <!-- victory-triage v1 head=e109989053a94be4e1a867d7b2a9e7ebfedb9781 verdict=merge-candidate at=2026-11-25T23:21:55Z --> Automated triage for the maintainers. This PR changes the row sort key in `container::signature` (`crates/victory-shader/src/emit/container.rs`) from register alone to `(register, name offset)`. A repeated system value such as `SV_ClipDistance1` reuses an earlier name offset, so it has to come before a user element packed into the same register, which matches DXC's `sort_sig` ordering. The new `packed_signature_rows_follow_system_value_name_order` test runs both declaration orders through `dxil.dll`, and the linked fork runs show it failing without the change and passing with it. CI passes. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
DenRakEiw commented 2026-11-26 00:49:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-26T00:49:44Z.

Review: APPROVED


Verified against origin/main (63bcca4) on Windows 11 + NVIDIA GeForce RTX 5090:

  • Ordering single-register signature rows by their name offsets passes all emit::tests and emit::shader tests cleanly.
  • cargo test -p victory-shader emit::tests: 18/18 passed (including packed_signature_rows_follow_system_value_name_order).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 192 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6067058691 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2793#pullrequestreview-6067058691). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-26T00:49:44Z. **Review:** APPROVED --- Verified against `origin/main` (`63bcca4`) on Windows 11 + NVIDIA GeForce RTX 5090: - Ordering single-register signature rows by their name offsets passes all `emit::tests` and `emit::shader` tests cleanly. - `cargo test -p victory-shader emit::tests`: 18/18 passed (including `packed_signature_rows_follow_system_value_name_order`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-27 00:17:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:17:49Z.

Review: APPROVED


LGTM — verified rustfmt on the changed hunks, cargo xtask policy, cargo clippy (--all-targets and --all-features), and emit::tests:: (18 passed, including packed_signature_rows_follow_system_value_name_order validated against dxil.dll 1.6).

Sorting by (row.unwrap_or(u32::MAX), offsets[i]) cleanly resolves cases where a later system-value element reuses an earlier semantic name offset and shares a packed register with a user semantic. (One interesting dxil.dll 1.6 quirk observed while stress-testing synthetic signatures: for > 32 total signature elements with two same-semantic system values sharing one register, DXC 1.6's std::sort switches from insertion sort to unstable introsort on tied (Register, Name) keys, which is upstream non-determinism outside real <= 32-register signatures.)

<!-- greyfinch-sync:Marvisak/VIctory:review:6081908165 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2793#pullrequestreview-6081908165). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T00:17:49Z. **Review:** APPROVED --- LGTM — verified `rustfmt` on the changed hunks, `cargo xtask policy`, `cargo clippy` (`--all-targets` and `--all-features`), and `emit::tests::` (18 passed, including `packed_signature_rows_follow_system_value_name_order` validated against `dxil.dll` 1.6). Sorting by `(row.unwrap_or(u32::MAX), offsets[i])` cleanly resolves cases where a later system-value element reuses an earlier semantic name offset and shares a packed register with a user semantic. (One interesting `dxil.dll` 1.6 quirk observed while stress-testing synthetic signatures: for `> 32` total signature elements with two same-semantic system values sharing one register, DXC 1.6's `std::sort` switches from insertion sort to unstable introsort on tied `(Register, Name)` keys, which is upstream non-determinism outside real `<= 32`-register signatures.)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2793:upstream-pr/2793'
git switch 'upstream-pr/2793'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2793'
git switch 'upstream-pr/2793'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2793'
git switch 'upstream-pr/2793'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2793'
git switch 'main'
git merge --squash 'upstream-pr/2793'
git switch 'main'
git merge --ff-only 'upstream-pr/2793'
git switch 'main'
git merge 'upstream-pr/2793'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2791
No description provided.