Shaders: emit canonical system-value names and preserve in-row order in ISG1/OSG1 (#53) #110

Open
adritoyalser wants to merge 2 commits from upstream-pr/110 into main
adritoyalser commented 2026-11-24 21:33:21 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by adritoyalser on 2026-11-24T21:33:21Z.


Addresses #53.

Problem

dxil.dll validates ISG1/OSG1/PSG1 by regenerating the signature container part from the DXIL module and comparing it byte-for-byte against the emitted part. Two mismatches in container::signature caused Container part 'Program Input Signature' does not match expected for module. (or 'Program Output Signature') even though D3D12 drivers still accepted the shader and created pipelines:

  1. Non-canonical system-value names: container::signature wrote SigElement::name verbatim (copied from the console shader's signature). When a shader declared e.g. SV_POSITION, SV_ISFRONTFACE, SV_PRIMITIVEID, SV_BARYCENTRICS, or SV_TARGET with uppercase/non-canonical casing, dxil.dll expected DXIL's canonical semantic name (SV_Position, SV_IsFrontFace, SV_PrimitiveID, SV_Barycentrics, SV_Target, etc.) and failed validation, while D3D12 matched semantic names case-insensitively.
  2. In-row column sorting: container::signature sorted rows by (row, col), whereas dxil.dll sorts stably by row only and preserves element order for elements sharing a register row. Two elements sharing a row in reverse column order (e.g. col 2 before col 0) failed ISG1 validation.

Fix

  • Add SigElement::canonical_name() in crates/victory-shader/src/emit/container.rs returning DXIL's canonical semantic name for all supported system values (kind != 0), keeping self.name for arbitrary semantics (kind == 0).
  • Sort ISG1/OSG1/PSG1 rows stably by row only (elements[i].row.unwrap_or(u32::MAX)).
  • Add two regression tests in crates/victory-shader/src/emit/mod.rs validated against dxil.dll:
    • non_canonical_system_value_names_validate_in_isg1_and_osg1
    • shared_row_elements_keep_element_order_in_isg1

Verification

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings — clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings — clean
  • cargo test -p victory-shader --lib --locked emit::tests — 12 passed, 0 failed (validated against dxil.dll 10.0.26100.0)
  • cargo test -p victory-shader --lib --locked emit::container::tests — 1 passed, 0 failed
<!-- greyfinch-sync:fxceless/victory-fork:issue:6591850657 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/110). Originally posted by [adritoyalser](https://github.com/adritoyalser) on 2026-11-24T21:33:21Z. --- Addresses #53. ### Problem `dxil.dll` validates `ISG1`/`OSG1`/`PSG1` by regenerating the signature container part from the DXIL module and comparing it byte-for-byte against the emitted part. Two mismatches in `container::signature` caused `Container part 'Program Input Signature' does not match expected for module.` (or `'Program Output Signature'`) even though D3D12 drivers still accepted the shader and created pipelines: 1. **Non-canonical system-value names:** `container::signature` wrote `SigElement::name` verbatim (copied from the console shader's signature). When a shader declared e.g. `SV_POSITION`, `SV_ISFRONTFACE`, `SV_PRIMITIVEID`, `SV_BARYCENTRICS`, or `SV_TARGET` with uppercase/non-canonical casing, `dxil.dll` expected DXIL's canonical semantic name (`SV_Position`, `SV_IsFrontFace`, `SV_PrimitiveID`, `SV_Barycentrics`, `SV_Target`, etc.) and failed validation, while D3D12 matched semantic names case-insensitively. 2. **In-row column sorting:** `container::signature` sorted rows by `(row, col)`, whereas `dxil.dll` sorts stably by `row` only and preserves element order for elements sharing a register row. Two elements sharing a row in reverse column order (e.g. `col 2` before `col 0`) failed `ISG1` validation. ### Fix - Add `SigElement::canonical_name()` in `crates/victory-shader/src/emit/container.rs` returning DXIL's canonical semantic name for all supported system values (`kind != 0`), keeping `self.name` for arbitrary semantics (`kind == 0`). - Sort `ISG1`/`OSG1`/`PSG1` rows stably by `row` only (`elements[i].row.unwrap_or(u32::MAX)`). - Add two regression tests in `crates/victory-shader/src/emit/mod.rs` validated against `dxil.dll`: - `non_canonical_system_value_names_validate_in_isg1_and_osg1` - `shared_row_elements_keep_element_order_in_isg1` ### Verification - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` — clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings` — clean - `cargo test -p victory-shader --lib --locked emit::tests` — 12 passed, 0 failed (validated against `dxil.dll` 10.0.26100.0) - `cargo test -p victory-shader --lib --locked emit::container::tests` — 1 passed, 0 failed
arminkhaleghirod commented 2026-11-24 23:09:35 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by arminkhaleghirod on 2026-11-24T22:23:45Z.


Merged onto main 90228a7 and ran victory translate --validate over the full title (26,148 programs) on Windows 11 / RTX 4080.

Clears the 39 Program Output Signature and 33 Program Input Signature mismatches. On main those 72 programs then fall into the blanket PSV mismatch (17,359 → 17,431), so the gain only shows on top of #61. #124, #110 and #112 give identical counts here, so they look like they overlap.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7146176425 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/110#issuecomment-7146176425). Originally posted by [arminkhaleghirod](https://github.com/arminkhaleghirod) on 2026-11-24T22:23:45Z. --- Merged onto main 90228a7 and ran `victory translate --validate` over the full title (26,148 programs) on Windows 11 / RTX 4080. Clears the 39 `Program Output Signature` and 33 `Program Input Signature` mismatches. On main those 72 programs then fall into the blanket PSV mismatch (17,359 → 17,431), so the gain only shows on top of #61. #124, #110 and #112 give identical counts here, so they look like they overlap.
adritoyalser commented 2026-11-25 11:10:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by adritoyalser on 2026-11-25T10:48:55Z.


Added unallocated-column handling (effective_col = 0 when row is None, e.g. SV_Depth with sentinel col = 0xff) plus a unit test (container::tests::unallocated_signature_element_uses_column_zero) in 009b6cf so #110 also covers the unallocated-column gap noted in #848.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7160209305 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/110#issuecomment-7160209305). Originally posted by [adritoyalser](https://github.com/adritoyalser) on 2026-11-25T10:48:55Z. --- Added unallocated-column handling (`effective_col` = 0 when `row` is `None`, e.g. `SV_Depth` with sentinel `col = 0xff`) plus a unit test (`container::tests::unallocated_signature_element_uses_column_zero`) in `009b6cf` so #110 also covers the unallocated-column gap noted in #848.
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/110:upstream-pr/110'
git switch 'upstream-pr/110'

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/110'
git switch 'upstream-pr/110'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/110'
git switch 'upstream-pr/110'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/110'
git switch 'main'
git merge --squash 'upstream-pr/110'
git switch 'main'
git merge --ff-only 'upstream-pr/110'
git switch 'main'
git merge 'upstream-pr/110'
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
fxceless/victory-fork!110
No description provided.