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

Open
github-bot wants to merge 2 commits from github-bot/gh-110 into main AGit
Owner

@⁠adritoyalser on GitHub · 2026-11-24 21:33 UTC · original
adritoyalser:fix/isg1-validation → main · +174 −8 · 2 files · 2 commits · open

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
**@⁠adritoyalser** on GitHub · 2026-11-24 21:33 UTC · [original](https://github.com/fxceless/victory-fork/pull/110) `adritoyalser:fix/isg1-validation` → `main` · +174 −8 · 2 files · 2 commits · open 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
container::signature previously copied SigElement::name verbatim for system values and sorted rows by (row, col). Validator 1.6 (dxil.dll) writes canonical DXIL semantic names for every system value (e.g. SV_Position, SV_Target, SV_IsFrontFace) regardless of the casing in the source signature, and sorts signature rows stably by register only (preserving element order within a shared row).

When a console shader declared a system value with non-canonical casing (such as SV_POSITION or SV_TARGET) or packed two elements into the same row in reverse column order, dxil.dll rejected the container with "Container part 'Program Input Signature' does not match expected for module" even though D3D12 still created the pipeline.

Emit canonical DXIL names for system values in container::signature, sort signature rows stably by register only, and add dxil.dll-backed regression tests for both cases.
Unallocated system-value elements (`row == None`, e.g. `SV_Depth`) carry
sentinel column `0xff`; shifting `mask` and `usage` by `col` overflows in
debug builds or produces wrong masks. Use column 0 whenever `row` is `None`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:20 +00:00
Author
Owner

@⁠arminkhaleghirod on GitHub · 2026-11-24 22:23 UTC · original

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.

**@⁠arminkhaleghirod** on GitHub · 2026-11-24 22:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/110#issuecomment-7146176425) 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.
Author
Owner

@⁠adritoyalser on GitHub · 2026-11-25 10:48 UTC · original

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.

**@⁠adritoyalser** on GitHub · 2026-11-25 10:48 UTC · [original](https://github.com/fxceless/victory-fork/pull/110#issuecomment-7160209305) 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/110/head:github-bot/gh-110'
git switch 'github-bot/gh-110'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-110'
git switch 'github-bot/gh-110'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-110'
git switch 'github-bot/gh-110'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-110'
git switch 'main'
git merge --squash 'github-bot/gh-110'
git switch 'main'
git merge --ff-only 'github-bot/gh-110'
git switch 'main'
git merge 'github-bot/gh-110'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.