Shaders: a buffer view picked from the resource heap by index is read as a raw buffer, not a constant buffer (missing world geometry and device removal on a Radeon 8060S) #148

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

@⁠SPFCChris on GitHub · 2026-11-25 17:07 UTC · original
SPFCChris:fix/heap-indexed-scalar-reads → main · +166 −0 · 2 files · 1 commits · open

Closes #48 (whose title is wrong: it was never textures).

Problem

On a Radeon 8060S the world's large geometry (buildings, roads, terrain, vehicle bodies) was not drawn, webs of one-pixel sliver triangles were, and about one run in five ended in a device removal.

In emit/lower.rs, a scalar load through a descriptor takes its view class from used_kind(src). That only finds a used-resource record for descriptors loaded from a table. For a descriptor the program loads from the resource heap by index it returns None, and None fell into the "else a constant buffer view" arm, so the handle was annotated as a CBV and read with cbufferLoadLegacy. The host mirrors what the title keeps in those slots as buffer views (raw SRVs).

Reading an SRV descriptor as a CBV is outside what D3D12 defines. GPU-based validation names it:

GPU-BASED VALIDATION: Dispatch, Descriptor type doesn't match shader register type:
Descriptor Heap Index: [17], Descriptor Type in Heap: D3D12_DESCRIPTOR_RANGE_TYPE_SRV,
Register Type: D3D12_DESCRIPTOR_RANGE_TYPE_CBV, Shader Stage: COMPUTE ... id=939 severity=1

Heap index 17 is the title's 174 MB scene buffer, which the meshlet-culling programs take as user data (u6=0x11). An RX 9070 XT evidently returns the data anyway. The 8060S does not: the culling programs passed almost no meshlets (1,944 of 2,194 indirect mesh draws had a group count of 0 in a dumped frame), and in the new test below the same access suspends the device.

Change

A descriptor loaded from the resource heap by index, with no used-resource record, is read as a raw buffer (rawBufferLoad, class SRV), which is what the host slot holds. 25 lines in lower.rs.

