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

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

@⁠justrealyme on GitHub · 2026-11-24 15:04 UTC · original
justrealyme:shader-heap-buffer-scalar-loads → main · +110 −2 · 2 files · 2 commits · closed without merging

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

**@⁠justrealyme** on GitHub · 2026-11-24 15:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/1015) `justrealyme:shader-heap-buffer-scalar-loads` → `main` · +110 −2 · 2 files · 2 commits · closed without merging ## 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)
A descriptor fetched from the resource heap by index has no used-resource
entry, so a scalar buffer load (s_buffer_load_dword*) through it was
lowered through a 64 KiB constant buffer handle. When vector buffer loads
read the same descriptor, the slot holds a buffer SRV (the title made it
one), and reading it through a CBV handle is a descriptor of the wrong
type, which D3D12 leaves undefined. Such loads now read the slot as a raw
buffer, as table SRVs already do. A descriptor also written through
(a UAV) and one only scalar loads read are unchanged.

In the title's shaders.rpf this changes 38,829 scalar loads in about 1,900
of 26,084 programs; emit and validation counts are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The first commit left a heap descriptor of no listed kind that a vector
buffer store or atomic also uses on the constant buffer path, which is a
CBV handle on the UAV the title made. Scalar loads through it now read a
raw UAV (11 | 0x1000), as #1055 does for a table's UAV; read-only use
stays a raw SRV. The test's store case now expects no CBV handle.

In the title's shaders.rpf no program has this case (all 38,829 changed
loads are the read-only one); emit and validation counts are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:17:09 +00:00
github-bot closed this pull request 2026-11-26 04:17:09 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:40 UTC · original

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

**@⁠Zipettte** on GitHub · 2026-11-24 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1015#issuecomment-7136419858) 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)._
Author
Owner

@⁠justrealyme on GitHub · 2026-11-24 17:10 UTC · original

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

**@⁠justrealyme** on GitHub · 2026-11-24 17:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1015#issuecomment-7138802051) 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).
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 17:23 UTC · original

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.

**@⁠MamaLeVrai** on GitHub · 2026-11-24 17:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1015#issuecomment-7139130956) 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.
Author
Owner

@⁠justlovett0 on GitHub · 2026-11-24 18:48 UTC · original

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.

**@⁠justlovett0** on GitHub · 2026-11-24 18:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1015#issuecomment-7141181974) **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.
Author
Owner

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

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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1015#issuecomment-7148575875) 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.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-24 16:29 UTC · original · approved these changes

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.

**@⁠catminou4** on GitHub · 2026-11-24 16:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1015#pullrequestreview-6043263126) · **approved these changes** 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.

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