Skip to content

Shaders: match whole entries in the PSV0 string table - #3088

Open
scoresby13 wants to merge 1 commit into
Marvisak:mainfrom
scoresby13:shader/psv-string-table-boundaries
Open

scoresby13 wants to merge 1 commit into
Marvisak:mainfrom
scoresby13:shader/psv-string-table-boundaries

Conversation

@scoresby13

Copy link
Copy Markdown

Summary

container::psv interned arbitrary semantic names (e.kind == 0) using find(&strings, &needle) via windows(needle.len()).position(...). Because find matches at any byte offset rather than only at NUL-delimited entry starts (table[at - 1] == 0), an arbitrary semantic name that is a proper suffix of an earlier one (for example, standard HLSL BINORMAL followed by NORMAL, or WORLD_COLOR followed by COLOR) reused a mid-string offset (such as offset 3 inside \0BINORMAL\0) instead of appending its own entry.

In Microsoft DXC (lib/DxilValidation/DxilContainerValidation.cpp), StringTableVerifier populates OffsetToUseCountMap only at NUL-terminated entry starts (0 and i + 1 after each '\0'), so PSVContentVerifier::VerifySignatureElement rejects mid-string SemanticName offsets via MarkUse, and pre-1.8 dxil.dll validators reject the mismatching PSV0 part.

Fix

  • Replace find with find_string(table, name), which walks whole NUL-delimited entries starting at index 1 and only matches when the entire entry equals name.
  • Map empty arbitrary semantic names directly to offset 0 without allocating a temporary Vec<u8>, while keeping identical full semantic names shared (matching main's layout per Shaders: PSV0 and signatures laid out as the validator expects #1208).

Verification

  • Reproduced failure on unpatched main (63bcca4):
    • cargo test -p victory-shader --lib emit::container::tests:
      • psv_string_table_matches_whole_entries failed: emitted \0BINORMAL\0WORLD_COLOR\0\0\0 (skipping NORMAL and COLOR).
      • psv_suffix_semantics_validate_with_dxil failed against Windows SDK 10.0.22621.0\x64\dxil.dll (101.6.2112.13): error: Container part 'Pipeline State Validation' does not match expected for module.\nValidation failed.
  • Patched checks (Windows 11 x64 MSVC, Rust 1.98.1):
    • cargo test -p victory-shader --lib emit::container::tests: 3 passed, 0 failed (including live dxil.dll validation).
    • cargo test -p victory-shader --lib emit::tests::constant_color_validates: 1 passed, 0 failed.
    • cargo test -p victory-shader --lib -- --test-threads=1: 292 passed, 3 ignored, 12 pre-existing failures unrelated to this change (10 Intel UHD 730 hardware GPU mismatches where WARP passes; 2 pre-existing repeated-TEXCOORD tests rejected by local dxil.dll 1.6 101.6.2112.13 instead of validator 1.8).
    • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
    • cargo clippy -p victory-shader --all-targets --all-features -- -D warnings: clean.
    • cargo xtask policy: asset policy: 191 files ok.

Claim comment: #1633 (comment)

AI-assisted. No game data used.

@Dukestar69 Dukestar69 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.

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (with dxil.dll validator):

  • cargo test -p victory-shader psv: 3 passed, 0 failed (including psv_string_table_matches_whole_entries and psv_suffix_semantics_validate_with_dxil).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown

Independent verification for my claim #1633 (comment). Test report only; no source review. Disclosure: checks run by Claude Code (Claude Sonnet 5.5), coordinated by Codex (gpt-6.2-sol).

Tested: PR head d7a95153c8088516273b8e30fdc4f68cb8548dd2, parent 63bcca43c6a00a758510398fa43096ce7e4f7df0 (current main). Windows 11 x64, Rust 1.98.1 (pinned), cargo -j 4 --locked. Synthetic inputs only: no game files, dumps or shader names.

Validator: dxil.dll 1.8.2502.11 from the installed Windows SDK 10.0.26100.0, which the test's default_path() selects. The live test skips silently when the DLL cannot be loaded (if let Ok(...)), so I checked with a throwaway probe in a scratch copy that it did not skip. At the head it printed path = the 26100 DLL, loaded = true, validate OK, container hash unchanged. With VICTORY_DXIL pointing at a nonexistent path the same test still reports ok without validating, so a bare ok does not prove validation ran.

Results at the head (cargo test -p victory-shader --lib psv):

  • psv_string_table_matches_whole_entries: ok
  • psv_suffix_semantics_validate_with_dxil: ok (validator loaded and validated, per the probe)
  • sample_interpolated_inputs_set_psv_sample_frequency: ok
  • Full victory-shader --lib at the head with VICTORY_WARP=1 and VICTORY_D3D12_WARP=1, adapter confirmed as "Microsoft Basic Render Driver" (software): 300 passed, 4 failed, 3 ignored. The 4 failures are emit::synthetic_tests::{gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out, a_mask_joined_with_data_at_a_uniform_loop_is_its_number}. The same 4 fail identically at the parent on WARP, twice in a row. They are pre-existing, unrelated to container.rs, and none uses the PSV path.

Baseline control (parent source plus the PR's two new tests, no other change):

  • psv_string_table_matches_whole_entries: fails at the parent. The table is \0BINORMAL\0WORLD_COLOR\0\0 instead of \0BINORMAL\0NORMAL\0WORLD_COLOR\0COLOR\0\0, because suffix matches resolve NORMAL into BINORMAL and COLOR into WORLD_COLOR. It passes at the head.
  • psv_suffix_semantics_validate_with_dxil: passes at the parent too. With the 1.8.2502.11 validator this container validates either way, so on this validator the live test does not discriminate parent from head. The synthetic table test is the one that demonstrates the fix.

Notes: the older SDK 10.0.19041.0 dxil.dll (10.0.19041.5609) is not usable for this test. It rejects the container with "Unknown shader model 'vs_6_6'", independent of this PR. The PSV tests themselves create no D3D12 device; the device-backed run above used WARP only. Scratch worktree, fixtures and cargo target directory were removed afterwards.

One disclosure: before I set the WARP variables, I ran the full victory-shader --lib once with no WARP switch, so that run may have used this machine's physical adapter. It is not counted above. The reported WARP run is the repeat with the switches set and a software adapter.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. In emit/container.rs (psv), arbitrary semantic names were interned with find, a substring search. A name that is a suffix of an earlier one (NORMAL after BINORMAL) got an offset in the middle of the earlier entry. find_string now matches only whole NUL-terminated entries from offset 1, and empty names still map to offset 0, so the layout for names without such a collision is unchanged. Names come from the title's own signature parts (emit/mod.rs, String::from_utf8_lossy(name)), so this collision can happen. Whole-entry dedup is what DXC's PSV string table and validator expect. psv_string_table_matches_whole_entries checks the exact table and offsets, and psv_suffix_semantics_validate_with_dxil runs the validator when one is present.

CI: passing (check).


Generated by Claude Code

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The whole-entry lookup in find_string (crates/victory-shader/src/emit/container.rs:239-255) cleanly fixes the PSV0 suffix-reuse bug and preserves 4-byte alignment and empty/system-value offset 0.

Verified locally on Windows 11 with Windows SDK 10.0.26100.0\x64\dxil.dll:

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo test -p victory-shader --lib --locked -- emit::container::tests: 3/3 passed (including psv_string_table_matches_whole_entries and psv_suffix_semantics_validate_with_dxil)

Two small notes for consideration:

  1. In psv_suffix_semantics_validate_with_dxil (emit/container.rs:544-550), if let Ok(validator) = Validator::load() silently passes if VICTORY_DXIL points to a missing/broken DLL. Requiring Validator::load() to succeed when VICTORY_DXIL is explicitly set (or logging the skip reason otherwise) would prevent false-green validator runs.
  2. Exact duplicate semantic names across input/output signatures (e.g., TEXCOORD in both) still deduplicate to one entry here. Older DXC validators (such as v1.8.2407) rebuild PSV0 by appending a string per arbitrary signature element and byte-comparing the result, whereas newer DXC compares by semantic content. Worth adding a note or a duplicate-name test case if compatibility with older dxil.dll builds is targeted.

@futurepro62

Copy link
Copy Markdown

NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head d7a9515 (on its base 63bcca4).

Tested

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

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.

6 participants