Upstream main and fxceless/victory-fork already do the equivalent in their own ways (upstream: "Constant data through the resource heap itself is a raw buffer"; fxceless picks between the two reads at run time from the slot's stride, which also covers a real constant buffer view at a directly indexed slot). If you would rather port one of those, this PR at least pins down the cause and brings a test.

Test

emit::tests::scalar_loads_through_a_heap_indexed_buffer_view_execute_on_gpu: a compute program loads a descriptor from heap slot 1, reads three dwords through it with s_buffer_load_dword / _dwordx2, and stores them. Run on the hardware adapter and on WARP.

8060S WARP
main (01aadd1) fails: "The GPU device instance has been suspended" not reached (the hardware run fails first)
with this change passes passes

Tested

Radeon 8060S (Ryzen AI Max+ 395), driver 32.0.32029.2010, Windows 11 build 26300, diag build, Series X profile, VICTORY_PRESENT_TARGET=1x1:1, VICTORY_HAIR=1.

  • In the title, on this branch: the opening scenes (apartment interior, street, city skyline) render completely, without slivers, across four runs; no device removal in them. Before, the street scene was a black void with floating props.
  • cargo test -p victory-shader --lib -- --test-threads=1: 267 passed, 0 failed, 6 ignored.
  • cargo clippy -p victory-shader --all-targets --locked: 12 warnings, the same 12 as on main.
  • About 1,600 host pipelines are made again on the first launch after this change.

Not tested

  • Any other GPU. On a card where the old read happened to work this should change nothing visible, but I have not run it on one.
  • GPU-based validation past the loading screen: the title stops there under it on this machine, so I could not list every mismatch of this kind or confirm with it that none remain.
  • A title that keeps a real constant buffer view at a directly indexed heap slot would now be read as a raw buffer; the frame dumps here show only Shader, Unordered and Placed views at such slots.

AI-assisted (Claude Code); no game data.

**@⁠SPFCChris** on GitHub · 2026-11-25 17:07 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/148) `SPFCChris:fix/heap-indexed-scalar-reads` → `main` · +166 −0 · 2 files · 1 commits · open Closes #48 (whose title is wrong: it was never textures). ## Problem On a Radeon 8060S the world's large geometry (buildings, roads, terrain, vehicle bodies) was not drawn, webs of one-pixel sliver triangles were, and about one run in five ended in a device removal. In `emit/lower.rs`, a scalar load through a descriptor takes its view class from `used_kind(src)`. That only finds a used-resource record for descriptors loaded from a **table**. For a descriptor the program loads from the **resource heap by index** it returns `None`, and `None` fell into the "else a constant buffer view" arm, so the handle was annotated as a CBV and read with `cbufferLoadLegacy`. The host mirrors what the title keeps in those slots as buffer views (raw SRVs). Reading an SRV descriptor as a CBV is outside what D3D12 defines. GPU-based validation names it: ``` GPU-BASED VALIDATION: Dispatch, Descriptor type doesn't match shader register type: Descriptor Heap Index: [17], Descriptor Type in Heap: D3D12_DESCRIPTOR_RANGE_TYPE_SRV, Register Type: D3D12_DESCRIPTOR_RANGE_TYPE_CBV, Shader Stage: COMPUTE ... id=939 severity=1 ``` Heap index 17 is the title's 174 MB scene buffer, which the meshlet-culling programs take as user data (`u6=0x11`). An RX 9070 XT evidently returns the data anyway. The 8060S does not: the culling programs passed almost no meshlets (1,944 of 2,194 indirect mesh draws had a group count of 0 in a dumped frame), and in the new test below the same access suspends the device. ## Change A descriptor loaded from the resource heap by index, with no used-resource record, is read as a raw buffer (`rawBufferLoad`, class SRV), which is what the host slot holds. 25 lines in `lower.rs`. Upstream `main` and fxceless/victory-fork already do the equivalent in their own ways (upstream: "Constant data through the resource heap itself is a raw buffer"; fxceless picks between the two reads at run time from the slot's stride, which also covers a real constant buffer view at a directly indexed slot). If you would rather port one of those, this PR at least pins down the cause and brings a test. ## Test `emit::tests::scalar_loads_through_a_heap_indexed_buffer_view_execute_on_gpu`: a compute program loads a descriptor from heap slot 1, reads three dwords through it with `s_buffer_load_dword` / `_dwordx2`, and stores them. Run on the hardware adapter and on WARP. | | 8060S | WARP | |---|---|---| | `main` (`01aadd1`) | fails: "The GPU device instance has been suspended" | not reached (the hardware run fails first) | | with this change | passes | passes | ## Tested Radeon 8060S (Ryzen AI Max+ 395), driver 32.0.32029.2010, Windows 11 build 26300, diag build, Series X profile, `VICTORY_PRESENT_TARGET=1x1:1`, `VICTORY_HAIR=1`. - In the title, on this branch: the opening scenes (apartment interior, street, city skyline) render completely, without slivers, across four runs; no device removal in them. Before, the street scene was a black void with floating props. - `cargo test -p victory-shader --lib -- --test-threads=1`: 267 passed, 0 failed, 6 ignored. - `cargo clippy -p victory-shader --all-targets --locked`: 12 warnings, the same 12 as on `main`. - About 1,600 host pipelines are made again on the first launch after this change. ## Not tested - Any other GPU. On a card where the old read happened to work this should change nothing visible, but I have not run it on one. - GPU-based validation past the loading screen: the title stops there under it on this machine, so I could not list every mismatch of this kind or confirm with it that none remain. - A title that keeps a real constant buffer view at a directly indexed heap slot would now be read as a raw buffer; the frame dumps here show only `Shader`, `Unordered` and `Placed` views at such slots. AI-assisted (Claude Code); no game data.
A descriptor loaded from the resource heap by index has no used-resource
record, so a scalar load through it was emitted as a constant buffer read.
The host keeps buffer views (SRVs) in those slots: GPU-based validation
reports that the descriptor type does not match the shader register type
for heap index 17, the scene buffer the meshlet-culling programs read. Read
as a raw buffer now, with a test that runs such a program on the hardware
adapter and on WARP.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:41 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-25 19:44 UTC · original

Independent A/B verification on NVIDIA GeForce RTX 3090 (Bazzite Linux 45 x86_64, driver 620.73.04, GE-Proton 10-34 / Wine 10.0 / vkd3d-proton 3.0.0 bd3f5e3d245c3ad, Rust 1.98.1) on PR head 7670245:

This fix is not Radeon 8060S-only — it also fixes silent zero-reads on NVIDIA RTX 3090 under vkd3d-proton 3.0.0:

Build (emit::tests::scalar_loads_through_a_heap_indexed_buffer_view_execute_on_gpu) NVIDIA RTX 3090 (vkd3d-proton 3.0.0)
Base 01aadd1 (lower.rs without PR #148) FAILED — read [0, 0, 0] instead of [0xC0DE0002, 0xC0DE0004, 0xC0DE0005] ([3235774466, 3235774468, 3235774469])
PR #148 (7670245) PASSED (hardware executed directly on RTX 3090, no skipped line; note EnumWarpAdapter in DXVK/vkd3d-proton falls back to the hardware RTX 3090 rather than Windows WARP)

Additional checks on 7670245:

  • Linux cargo test --locked -p victory-shader: 186 passed, 0 failed, 6 ignored (lib) + 3 passed, 0 failed, 1 ignored (tests/resource_tracking.rs).
  • Windows GNU cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-gnu: 0 new warnings (10 pre-existing warnings).
  • Minor Linux CI note (relevant once #165 lands): let mut dxil = l.dxil; at crates/victory-shader/src/emit/mod.rs:1488 emits unused_mut / unused_variables warnings on non-Windows targets (same pattern as the neighboring #[cfg(windows)] GPU tests).
**@⁠KernelSmoker** on GitHub · 2026-11-25 19:44 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/148#issuecomment-7172702051) Independent A/B verification on **NVIDIA GeForce RTX 3090** (Bazzite Linux 45 x86_64, driver 620.73.04, GE-Proton 10-34 / Wine 10.0 / vkd3d-proton 3.0.0 `bd3f5e3d245c3ad`, Rust 1.98.1) on PR head `7670245`: This fix is **not Radeon 8060S-only** — it also fixes silent zero-reads on NVIDIA RTX 3090 under vkd3d-proton 3.0.0: | Build (`emit::tests::scalar_loads_through_a_heap_indexed_buffer_view_execute_on_gpu`) | NVIDIA RTX 3090 (vkd3d-proton 3.0.0) | |---|---| | Base `01aadd1` (`lower.rs` without PR #148) | **FAILED** — read `[0, 0, 0]` instead of `[0xC0DE0002, 0xC0DE0004, 0xC0DE0005]` (`[3235774466, 3235774468, 3235774469]`) | | PR #148 (`7670245`) | **PASSED** (`hardware` executed directly on RTX 3090, no `skipped` line; note `EnumWarpAdapter` in DXVK/vkd3d-proton falls back to the hardware RTX 3090 rather than Windows WARP) | Additional checks on `7670245`: - Linux `cargo test --locked -p victory-shader`: **186 passed, 0 failed, 6 ignored** (lib) + **3 passed, 0 failed, 1 ignored** (`tests/resource_tracking.rs`). - Windows GNU `cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-gnu`: **0 new warnings** (10 pre-existing warnings). - Minor Linux CI note (relevant once #165 lands): `let mut dxil = l.dxil;` at `crates/victory-shader/src/emit/mod.rs:1488` emits `unused_mut` / `unused_variables` warnings on non-Windows targets (same pattern as the neighboring `#[cfg(windows)]` GPU tests).
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 19:52 UTC · original

Corpus data from the game's shaders.rpf on an RX 7900 XT (Windows 11 build 26300, dxil.dll 10.0.26100.0), head 7670245 on 01aadd1, victory translate --validate --list --host-lanes 32-64, comparing a hash of each program's DXIL with 01aadd1:

  • 2,054 programs change: 1,181 compute, 867 vertex and 6 pixel. All of them validate, and the counts are unchanged (VS/PS 14,247/14,247, CS 2,682/2,682, MS 8,694 of 8,765). Every other program is byte for byte the same.
  • cargo test -p victory-shader --lib -- --test-threads=1: 267 passed, 0 failed, 6 ignored, including the new GPU test. It ran without a device removal on this card.

So the change reaches vertex programs too, not only the culling compute shaders, which is worth knowing for the shader cache. Pipelines were not created and the game was not run here.

**@⁠adrianmjim** on GitHub · 2026-11-25 19:52 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/148#issuecomment-7172890077) Corpus data from the game's `shaders.rpf` on an RX 7900 XT (Windows 11 build 26300, dxil.dll 10.0.26100.0), head `7670245` on `01aadd1`, `victory translate --validate --list --host-lanes 32-64`, comparing a hash of each program's DXIL with `01aadd1`: - 2,054 programs change: 1,181 compute, 867 vertex and 6 pixel. All of them validate, and the counts are unchanged (VS/PS 14,247/14,247, CS 2,682/2,682, MS 8,694 of 8,765). Every other program is byte for byte the same. - `cargo test -p victory-shader --lib -- --test-threads=1`: 267 passed, 0 failed, 6 ignored, including the new GPU test. It ran without a device removal on this card. So the change reaches vertex programs too, not only the culling compute shaders, which is worth knowing for the shader cache. Pipelines were not created and the game was not run here.
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:52 UTC · original · reviewed

AI-assisted static review (ChatGPT); I inspected the lowering change and fixture but did not run tests.

**@⁠gut0to** on GitHub · 2026-11-27 14:52 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/148#pullrequestreview-6089924656) · **reviewed** AI-assisted static review (ChatGPT); I inspected the lowering change and fixture but did not run tests.
@ -6720,0 +6730,4 @@
/// Whether every load `src` comes from reads the resource heap by index
/// (not a table, whose entries have used-resource records).
fn heap_indexed(&self, src: &Source) -> bool {
let leaves = src.leaves();
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:52 UTC · original

Could this get a focused CFG-join fixture as well? The new classification depends on every leaf of src being a resource-heap load, while the added shader fixture exercises only a direct heap-indexed descriptor. A small shader whose join selects between two heap-indexed buffer descriptors would verify that the Phi path still lowers the load as a raw-buffer view.

**@⁠gut0to** on GitHub · 2026-11-27 14:52 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/148#discussion_r4720805463) Could this get a focused CFG-join fixture as well? The new classification depends on every leaf of `src` being a resource-heap load, while the added shader fixture exercises only a direct heap-indexed descriptor. A small shader whose join selects between two heap-indexed buffer descriptors would verify that the `Phi` path still lowers the load as a raw-buffer view.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/148/head:github-bot/gh-148'
git switch 'github-bot/gh-148'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-148'
git switch 'github-bot/gh-148'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-148'
git switch 'github-bot/gh-148'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-148'
git switch 'main'
git merge --squash 'github-bot/gh-148'
git switch 'main'
git merge --ff-only 'github-bot/gh-148'
git switch 'main'
git merge 'github-bot/gh-148'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.