Shaders: use declared structured SRVs for scalar loads and record counts #995

Closed
github-bot wants to merge 2 commits from gh-pr/995/head into gh-pr/995/base
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 14:46 UTC · original
jeremygold02:codex/declared-structured-srv-scalar-loads → main · +478 −8 · 5 files · 2 commits · closed without merging

Scalar s_buffer_load_dword* instructions use byte addresses. On ffe310e, a descriptor-table SRV takes the raw-buffer path even when the original shader declares a structured SRV. Reading descriptor word 2 (NUM_RECORDS) as ordinary data can also stop translation. Native stride alone cannot identify the view because a raw SRV can carry the same stride metadata.

This change checks the original PSV0 declaration and the exact, statically addressed native table slot. A unique, single-register structured SRV with a matching native binding uses structured addressing. Each dword of a wide load gets its own record index and byte offset, including when the load crosses a record boundary. A use of the record count as ordinary data or through a phi obtains it from GetDimensions. Loads that only need the descriptor handle omit that query. Raw, ambiguous, dynamically selected and mixed-consumer bindings keep their existing behavior.

Relationship to other PRs

#984, opened while this branch was being verified, also splits each scalar dword address and covers flat vector loads, stores and atomics. It selects the structured path from table binding and aligned stride. The scalar address arithmetic overlaps. This patch adds the declaration and slot check and recovers the consumed record count for that same structured SRV.

#136 demonstrated the structured scalar case using native stride. #329 recovers counts for descriptors with no tracked resource consumer. #437 preserves raw scalar loads, and #953 uses a raw view to query size for a scalar consumer. The case here reads an element count from a declared structured view and addresses each scalar dword within that view.

Verification

  • On the submitted revision against ffe310e, all five new regression tests and the upstream stencil-export test passed with Windows SDK 10.0.26100.0 dxil.dll. The broader victory-shader library run passed 103 tests, with one benchmark ignored and 22 GPU or differential cases filtered. cargo clippy --locked -p victory-shader --all-targets --all-features -- -D warnings passed.
  • On parent c2e7254, two vertex shaders failed on the scalar descriptor-data read. Both translated and passed SDK validation on 89b6c67. Each emitted one live count query and 21 dword loads split into record index and byte offset.
  • Four small dispatches on a physical RTX 5070 checked the words on either side of an 80-byte record boundary, a nonzero view start, a matching raw subview, and both outcomes of a count guard. All four fences completed and the output canaries were preserved. Revision 89b6c67 reproduced the three hardware-tested DXIL containers byte for byte.
  • An earlier comparison of the same change on d2a4bae covered 25,694 inputs. Fifteen additional shaders passed SDK validation and all 21,971 previously valid shaders still passed. The emitted code changed for 18,136 of those previously valid shaders.

Gameplay impact remains unverified.

**@⁠jeremygold02** on GitHub · 2026-11-24 14:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/995) `jeremygold02:codex/declared-structured-srv-scalar-loads` → `main` · +478 −8 · 5 files · 2 commits · closed without merging Scalar `s_buffer_load_dword*` instructions use byte addresses. On `ffe310e`, a descriptor-table SRV takes the raw-buffer path even when the original shader declares a structured SRV. Reading descriptor word 2 (`NUM_RECORDS`) as ordinary data can also stop translation. Native stride alone cannot identify the view because a raw SRV can carry the same stride metadata. This change checks the original `PSV0` declaration and the exact, statically addressed native table slot. A unique, single-register structured SRV with a matching native binding uses structured addressing. Each dword of a wide load gets its own record index and byte offset, including when the load crosses a record boundary. A use of the record count as ordinary data or through a phi obtains it from `GetDimensions`. Loads that only need the descriptor handle omit that query. Raw, ambiguous, dynamically selected and mixed-consumer bindings keep their existing behavior. ### Relationship to other PRs #984, opened while this branch was being verified, also splits each scalar dword address and covers flat vector loads, stores and atomics. It selects the structured path from table binding and aligned stride. The scalar address arithmetic overlaps. This patch adds the declaration and slot check and recovers the consumed record count for that same structured SRV. #136 demonstrated the structured scalar case using native stride. #329 recovers counts for descriptors with no tracked resource consumer. #437 preserves raw scalar loads, and #953 uses a raw view to query size for a scalar consumer. The case here reads an element count from a declared structured view and addresses each scalar dword within that view. ### Verification - On the submitted revision against `ffe310e`, all five new regression tests and the upstream stencil-export test passed with Windows SDK 10.0.26100.0 `dxil.dll`. The broader `victory-shader` library run passed 103 tests, with one benchmark ignored and 22 GPU or differential cases filtered. `cargo clippy --locked -p victory-shader --all-targets --all-features -- -D warnings` passed. - On parent `c2e7254`, two vertex shaders failed on the scalar descriptor-data read. Both translated and passed SDK validation on `89b6c67`. Each emitted one live count query and 21 dword loads split into record index and byte offset. - Four small dispatches on a physical RTX 5070 checked the words on either side of an 80-byte record boundary, a nonzero view start, a matching raw subview, and both outcomes of a count guard. All four fences completed and the output canaries were preserved. Revision `89b6c67` reproduced the three hardware-tested DXIL containers byte for byte. - An earlier comparison of the same change on `d2a4bae` covered 25,694 inputs. Fifteen additional shaders passed SDK validation and all 21,971 previously valid shaders still passed. The emitted code changed for 18,136 of those previously valid shaders. Gameplay impact remains unverified.
Use the original PSV binding and the exact native table slot to recover the record count and split scalar byte offsets within structured records. Preserve existing handling of ambiguous, mixed-consumer, and raw views.

Refs: #136, #329, #437
Merge upstream main, retain both shader regression tests, and pass absent PSV metadata in the three synthetic fixtures that construct lowering inputs directly.

Refs: #136, #329, #437
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:16:28 +00:00
github-bot closed this pull request 2026-11-26 04:16:28 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 14:54 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 78c8078: cargo test -p victory-shader passes, 125 passed / 0 failed. Workspace baseline on main (ffe310e) was green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 14:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/995#issuecomment-7135153963) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 78c8078: `cargo test -p victory-shader` passes, 125 passed / 0 failed. Workspace baseline on main (ffe310e) was green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 15:47 UTC · original

I compared the same two mission vertex shaders on Windows 11 with Windows SDK 10.0.26100.0. The draw-entry observations for the affected slot are in the earlier verification on #136.

Revision SDK-valid outputs Result for the affected 80-byte structured SRV
ffe310e (main) 0/2 Both stop at the scalar descriptor-data read.
c42cbb0 (#953) 2/2 Neither output queries dimensions on an 80-byte structured handle.
5011645 (#984) 0/2 Both stop at the same descriptor-data read as main.
78c8078 (this PR) 2/2 Each output queries the count once and splits all 21 dword loads from the same binding into record index and byte offset.

I also ran #984’s separate one-thread buffer-read regression on a physical RTX 5070. I restricted the test adapter loop to hardware and checked the device LUID’s adapter description before dispatch. Both scalar and flat vector reads returned the expected word at all nine offsets across three 56-byte records. That fixture covers a distinct case worth retaining alongside the count-consuming shaders here. The mission shaders were translated offline.

**@⁠jeremygold02** on GitHub · 2026-11-24 15:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/995#issuecomment-7136608409) I compared the same two mission vertex shaders on Windows 11 with Windows SDK 10.0.26100.0. The draw-entry observations for the affected slot are in [the earlier verification on #136](https://git.gtahub.st/github/Marvisak--VIctory/pulls/136). | Revision | SDK-valid outputs | Result for the affected 80-byte structured SRV | | --- | ---: | --- | | `ffe310e` (main) | 0/2 | Both stop at the scalar descriptor-data read. | | `c42cbb0` (#953) | 2/2 | Neither output queries dimensions on an 80-byte structured handle. | | `5011645` (#984) | 0/2 | Both stop at the same descriptor-data read as main. | | `78c8078` (this PR) | 2/2 | Each output queries the count once and splits all 21 dword loads from the same binding into record index and byte offset. | I also ran #984’s separate one-thread buffer-read regression on a physical RTX 5070. I restricted the test adapter loop to hardware and checked the device LUID’s adapter description before dispatch. Both scalar and flat vector reads returned the expected word at all nine offsets across three 56-byte records. That fixture covers a distinct case worth retaining alongside the count-consuming shaders here. The mission shaders were translated offline.
Author
Owner

@⁠jtrudeau1530 on GitHub · 2026-11-24 16:39 UTC · original

Validated this exact change (78c8078a) locally on RX 7900 XT / RADV under Wine 11.18 and vkd3d-proton 3.2.0. The test base also contains the mapped-copy fix and #1056; no title-derived fixtures were used.

A synthetic scalar-buffer fixture passed 12 hardware dispatches with exact eight-word readbacks: stride 80, x2/x4 loads across record boundaries at byte offsets 76 and 156, a count-derived last-record address, both count-guard outcomes, and raw-buffer controls with the same native stride. Canary words remain intact. The raw count remains refused rather than being inferred from stride. Microsoft DXIL validator release 1.7.2308 was required and passed.

The identical declaration/count fixture on the test-only parent reproduces the original scalar-memory-read refusal; the patched candidate passes. This establishes those scalar cases, not full game correctness or performance.

**@⁠jtrudeau1530** on GitHub · 2026-11-24 16:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/995#issuecomment-7138017095) Validated this exact change (78c8078a) locally on RX 7900 XT / RADV under Wine 11.18 and vkd3d-proton 3.2.0. The test base also contains the mapped-copy fix and #1056; no title-derived fixtures were used. A synthetic scalar-buffer fixture passed 12 hardware dispatches with exact eight-word readbacks: stride 80, x2/x4 loads across record boundaries at byte offsets 76 and 156, a count-derived last-record address, both count-guard outcomes, and raw-buffer controls with the same native stride. Canary words remain intact. The raw count remains refused rather than being inferred from stride. Microsoft DXIL validator release 1.7.2308 was required and passed. The identical declaration/count fixture on the test-only parent reproduces the original scalar-memory-read refusal; the patched candidate passes. This establishes those scalar cases, not full game correctness or performance.
Author
Owner

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-24 16:51 UTC · original

Independent verification at 78c8078 on Windows 11, RTX 5070 Ti (driver 32.0.16.2135) + WARP (VICTORY_D3D12_DEBUG=1), dxil.dll 1.8.2502.11, Rust 1.98.1 against upstream/main (ffe310eb):

  • Cleanly on ffe310eb; cargo xtask policy: 154 files ok; both clippy checks pass.
  • cargo test --workspace --locked: 347 passed, 0 failed, 6 ignored.
  • victory-shader --features host (VICTORY_D3D12_DEBUG=1, RTX 5070 Ti & VICTORY_WARP=1): 125 passed, 0 failed, 1 ignored (0 D3D12 debug errors/warnings).
  • victory-gpu --features diagnostics (VICTORY_D3D12_DEBUG=1, RTX 5070 Ti & VICTORY_D3D12_WARP=1): 53 passed, 0 failed, 1 ignored (0 D3D12 debug errors/warnings).
  • Zero unsafe added; PSV0 + unique static slot check + wide-load dword splitting avoids the raw bytes/4 NUM_RECORDS mismatch in #953 (note textual conflict with #953 in lower.rs — prefer #995).

AI-assisted verification on local RTX 5070 Ti + WARP; no game data.

**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-24 16:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/995#issuecomment-7138310655) Independent verification at `78c8078` on **Windows 11**, **RTX 5070 Ti** (driver `32.0.16.2135`) + **WARP** (`VICTORY_D3D12_DEBUG=1`), **dxil.dll `1.8.2502.11`**, **Rust `1.98.1`** against `upstream/main` (`ffe310eb`): - Cleanly on `ffe310eb`; `cargo xtask policy`: `154 files ok`; both `clippy` checks pass. - `cargo test --workspace --locked`: **347 passed, 0 failed, 6 ignored**. - `victory-shader --features host` (`VICTORY_D3D12_DEBUG=1`, RTX 5070 Ti & `VICTORY_WARP=1`): **125 passed, 0 failed, 1 ignored** (0 D3D12 debug errors/warnings). - `victory-gpu --features diagnostics` (`VICTORY_D3D12_DEBUG=1`, RTX 5070 Ti & `VICTORY_D3D12_WARP=1`): **53 passed, 0 failed, 1 ignored** (0 D3D12 debug errors/warnings). - Zero `unsafe` added; `PSV0` + unique static slot check + wide-load dword splitting avoids the raw `bytes/4` `NUM_RECORDS` mismatch in `#953` (note textual conflict with `#953` in `lower.rs` — prefer `#995`). AI-assisted verification on local RTX 5070 Ti + WARP; no game data.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 19:50 UTC · original

Offline measurement on a retail dump, and the shader tests on Ada

Result: +15 programs over main, 0 lost.

Offline. I merged head 78c8078 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,739 with this PR.

Failure on main Gained
emit: a scalar memory read as data 15

All 15 are among the programs that #1319 gains. Another 114 programs move from "a scalar memory read as data" on to "a descriptor's address or format read as data". That is the reason #1597 targets, and I'm measuring this PR stacked on #1597.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 125, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 19:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/995#issuecomment-7142657848) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: +15 programs over `main`, 0 lost.** **Offline.** I merged head 78c8078 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,739 with this PR. | Failure on `main` | Gained | |---|---| | emit: a scalar memory read as data | 15 | All 15 are among the programs that #1319 gains. Another 114 programs move from "a scalar memory read as data" on to "a descriptor's address or format read as data". That is the reason #1597 targets, and I'm measuring this PR stacked on #1597. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 125, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠anlnimus on GitHub · 2026-11-24 20:33 UTC · original

Hardware note from testing on AMD Radeon RX 6900 XT (RDNA2), Adrenalin driver 32.0.21045.16010, Windows 11 Pro (10.0.26200):

While verifying structured SRVs on hardware in a local integration build (#986 + #995-style lowering), reading a structured heap SRV (StructureByteStride > 0) through a raw DXIL ByteAddressBuffer handle returned all zeros on RX 6900 XT (even where WARP / NVIDIA tolerate the view/resource kind mismatch). Lowering scalar buffer loads on structured table SRVs with a matching StructuredBuffer handle ((12, stride) + UDiv/URem element indexing) returned the exact expected bytes on RX 6900 XT.

This directly supports #995's motivation on AMD RDNA2 hardware. (No game assets or dumps attached; tested with AI assistance.)

**@⁠anlnimus** on GitHub · 2026-11-24 20:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/995#issuecomment-7143733795) Hardware note from testing on **AMD Radeon RX 6900 XT (RDNA2)**, Adrenalin driver `32.0.21045.16010`, Windows 11 Pro (`10.0.26200`): While verifying structured SRVs on hardware in a local integration build (`#986` + #995-style lowering), reading a structured heap SRV (`StructureByteStride > 0`) through a raw DXIL `ByteAddressBuffer` handle returned all zeros on RX 6900 XT (even where WARP / NVIDIA tolerate the view/resource kind mismatch). Lowering scalar buffer loads on structured table SRVs with a matching `StructuredBuffer` handle (`(12, stride)` + `UDiv`/`URem` element indexing) returned the exact expected bytes on RX 6900 XT. This directly supports #995's motivation on AMD RDNA2 hardware. (No game assets or dumps attached; tested with AI assistance.)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:29 UTC · original

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Structured addressing for scalar loads chosen from PSV0, and record counts: main settled this the other way (scalar loads read raw views by byte address, emit/mod.rs notes) and reads record counts through getDimensions (75677cb8).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/995#issuecomment-7148568348) Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Structured addressing for scalar loads chosen from PSV0, and record counts: main settled this the other way (scalar loads read raw views by byte address, emit/mod.rs notes) and reads record counts through getDimensions (75677cb8). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 01:45 UTC · original

Stacked results

  • On #1402: 0 gained, 0 lost, and no failure reason changes. On main this PR gained 15 programs, and all of them are among #1319's gains (inside #1402).
  • On #1597: at first, this PR cost 21 programs. It turns some raw views into structured ones, and #1597 did not yet treat a structured view's dword 1 as hidden. #1597's commit cc7d30a fixes that. Measured on the base #1597 had before that commit, with only the one-line fix added, #995 is now +1, 0 lost on top of it.

The merge with #1402 conflicts in 4 hunks (emit/lower.rs, emit/mod.rs). In two places the intents contradict each other:

  1. On the scalar-load path, an SRV raw view takes this PR's structured stride when it is known. Otherwise #1402's raw or UAV choice applies.
  2. In #953's s_buffer_load arm, the view becomes structured if this PR's record-count and declaration conditions hold. Otherwise it stays #953's raw view.

This PR's test scalar_table_record_count_requires_an_exact_unambiguous_declaration expects a refusal, but with #953 the merge falls back to a raw view. I had to relax that test to merge. On the merge, cargo test --locked -p victory-shader --lib: 142 passed, 0 failed.

Method: victory translate --validate --list on shaders.rpf (1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs). AI-assisted (Claude Code). No shader names or data are included, per the asset policy.

**@⁠sinan-cmyk** on GitHub · 2026-11-25 01:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/995#issuecomment-7149927102) ### Stacked results - **On #1402:** 0 gained, 0 lost, and no failure reason changes. On `main` this PR gained 15 programs, and all of them are among #1319's gains (inside #1402). - **On #1597:** at first, this PR cost 21 programs. It turns some raw views into structured ones, and #1597 did not yet treat a structured view's dword 1 as hidden. #1597's commit cc7d30a fixes that. Measured on the base #1597 had before that commit, with only the one-line fix added, #995 is now **+1, 0 lost** on top of it. The merge with #1402 conflicts in 4 hunks (`emit/lower.rs`, `emit/mod.rs`). In two places the intents contradict each other: 1. On the scalar-load path, an SRV raw view takes this PR's structured stride when it is known. Otherwise #1402's raw or UAV choice applies. 2. In #953's `s_buffer_load` arm, the view becomes structured if this PR's record-count and declaration conditions hold. Otherwise it stays #953's raw view. This PR's test `scalar_table_record_count_requires_an_exact_unambiguous_declaration` expects a refusal, but with #953 the merge falls back to a raw view. I had to relax that test to merge. On the merge, `cargo test --locked -p victory-shader --lib`: 142 passed, 0 failed. Method: `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs). AI-assisted (Claude Code). No shader names or data are included, per the asset policy.

Pull request closed

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!995
No description provided.