Shaders: scalar loads through a heap buffer that vector accesses use read a buffer view #1015

Closed
justrealyme wants to merge 2 commits from upstream-pr/1015 into main
justrealyme commented 2026-11-24 15:04:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by justrealyme on 2026-11-24T15:04:18Z.


What

A descriptor fetched from the resource heap by an index the program computes (s_load_dwordx4 s[n:n+3], <ResourceHeap root>, <index * 32>) has no used-resource entry, so used_kind returns None. A scalar buffer load (s_buffer_load_dword*) through such a descriptor was therefore lowered through a 64 KiB constant buffer handle (annotateHandle {13, 65536} + cbufferLoadLegacy).

On the console a scalar load works through any buffer descriptor, and titles read the same bindless buffer both ways: scalar loads for its header, vector loads (buffer_load_*) for its contents. In the title's heap that slot holds the buffer SRV the title made. Reading it through a CBV handle is a descriptor of the wrong type, which D3D12 leaves undefined (the host takes the SRV's bits as a CBV's address and size).

smem now reads such a descriptor (no listed kind) as a raw buffer, as it already does for table SRVs, when vector buffer accesses use the same descriptor source:

  • only loads (buffer_load_*, tbuffer_load_*): a raw SRV ({11, 0} + rawBufferLoad);
  • any store or atomic: a raw UAV ({11 | 0x1000, 0}), as #1055 does for a table's UAV.

A descriptor that only scalar loads read is lowered as before. Nothing says it isn't a CBV.

Example

