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
SPFCChris wants to merge 1 commit from upstream-pr/148 into main
SPFCChris commented 2026-11-25 17:07:46 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by SPFCChris on 2026-11-25T17:07:46Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5495722097 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/148). Originally posted by [SPFCChris](https://github.com/SPFCChris) on 2026-11-25T17:07:46Z. --- 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.
KernelSmoker commented 2026-11-25 19:44:21 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by KernelSmoker on 2026-11-25T19:44:21Z.


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).
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7172702051 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/148#issuecomment-7172702051). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-25T19:44:21Z. --- 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).
adrianmjim commented 2026-11-25 19:52:52 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-25T19:52:52Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7172890077 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/148#issuecomment-7172890077). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T19:52:52Z. --- 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.
gut0to commented 2026-11-27 14:52:01 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-27T14:52:01Z.

Code review location: crates/victory-shader/src/emit/lower.rs; line 6733

@@ -6717,6 +6727,21 @@ impl<'a> Lower<'a> {
         }
     }
 
+    /// 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();

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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4720805463 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/148#discussion_r4720805463). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-27T14:52:01Z. **Code review location:** `crates/victory-shader/src/emit/lower.rs`; line 6733 ~~~~diff @@ -6717,6 +6727,21 @@ impl<'a> Lower<'a> { } } + /// 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(); ~~~~ --- 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 commented 2026-11-27 14:52:01 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-27T14:52:01Z.

Review: COMMENTED


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

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6089924656 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/148#pullrequestreview-6089924656). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-27T14:52:01Z. **Review:** COMMENTED --- AI-assisted static review (ChatGPT); I inspected the lowering change and fixture but did not run tests.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/148:upstream-pr/148'
git switch 'upstream-pr/148'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/148'
git switch 'upstream-pr/148'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/148'
git switch 'upstream-pr/148'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/148'
git switch 'main'
git merge --squash 'upstream-pr/148'
git switch 'main'
git merge --ff-only 'upstream-pr/148'
git switch 'main'
git merge 'upstream-pr/148'
git push origin 'main'
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
Belobug/VIctory-Belobug-AMD!148
No description provided.