d3d12: the PSV0 part's name table holds a copy of a name per element (SHADER-PSV0-NAME-PER-ELEMENT) #2864

Closed
Neutron-0 wants to merge 1 commit from upstream-pr/2864 into main
Neutron-0 commented 2026-12-01 10:43:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T10:43:32Z.


Claimed in the coordination issue as: SHADER-PSV0-NAME-PER-ELEMENT (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7306830693)

What and why

d3d12/crates/leonida-shader/src/emit/container.rs writes the PSV0 part of the DXIL container. Its name table held one copy of a semantic's name for all the elements that shared it, while the validator compares this part with the one it computes from the module - and that one's table holds a copy per element. Every element after the first then carried a name offset the module's table does not have, and the validator refused the program:

error: Container part 'Pipeline State Validation' does not match expected for module.

Every program with an arbitrary semantic (POSITION, TEXCOORD, ...) has such elements, so this is not a corner case.

The fix writes one copy per element, in element order, as DXC writes it (the ISG1/OSG1 part above already did). The PSV0 of a geometry stage built by hand is now byte for byte the one DXC 1.7 writes for the same signature, apart from the dependency-mask table, which the validator does not compare.

Where this shows, and where it does not. The validator runs in validate() (emit/mod.rs), which is #[cfg(windows)] and only validates when a dxil.dll loads; without one it returns without validating, and the test passes. On a machine with the Windows SDK's dxil.dll the four tests that validate such a program fail (the same message with DXC 1.5.2005, 1.6.2104, 1.6.2112 and 1.7.2308 - not a version quirk). The CI's windows-latest runner has no dxil.dll that loads, so its job is green and cannot see this: the four tests read ok there without validating anything.

So the CI is not the place this is caught; a developer machine with the SDK is. The container the translator writes is what the host's own D3D12 runtime validates, and a container the validator refuses is a pipeline the host refuses, so making the part byte for byte the one DXC writes is the safe shape regardless of which validator version the host has.

The shader cache key follows the translator's sources (build.rs), so the key changes with this change and the caches built before it are rebuilt once.

This touches emit/container.rs, which #2581 also touches, but in another part of the file: #2581 changes the ISG1/OSG1 writer and the geometry block of psv(), this changes the name table further down in the same function.

Tested

  • cargo test -p leonida-shader --locked - fails on main 60f7dcd90 in the 4 validator tests (the message above, with dxil.dll 101.7.2308.24) and 415 tests OK, 0 failed, 5 ignored with the change on this pull request's head.
  • The new test emit::container::tests::the_psv_name_table_holds_a_copy_of_a_name_per_element - fails on main (both elements share the name offset 1) and passes with the change.
  • The PSV0 part of the geometry stage the test builds is now byte for byte DXC 1.7's own for the same signature (compared part by part; only the dependency-mask table differs).
  • cargo test -p leonida-gpu --lib --locked -- --test-threads=1 - 644 passed, 0 failed, 59 ignored.
  • cargo test --workspace --locked --exclude leonida-gpu - everything green except xtask's policy::tests::repository_passes_policy, which fails on main as well (3 violations about leonida-gpu/src/host.rs, emit/lower.rs and emit/indirect/amplify_dxil.rs; #2815 is the fix for that, and this change touches none of those files).
  • No game files; no GPU needed (the validator is the Windows SDK's dxil.dll).

GPUs tested: n/a (the validator is the Windows SDK's dxil.dll; no GPU, no game files)

AI-assisted: yes - OpenCode (MiniMax M3.1 Flash)

Checklist

  • Based on current main (60f7dcd90).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
    Not applicable: no translator rule; the change is in the container the translator writes.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5584046893 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2864). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T10:43:32Z. --- Claimed in the coordination issue as: SHADER-PSV0-NAME-PER-ELEMENT (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7306830693) ### What and why `d3d12/crates/leonida-shader/src/emit/container.rs` writes the `PSV0` part of the DXIL container. Its name table held **one copy of a semantic's name for all the elements that shared it**, while the validator compares this part with the one it computes from the module - and that one's table holds **a copy per element**. Every element after the first then carried a name offset the module's table does not have, and the validator refused the program: ``` error: Container part 'Pipeline State Validation' does not match expected for module. ``` Every program with an arbitrary semantic (`POSITION`, `TEXCOORD`, ...) has such elements, so this is not a corner case. The fix writes one copy per element, in element order, as DXC writes it (the `ISG1`/`OSG1` part above already did). The `PSV0` of a geometry stage built by hand is now byte for byte the one DXC 1.7 writes for the same signature, apart from the dependency-mask table, which the validator does not compare. **Where this shows, and where it does not.** The validator runs in `validate()` (`emit/mod.rs`), which is `#[cfg(windows)]` and **only validates when a `dxil.dll` loads**; without one it returns without validating, and the test passes. On a machine with the Windows SDK's `dxil.dll` the four tests that validate such a program fail (the same message with DXC 1.5.2005, 1.6.2104, 1.6.2112 and 1.7.2308 - not a version quirk). The CI's `windows-latest` runner has no `dxil.dll` that loads, so its job is green and cannot see this: the four tests read `ok` there without validating anything. So the CI is not the place this is caught; a developer machine with the SDK is. The container the translator writes is what the host's own D3D12 runtime validates, and a container the validator refuses is a pipeline the host refuses, so making the part byte for byte the one DXC writes is the safe shape regardless of which validator version the host has. The shader cache key follows the translator's sources (`build.rs`), so the key changes with this change and the caches built before it are rebuilt once. This touches `emit/container.rs`, which #2581 also touches, but in another part of the file: #2581 changes the `ISG1`/`OSG1` writer and the geometry block of `psv()`, this changes the name table further down in the same function. ### Tested - `cargo test -p leonida-shader --locked` - **fails on `main` `60f7dcd90`** in the 4 validator tests (the message above, with `dxil.dll` 101.7.2308.24) and **415 tests OK, 0 failed, 5 ignored** with the change on this pull request's head. - The new test `emit::container::tests::the_psv_name_table_holds_a_copy_of_a_name_per_element` - **fails on `main`** (both elements share the name offset 1) and passes with the change. - The `PSV0` part of the geometry stage the test builds is now byte for byte DXC 1.7's own for the same signature (compared part by part; only the dependency-mask table differs). - `cargo test -p leonida-gpu --lib --locked -- --test-threads=1` - 644 passed, 0 failed, 59 ignored. - `cargo test --workspace --locked --exclude leonida-gpu` - everything green except `xtask`'s `policy::tests::repository_passes_policy`, which fails on `main` as well (3 violations about `leonida-gpu/src/host.rs`, `emit/lower.rs` and `emit/indirect/amplify_dxil.rs`; #2815 is the fix for that, and this change touches none of those files). - No game files; no GPU needed (the validator is the Windows SDK's `dxil.dll`). GPUs tested: n/a (the validator is the Windows SDK's `dxil.dll`; no GPU, no game files) AI-assisted: yes - OpenCode (MiniMax M3.1 Flash) ### Checklist - [x] Based on current `main` (`60f7dcd90`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. Not applicable: no translator rule; the change is in the container the translator writes.
Neutron-0 commented 2026-12-01 10:52:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T10:52:21Z.


One note about this account's side of it: GitHub allows this account one open pull request in this repository, so this pull request holds the slot that #2837 (the census fix, reviewed and verified) had to give up. #2837 is closed with the reason on the record and is reopened as soon as this one is merged; three other fixes (a switch page with a test that keeps it in step, a reported skip instead of a silent one, and a retry for a dropped connection in the conflict labeler) are queued behind it, each with its branch pushed and tested.

Nothing about the four changes depends on each other, so they can be merged in any order; only the account's one-at-a-time limit orders them.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7308847206 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2864#issuecomment-7308847206). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T10:52:21Z. --- One note about this account's side of it: GitHub allows this account **one** open pull request in this repository, so this pull request holds the slot that #2837 (the census fix, reviewed and verified) had to give up. #2837 is closed with the reason on the record and is reopened as soon as this one is merged; three other fixes (a switch page with a test that keeps it in step, a reported skip instead of a silent one, and a retry for a dropped connection in the conflict labeler) are queued behind it, each with its branch pushed and tested. Nothing about the four changes depends on each other, so they can be merged in any order; only the account's one-at-a-time limit orders them.
Neutron-0 commented 2026-12-01 11:54:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T11:54:06Z.


Two practical notes for whoever looks at this:

The workflow run is waiting for an approval (action_required): a fork run of a first-time contributor needs a maintainer to approve it before the job runs. Approving it would let the d3d12 (windows-latest) job run on this head.

The job cannot see what this fixes, and that is worth knowing before reading it as green. validate() (d3d12/crates/leonida-shader/src/emit/mod.rs) is #[cfg(windows)] and only validates when a dxil.dll loads; without one it returns without validating and the test passes. No dxil.dll loads on the runner - it is in the log of main's run 46634364807: emit::rect::tests::rectangles_are_drawn_whole ... ok and emit::rect::tests::the_rectangle_stage_is_a_geometry_shader ... ok, i.e. the tests pass without validating anything.

On a machine with the Windows SDK's dxil.dll the same two fail on main with "Container part 'Pipeline State Validation' does not match expected for module" (DXC 1.5.2005, 1.6.2104, 1.6.2112 and 1.7.2308 all give it), and they pass on this head. LEONIDA_DXIL points the validator at a specific dxil.dll, so a reviewer with one can check it in a minute:

cargo test -p leonida-shader --lib --locked -- emit::

The finding about the job not seeing this at all is in the coordination issue (#2570).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7310323944 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2864#issuecomment-7310323944). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T11:54:06Z. --- Two practical notes for whoever looks at this: **The workflow run is waiting for an approval** (`action_required`): a fork run of a first-time contributor needs a maintainer to approve it before the job runs. Approving it would let the `d3d12 (windows-latest)` job run on this head. **The job cannot see what this fixes, and that is worth knowing before reading it as green.** `validate()` (`d3d12/crates/leonida-shader/src/emit/mod.rs`) is `#[cfg(windows)]` and only validates when a `dxil.dll` loads; without one it returns without validating and the test passes. No `dxil.dll` loads on the runner - it is in the log of `main`'s run 46634364807: `emit::rect::tests::rectangles_are_drawn_whole ... ok` and `emit::rect::tests::the_rectangle_stage_is_a_geometry_shader ... ok`, i.e. the tests pass without validating anything. On a machine with the Windows SDK's `dxil.dll` the same two fail on `main` with \"Container part 'Pipeline State Validation' does not match expected for module\" (DXC 1.5.2005, 1.6.2104, 1.6.2112 and 1.7.2308 all give it), and they pass on this head. `LEONIDA_DXIL` points the validator at a specific `dxil.dll`, so a reviewer with one can check it in a minute: ``` cargo test -p leonida-shader --lib --locked -- emit:: ``` The finding about the job not seeing this at all is in the coordination issue (#2570).
KelboLive commented 2026-12-01 13:20:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T13:20:56Z.

Review: COMMENTED


Confirmed against DXC: SetPSVSigElement() appends a name for every arbitrary element, and pre-1.8 validators compare the PSV0 part byte-for-byte with a regenerated one, so the old find() shared offset was the rejection. The new writer matches DXC's input/output/prim order and keeps system values at offset 0, with offsets relative to the string-table start (including its leading NUL) and lengths including the terminator — I checked base, terminator and count against docs/design.md:745-752 and tools/ps_interp_modes.py:116-171, and both read either form correctly.

The new test is a real guard: reverting only the writer fails it at container.rs:536 (assert_ne!(name_of(0), name_of(1)), left: 1, right: 1), and leonida-shader --lib is 410/0/5 here, with tests/test_ps_interp_modes.py 32/32. This is a writer, not a parser, so there is no name-table read to overrun; the production readers are bounded (emit/mod.rs:1628-1637 with split_at_checked, ps_interp_modes.py:150-153 with 0 < noff < len).

Two notes, neither blocking:

  • Memory now grows with element count, not unique names (O(sum(len+1))): two TEXCOORDs go 12 → 20 bytes. Bounded by D3D signature limits and no unbounded input, but worth one sentence in the commit message since it is the deliberate trade for byte-identity with DXC.
  • One divergence from DXC: DXC appends only for a non-empty arbitrary name; this code would append \0 and give an empty arbitrary name offset 1 instead of 0. Unreachable for valid modules (arbitrary semantics must be named), so not a blocker — but if the writer is ever used on a hand-built signature, that is the one case where it would differ again.

docs/design.md:745 describes the layout but not whether the table may be deduplicated; a clause saying it need not be would keep the next writer from reintroducing find().

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6132050538 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2864#pullrequestreview-6132050538). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T13:20:56Z. **Review:** COMMENTED --- Confirmed against DXC: `SetPSVSigElement()` appends a name for every arbitrary element, and pre-1.8 validators compare the PSV0 part byte-for-byte with a regenerated one, so the old `find()` shared offset was the rejection. The new writer matches DXC's input/output/prim order and keeps system values at offset 0, with offsets relative to the string-table start (including its leading NUL) and lengths including the terminator — I checked base, terminator and count against `docs/design.md:745-752` and `tools/ps_interp_modes.py:116-171`, and both read either form correctly. The new test is a real guard: reverting only the writer fails it at `container.rs:536` (`assert_ne!(name_of(0), name_of(1))`, `left: 1, right: 1`), and `leonida-shader --lib` is 410/0/5 here, with `tests/test_ps_interp_modes.py` 32/32. This is a writer, not a parser, so there is no name-table read to overrun; the production readers are bounded (`emit/mod.rs:1628-1637` with `split_at_checked`, `ps_interp_modes.py:150-153` with `0 < noff < len`). Two notes, neither blocking: - **Memory now grows with element count, not unique names** (`O(sum(len+1))`): two `TEXCOORD`s go 12 → 20 bytes. Bounded by D3D signature limits and no unbounded input, but worth one sentence in the commit message since it is the deliberate trade for byte-identity with DXC. - **One divergence from DXC**: DXC appends only for a non-empty arbitrary name; this code would append `\0` and give an empty arbitrary name offset 1 instead of 0. Unreachable for valid modules (arbitrary semantics must be named), so not a blocker — but if the writer is ever used on a hand-built signature, that is the one case where it would differ again. `docs/design.md:745` describes the layout but not whether the table may be deduplicated; a clause saying it need not be would keep the next writer from reintroducing `find()`.
merzleckeier commented 2026-12-01 15:44:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T15:44:41Z.


I ran an explicit DXIL validator comparison at 31991268 + 0ff8a532f. The synthetic rectangle geometry stage had SV_Position, TEXCOORD0, COLOR0 and TEXCOORD1, with and without a primitive-ID output. The fixture requires the validator to load and validates each result directly, rather than silently skipping if the DLL cannot be found.

With the PR, both cases passed the x64 dxil.dll from Microsoft DXC v1.7.2308 and the newer validator used by the local harness. In a local control I restored only PSV0 name deduplication. The v1.7.2308 validator rejected both variants with “Pipeline State Validation” not matching the module. The newer validator accepted both control variants. The stock name-table test also passed with the PR. Win64 target under Wine 11.22, synthetic code only.

Microsoft DXC v1.7.2308 release · MEASURED, AI-assisted (Codex).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7316433548 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2864#issuecomment-7316433548). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-01T15:44:41Z. --- I ran an explicit DXIL validator comparison at 31991268 + 0ff8a532f. The synthetic rectangle geometry stage had SV_Position, TEXCOORD0, COLOR0 and TEXCOORD1, with and without a primitive-ID output. The fixture requires the validator to load and validates each result directly, rather than silently skipping if the DLL cannot be found. With the PR, both cases passed the x64 dxil.dll from Microsoft DXC v1.7.2308 and the newer validator used by the local harness. In a local control I restored only PSV0 name deduplication. The v1.7.2308 validator rejected both variants with “Pipeline State Validation” not matching the module. The newer validator accepted both control variants. The stock name-table test also passed with the PR. Win64 target under Wine 11.22, synthetic code only. [Microsoft DXC v1.7.2308 release](https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.7.2308) · MEASURED, AI-assisted (Codex).
Neutron-0 commented 2026-12-02 05:36:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-02T05:36:43Z.


Closed to hand the slot over, not because of anything in the review.

GitHub allows this account one open pull request in this repository, and this one has been holding that slot while its workflow run waits for a maintainer's approval (action_required, a first-time contributor's fork run). The next pull request is ready and measured, so the slot goes there instead of idling here.

Nothing is lost: this pull request keeps its discussion and its review, and the opener reopens it - on a fresh main - as soon as the next one is merged. The queue is the census fix, the texture recheck switch, this one, then the page check, the hard-link skip and the label retry.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7336112189 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2864#issuecomment-7336112189). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-02T05:36:43Z. --- Closed to hand the slot over, not because of anything in the review. GitHub allows this account **one** open pull request in this repository, and this one has been holding that slot while its workflow run waits for a maintainer's approval (`action_required`, a first-time contributor's fork run). The next pull request is ready and measured, so the slot goes there instead of idling here. Nothing is lost: this pull request keeps its discussion and its review, and the opener reopens it - on a fresh `main` - as soon as the next one is merged. The queue is the census fix, the texture recheck switch, this one, then the page check, the hard-link skip and the label retry.
Neutron-0 commented 2026-12-02 05:39:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-02T05:39:22Z.


Reopened: the slot this account may hold in this repository is free again.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7336156972 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2864#issuecomment-7336156972). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-02T05:39:22Z. --- Reopened: the slot this account may hold in this repository is free again.

Pull request closed

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
ProjectLeonida/mandy!2864
No description provided.