Skip to content

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

Open
Neutron-0 wants to merge 1 commit into
ProjectLeonida:mainfrom
Neutron-0:fix/psv0-name-per-element
Open

Neutron-0 wants to merge 1 commit into
ProjectLeonida:mainfrom
Neutron-0:fix/psv0-name-per-element

Conversation

@Neutron-0

@Neutron-0 Neutron-0 commented Dec 1, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: SHADER-PSV0-NAME-PER-ELEMENT (#2570 (comment))

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 27613ab6b 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 - 597 tests OK, 0 failed, 53 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; policy: a Rust source file is not data, whatever its size #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 (27613ab6b).
  • 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.

@Neutron-0

Copy link
Copy Markdown
Author

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

Neutron-0 commented Dec 1, 2026 •

Copy link
Copy Markdown
Author

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

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

@merzleckeier

Copy link
Copy Markdown
Contributor

I ran an explicit DXIL validator comparison at 3199126 + 0ff8a53. 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).

@Neutron-0
Neutron-0 force-pushed the fix/psv0-name-per-element branch from 3199126 to c864439 Compare December 1, 2026 17:29
…(SHADER-PSV0-NAME-PER-ELEMENT)

The validator compares the PSV0 part with the one it computes from the
module, and that one's name table holds a copy of a semantic's name per
element. Ours held one copy for all the elements that shared the name, so
every later element's name offset differed from the module's and the
validator refused the program with "Container part 'Pipeline State
Validation' does not match expected for module".

Every program with an arbitrary semantic (POSITION, TEXCOORD, ...) has
one, so the 4 tests that validate such a program failed on Windows with
any dxil.dll of DXC 1.5.2005 or newer. The validator block is
#[cfg(windows)], so a Linux CI job cannot see it.

Write one copy per element, as DXC writes it: 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 the validator does
not compare.

Test: the new test in emit/container.rs fails on main (both elements
share the name offset 1) and passes with the change; the 4 validator
tests pass with it (405 tests, 0 failed).

Needs no game files and no GPU.

AI-assisted: yes - MiniMax M3.1 Flash (OpenCode).
@Neutron-0
Neutron-0 force-pushed the fix/psv0-name-per-element branch from c864439 to d9bc50c Compare December 1, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants