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

Open
github-bot wants to merge 1 commit from github-bot/gh-3088 into main AGit
Owner

@⁠scoresby13 on GitHub · 2026-11-26 07:18 UTC · original
scoresby13:shader/psv-string-table-boundaries → main · +116 −7 · 1 files · 1 commits · open

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 #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

AI-assisted. No game data used.

**@⁠scoresby13** on GitHub · 2026-11-26 07:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/3088) `scoresby13:shader/psv-string-table-boundaries` → `main` · +116 −7 · 1 files · 1 commits · open ### 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 #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: https://git.gtahub.st/github/Marvisak--VIctory/issues/1633 AI-assisted. No game data used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 07:27:08 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 07:27 UTC · original · approved these changes

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

**@⁠Dukestar69** on GitHub · 2026-11-26 07:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3088#pullrequestreview-6070031725) · **approved these changes** 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).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 08:16 UTC · original

Independent verification for my claim #1633. 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.

**@⁠oni-swr** on GitHub · 2026-11-26 08:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/3088#issuecomment-7186397716) Independent verification for my claim https://git.gtahub.st/github/Marvisak--VIctory/issues/1633. 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 08:21 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 08:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/3088#issuecomment-7186490828) <!-- victory-triage v1 head=d7a95153c8088516273b8e30fdc4f68cb8548dd2 verdict=merge-candidate at=2026-11-26T08:17:59Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 08:29 UTC · original · reviewed

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3088#pullrequestreview-6070712781) · **reviewed** 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.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 11:01 UTC · original

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

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 868 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: psv_string_table_matches_whole_entries, psv_suffix_semantics_validate_with_dxil.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

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.
**@⁠futurepro62** on GitHub · 2026-11-26 11:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/3088#issuecomment-7190152093) 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** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **868 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `psv_string_table_matches_whole_entries`, `psv_suffix_semantics_validate_with_dxil`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **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.
This pull request can be merged automatically.
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/3088/head:github-bot/gh-3088'
git switch 'github-bot/gh-3088'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3088'
git switch 'github-bot/gh-3088'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3088'
git switch 'github-bot/gh-3088'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3088'
git switch 'main'
git merge --squash 'github-bot/gh-3088'
git switch 'main'
git merge --ff-only 'github-bot/gh-3088'
git switch 'main'
git merge 'github-bot/gh-3088'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3088
No description provided.