compute eeed82b877b44b5f (the program behind the NVIDIA world hang in #578 / #71) reads two mesh buffers it fetches from the heap by index, with 33 + 8 vector loads and 21 scalar loads. All 21 went through CBV handles. With this change, none do.

This does not fix that hang: it still hangs on an RTX 5070 Ti with this change (details in #578). This is a correctness fix of its own.

Scope

victory translate --validate on the title's shaders.rpf (26,084 programs), with and without the change:

  • 38,829 scalar loads in about 1,900 programs now read a raw SRV instead of a CBV handle. No program in this title has the written (UAV) case, which is included so the rule has no wrong branch.
  • Emitted and validated counts are identical (12,231 / 12,155 vertex+pixel, 1,441 / 1,417 compute, 8,214 / 8,152 mesh), as is every failure reason count.

Related: #1055 fixes the neighbouring case, a descriptor whose listed kind is a UAV. Both touch the same lines of smem, so whichever lands second needs a small rebase.

Verification

  • New test scalar_loads_through_a_heap_buffer_that_vector_accesses_use_read_a_buffer_view: a heap descriptor at an index from a root constant, read by s_buffer_load_dword alone, with a buffer_load_dword, or with a buffer_store_dword. It asserts 1 / 0 / 0 CBV heap handles. It fails on main (the load case gives 1) and passes with the change. Synthetic code, assembled with llvm-mc -mcpu=gfx1013.
  • To count heap handles annotated as CBVs, Shader/Lowered get a test-only cbuffer_handles counter next to nonuniform_handles.
  • Windows 11 build 26300, Rust 1.98.1, VS 2022 Build Tools: cargo clippy --workspace --all-targets --locked -- -D warnings and the same with --all-features are clean. cargo test --workspace --locked passes (343 passed, 0 failed). cargo xtask policy passes (154 files ok). rustfmt adds no new differences to the two files.
  • In the title, on an NVIDIA RTX 5070 Ti, driver 617.42, diag build, VICTORY_D3D12_DRED=1. On top of main + #578 + @JFIREonFIRE's fix/refuse-unsized-wave64-compute (to get past the hang above), the first commit ran 14.2 min in the world with no device removal, 0 refused pipelines and no errors. Without the change: 18.7 min, also with no removal. Draws per frame were 376 with the change and 350 without.

AI-assisted (Claude Code). No game data in the change or the test.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6584813098 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1015). Originally posted by [justrealyme](https://github.com/justrealyme) on 2026-11-24T15:04:18Z. --- ## What A descriptor fetched from the resource heap by an index the program computes (`s_load_dwordx4 s[n:n+3], <ResourceHeap root>, <index * 32>`) has no used-resource entry, so `used_kind` returns `None`. A scalar buffer load (`s_buffer_load_dword*`) through such a descriptor was therefore lowered through a **64 KiB constant buffer handle** (`annotateHandle {13, 65536}` + `cbufferLoadLegacy`). On the console a scalar load works through any buffer descriptor, and titles read the same bindless buffer both ways: scalar loads for its header, vector loads (`buffer_load_*`) for its contents. In the title's heap that slot holds the **buffer SRV** the title made. Reading it through a CBV handle is a descriptor of the wrong type, which D3D12 leaves undefined (the host takes the SRV's bits as a CBV's address and size). `smem` now reads such a descriptor (no listed kind) as a raw buffer, as it already does for table SRVs, when vector buffer accesses use the same descriptor source: - only loads (`buffer_load_*`, `tbuffer_load_*`): a raw **SRV** (`{11, 0}` + `rawBufferLoad`); - any store or atomic: a raw **UAV** (`{11 | 0x1000, 0}`), as #1055 does for a table's UAV. A descriptor that only scalar loads read is lowered as before. Nothing says it isn't a CBV. ## Example `compute eeed82b877b44b5f` (the program behind the NVIDIA world hang in #578 / #71) reads two mesh buffers it fetches from the heap by index, with 33 + 8 vector loads and 21 scalar loads. All 21 went through CBV handles. With this change, none do. This does **not** fix that hang: it still hangs on an RTX 5070 Ti with this change (details in #578). This is a correctness fix of its own. ## Scope `victory translate --validate` on the title's `shaders.rpf` (26,084 programs), with and without the change: - **38,829 scalar loads in about 1,900 programs** now read a raw SRV instead of a CBV handle. No program in this title has the written (UAV) case, which is included so the rule has no wrong branch. - Emitted and validated counts are identical (12,231 / 12,155 vertex+pixel, 1,441 / 1,417 compute, 8,214 / 8,152 mesh), as is every failure reason count. Related: #1055 fixes the neighbouring case, a descriptor whose listed kind is a UAV. Both touch the same lines of `smem`, so whichever lands second needs a small rebase. ## Verification - New test `scalar_loads_through_a_heap_buffer_that_vector_accesses_use_read_a_buffer_view`: a heap descriptor at an index from a root constant, read by `s_buffer_load_dword` alone, with a `buffer_load_dword`, or with a `buffer_store_dword`. It asserts 1 / 0 / 0 CBV heap handles. It fails on `main` (the load case gives 1) and passes with the change. Synthetic code, assembled with `llvm-mc -mcpu=gfx1013`. - To count heap handles annotated as CBVs, `Shader`/`Lowered` get a test-only `cbuffer_handles` counter next to `nonuniform_handles`. - Windows 11 build 26300, Rust 1.98.1, VS 2022 Build Tools: `cargo clippy --workspace --all-targets --locked -- -D warnings` and the same with `--all-features` are clean. `cargo test --workspace --locked` passes (343 passed, 0 failed). `cargo xtask policy` passes (154 files ok). rustfmt adds no new differences to the two files. - In the title, on an **NVIDIA RTX 5070 Ti, driver 617.42**, diag build, `VICTORY_D3D12_DRED=1`. On top of `main` + #578 + @JFIREonFIRE's `fix/refuse-unsized-wave64-compute` (to get past the hang above), the first commit ran 14.2 min in the world with no device removal, 0 refused pipelines and no errors. Without the change: 18.7 min, also with no removal. Draws per frame were 376 with the change and 350 without. AI-assisted (Claude Code). No game data in the change or the test. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Zipettte commented 2026-11-24 16:05:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:40:23Z.


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

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136419858 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1015#issuecomment-7136419858). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T15:40:23Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at cb7115a: `cargo test -p victory-shader` passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
catminou4 commented 2026-11-24 17:02:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T16:29:00Z.

Review: APPROVED


Scalar loads through a heap descriptor of unknown kind are typed as SRV when only vector buffer loads read it (buffer_loads_only scans descriptor uses; any store disqualifies -> unchanged CBV path). Conservative and well-tested with the three-way Nothing/Load/Store case. Same lower.rs hunk as #1055 — merge order will need a rebase for the second one. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p <crate> --locked. Shader execution tests (valu_tests/host) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. victory-shader: 97 passed, 0 failed.

<!-- greyfinch-sync:Marvisak/VIctory:review:6043263126 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1015#pullrequestreview-6043263126). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T16:29:00Z. **Review:** APPROVED --- Scalar loads through a heap descriptor of unknown kind are typed as SRV when only vector buffer loads read it (buffer_loads_only scans descriptor uses; any store disqualifies -> unchanged CBV path). Conservative and well-tested with the three-way Nothing/Load/Store case. Same lower.rs hunk as #1055 — merge order will need a rebase for the second one. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p <crate> --locked`. Shader execution tests (valu_tests/host) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. victory-shader: 97 passed, 0 failed.
upstream-sync changed title from [PR #1015] Shaders: scalar loads through a heap buffer that vector loads read use a buffer view to [PR #1015] Shaders: scalar loads through a heap buffer that vector accesses use read a buffer view 2026-11-24 18:03:44 +00:00
justrealyme commented 2026-11-24 18:05:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by justrealyme on 2026-11-24T17:10:40Z.


Thanks for checking it. You're right about the overlap with #1055: it fixes the neighbouring case (a listed UAV) on the same lines of smem, so whichever lands second needs a small rebase. I've linked it in the description.

Your summary also points at the gap I'd left: a heap descriptor that a store also uses stayed on the CBV path, which is a CBV handle on a UAV slot, the case #1055 shows removing the device on WARP. b8cfe8c reads that case as a raw UAV (11 | 0x1000, the same props #1055 uses), and the test's store case now expects 0 CBV handles. A descriptor that only scalar loads read is unchanged. In this title's shaders.rpf no program has the store case (all 38,829 changed loads are read-only), and emit/validation and failure counts are still identical to main. Re-checked: clippy (both configurations), cargo test --workspace --locked 343 passed, policy ok, and the test fails on main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138802051 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1015#issuecomment-7138802051). Originally posted by [justrealyme](https://github.com/justrealyme) on 2026-11-24T17:10:40Z. --- Thanks for checking it. You're right about the overlap with #1055: it fixes the neighbouring case (a listed UAV) on the same lines of `smem`, so whichever lands second needs a small rebase. I've linked it in the description. Your summary also points at the gap I'd left: a heap descriptor that a store also uses stayed on the CBV path, which is a CBV handle on a UAV slot, the case #1055 shows removing the device on WARP. `b8cfe8c` reads that case as a raw UAV (`11 | 0x1000`, the same props #1055 uses), and the test's store case now expects 0 CBV handles. A descriptor that only scalar loads read is unchanged. In this title's `shaders.rpf` no program has the store case (all 38,829 changed loads are read-only), and emit/validation and failure counts are still identical to `main`. Re-checked: clippy (both configurations), `cargo test --workspace --locked` 343 passed, policy ok, and the test fails on `main`. AI-assisted (Claude Code).
MamaLeVrai commented 2026-11-24 18:05:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-24T17:23:49Z.


Heads-up: this PR and #1055 both change the raw-view choice for a scalar buffer load of a descriptor in emit/lower.rs and conflict with each other. The resolution (SRV range reads a raw SRV view, UAV range a raw UAV view, descriptor of no listed kind the heap buffer view) is in the bundle #1319, with both PRs' tests kept; clippy and tests pass on it. AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139130956 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1015#issuecomment-7139130956). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-24T17:23:49Z. --- Heads-up: this PR and #1055 both change the raw-view choice for a scalar buffer load of a descriptor in `emit/lower.rs` and conflict with each other. The resolution (SRV range reads a raw SRV view, UAV range a raw UAV view, descriptor of no listed kind the heap buffer view) is in the bundle #1319, with both PRs' tests kept; clippy and tests pass on it. AI-assisted (Claude Code); no game data.
justlovett0 commented 2026-11-24 19:04:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by justlovett0 on 2026-11-24T18:48:35Z.


Verified on our runtime containers: gain 0 on the address/format class. Stack: main ffe310e + #175/#994/#747/#302/#193/#704/#309/#953/#1067/#986/#1260/#1267/#1254/#1276/#189 (wave64 emulation), RTX 3080 10 GB / Win10 21H2 (19044.7846) / driver 621.24 (32.0.16.2124). Re-census of captured runtime containers; world stable ~9 min, 0 device removals.

Tested by re-census of our captured runtime refusals: this PR (and #1055; #995 conflicts) does not clear our largest class, "a descriptor's address or format read as data" (50 shaders). Those shaders read descriptor address/format dwords as data (which have no host value); the scalar-load fixes here target buffer-data loads through heap descriptors, a different pattern. Useful negative result so the offline count isn't read as covering this class.

AI use: Qwen Code; local measurements. No game data posted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141181974 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1015#issuecomment-7141181974). Originally posted by [justlovett0](https://github.com/justlovett0) on 2026-11-24T18:48:35Z. --- **Verified on our runtime containers: gain 0 on the address/format class.** Stack: main `ffe310e` + #175/#994/#747/#302/#193/#704/#309/#953/#1067/#986/#1260/#1267/#1254/#1276/#189 (wave64 emulation), RTX 3080 10 GB / Win10 21H2 (19044.7846) / driver 621.24 (32.0.16.2124). Re-census of captured runtime containers; world stable ~9 min, 0 device removals. Tested by re-census of our captured runtime refusals: this PR (and #1055; #995 conflicts) does **not** clear our largest class, "a descriptor's address or format read as data" (50 shaders). Those shaders read descriptor *address/format* dwords as data (which have no host value); the scalar-load fixes here target buffer-*data* loads through heap descriptors, a different pattern. Useful negative result so the offline count isn't read as covering this class. AI use: Qwen Code; local measurements. No game data posted.
upstream-sync closed this pull request 2026-11-25 01:05:16 +00:00
Marvisak commented 2026-11-25 01:07:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:30:12Z.


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

Scalar loads through a descriptor taken from the resource heap read a raw buffer view in main (emit/lower.rs smem(): heap_constants; module notes 'Constant buffers in the heap').

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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148575875 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1015#issuecomment-7148575875). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:30:12Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Scalar loads through a descriptor taken from the resource heap read a raw buffer view in main (emit/lower.rs smem(): heap_constants; module notes 'Constant buffers in the heap'). 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.

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
Marvisak/VIctory!1015
No description provided.