Skip to content

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

Open
Moon0755 wants to merge 1 commit into
Marvisak:mainfrom
Moon0755:fix/signature-row-name-offset
Open

Moon0755 wants to merge 1 commit into
Marvisak:mainfrom
Moon0755:fix/signature-row-name-offset

Conversation

@Moon0755

Copy link
Copy Markdown

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

Validator 1.6 orders the rows of one register by semantic name offset
(DXC's `sort_sig`: stream, register, name). `signature` kept element
order, which is the same order except where a system value repeats: its
later elements share the first one's name, so they sort before an
arbitrary semantic declared between them. With SV_ClipDistance1 packed
into a row after a TEXCOORD, the validator refused the container
("Container part 'Program Output Signature' does not match expected for
module").

The key is the one Marvisak#1022 proposed.

Test: `packed_signature_rows_follow_system_value_name_order`, both
declaration orders through dxil.dll.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@kotekompotek

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

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.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026

Copy link
Copy Markdown
Owner

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

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants