Skip to content

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

Closed
justrealyme wants to merge 2 commits into
Marvisak:mainfrom
justrealyme:shader-heap-buffer-scalar-loads
Closed

justrealyme wants to merge 2 commits into
Marvisak:mainfrom
justrealyme:shader-heap-buffer-scalar-loads

Conversation

@justrealyme

@justrealyme justrealyme commented Nov 24, 2026 •

Copy link
Copy Markdown

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:

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 + GPU: refuse wave64 mesh and compute programs on hosts without 64-lane waves #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

…e a buffer view

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 <noreply@anthropic.com>
PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 24, 2026
JMAN730 pushed a commit to JMAN730/project-flamingo that referenced this pull request Nov 24, 2026
@Zipettte

Copy link
Copy Markdown

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

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.

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 Marvisak#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 <noreply@anthropic.com>
@justrealyme justrealyme changed the title Shaders: scalar loads through a heap buffer that vector loads read use a buffer view Shaders: scalar loads through a heap buffer that vector accesses use read a buffer view Nov 24, 2026
@justrealyme

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
@Marvisak

Copy link
Copy Markdown
Owner

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 Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants