Skip to content

Shaders: scalar buffer loads from a UAV read it raw - #1055

Open
adamdotpy wants to merge 1 commit into
Marvisak:mainfrom
adamdotpy:shader/smem-uav-raw
Open

adamdotpy wants to merge 1 commit into
Marvisak:mainfrom
adamdotpy:shader/smem-uav-raw

Conversation

@adamdotpy

Copy link
Copy Markdown

What

Lower::smem reads a scalar buffer load (s_buffer_load_dword*) through a raw handle when the descriptor's range is an SRV. Any other kind took the constant-buffer path (handle(.., (13, 0x1_0000)), then cbufferLoadLegacy), a table's UAV included. That is a CBV handle at the heap index where the host has a UAV.

A scalar buffer load from a UAV now reads it raw. It uses a handle with UAV properties (11 | 0x1000, 0), which is how a raw SRV is read here and how vector buffer accesses read a UAV, so all of a load site's accesses share one handle. Root UAVs are unchanged; they are still refused with "a root UAV or typed root view".

Why

Reading a UAV through a CBV handle removes the device. On main (ffe310e) with VICTORY_WARP=1, the test below fails with "The GPU device instance has been suspended". I did not run the unfixed program on hardware, because it is undefined behaviour there.

How often the title does this is unknown. A translation census can't show it, since these programs translate. Any program that does would remove the device, so this may be one cause of device-removal reports such as #653.

Related: #1015 fixes the neighbouring case, a heap descriptor with no listed kind that vector loads also read. This PR covers a descriptor whose listed kind is a UAV. The two touch the same lines of smem, so whichever lands second needs a small rebase.

Test

scalar_buffer_loads_read_a_uav_through_its_table (emit/valu_tests.rs) uses build_valu_cs, whose output UAV is a raw UAV in a table. The program:

  1. writes root constant 0 to the UAV's dword 0;
  2. reads it back with s_buffer_load_dword;
  3. stores that value.

The test removed the WARP device before this change. With the change it passes on an RTX 4060 Ti and on WARP.

Checks

  • cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored. The GPU tests ran on an RTX 4060 Ti and WARP, with no "skipped" lines.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and the same with --all-features: clean.
  • cargo xtask policy: ok.

No title data was used.

🤖 Generated with Claude Code

s_buffer_load_dword* through a table's UAV took the constant buffer
path: a CBV handle at the heap index of a UAV. Reading through it
removes the device (WARP: "The GPU device instance has been
suspended"). Such a load now reads the UAV raw, as a raw SRV is read
and as vector buffer accesses read a UAV.

The test writes a value to the VALU tests' raw UAV, reads it back with
a scalar buffer load and stores that; it removed the WARP device before
this change and passes on the hardware GPU and WARP after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ThomasHFWright

Copy link
Copy Markdown

Independent Linux/Wine validation of 21d1b4682735b59a2742b6cf4696716e07e04d99, based on ffe310e. The new scalar_buffer_loads_read_a_uav_through_its_table regression passes: both patterns (0x12345678, 0xDEADBEEF) survive the UAV store/scalar-load/readback path. I did not run the unfixed device-removal case on hardware.

Full workspace unit/integration suite, all features, all 14 generated Windows MSVC test executables:

Tree Passed Failed Ignored
ffe310e baseline 341 5 6
This PR alone, unmodified 342 5 6

The five failures match baseline: empty pipeline library (#347), missing Wine Winsock export (#217), checksum-rejection expectation, nested Cargo fixture build, and Windows xtask attempting to launch host Git. Native Linux shader tests separately pass 96 / 0 / 1, xtask 4 / 0 / 0, and asset policy passes. Windows-target workspace Clippy with all targets/features and -D warnings passes.

Environment: Rust 1.98.1, Wine 11.22, RTX 5090 / NVIDIA 620.73.04, vkd3d-proton 30b0eb9bc12dc9f; native d3dcompiler_47 supplied for GPU fixtures, identical runtime DLLs to baseline. Both requested device paths in the new test completed, but this Wine/DXVK setup is not genuine Windows WARP coverage. Optional dxil.dll validation was unavailable; GPU pipeline creation and dispatch/readback executed.

Offline and offscreen, no game data or gameplay. No native Windows or Wine doctests. Aggregate counts include existing early-return tests without optional console compilers or the DXIL validator; the new regression executed. AI-assisted testing with Codex.

@adamdotpy

adamdotpy commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Thanks — that is the second independent environment (Wine 11.22, RTX 5090, vkd3d-proton) on this branch, and the 342/5/6 line matches the baseline failures one for one, so the fix costs nothing elsewhere.

One thing would close this completely, and it is the half you flagged: the red side. The test asserts the load succeeds; the bug it fixes is the device, so the evidence that matters is that the same program on unfixed ffe310e either removes the device or reads back the wrong dword. If your harness can run the regression against the base commit once and paste the failure, the PR stops needing anyone to take the mechanism on trust. If the unfixed path is hard to reach there (device removal is the expected symptom, not a clean assertion), say so and I will leave it — the mechanism is written out in the commit message either way.

@shortselow-byte

Copy link
Copy Markdown

This PR has no CI run yet, so I ran the CI's checks at head 21d1b46 (on main ffe310e) natively on Windows with an AMD GPU, to complement the Linux/Wine run above: Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2).

  • cargo test --workspace --locked -- --test-threads=1: 343 passed, 0 failed, including scalar_buffer_loads_read_a_uav_through_its_table (AMD device and WARP).
  • cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: clean.
  • cargo xtask policy: ok.

Like you, I did not run the unfixed program on the hardware device.

@adamdotpy

Copy link
Copy Markdown
Author

Thanks — that is the native-Windows/AMD half of the evidence the Wine run could not give, and it matches the other two environments (343 passed / 0 failed with the new regression, clippy and xtask policy clean). Nothing further needed from us on this branch; the only open item anywhere here is whether the unfixed program can be made to fail on a hardware device, and both testers have said the same thing — that it is the device-removal symptom rather than a clean assertion, so I will leave it as it stands rather than ask a third person to chase it.

@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 buffer loads through a UAV descriptor now use a raw buffer view (props 11|0x1000) instead of being refused/mistyped; the comment correctly notes the reverse case (UAV read via CBV handle removes the device). Complements #1015 (heap SRV inference) — note both touch the same ResourceType::Srv hunk in lower.rs, so whichever lands second will need a small rebase. 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: 96 passed, 0 failed (the new valu test is Windows-gated).

@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 21d1b46: 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).

@adamdotpy

Copy link
Copy Markdown
Author

Thanks for the RDNA3 run @Zipettte — 121 passed / 0 failed at 21d1b46 with the workspace baseline green on main noted, that's the fourth independent validation of this branch (Wine + RDNA3 hardware here, RX 7900 XT by jtrudeau1530 earlier). Nothing actionable in the report.

justrealyme added a commit to justrealyme/VIctory that referenced this pull request Nov 24, 2026
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>
@MamaLeVrai

Copy link
Copy Markdown

Heads-up: this PR and #1015 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.

nazmi added a commit to nazmi/VIctory that referenced this pull request Nov 24, 2026
A UAV read through a constant buffer handle removes the device. Adapted
from Marvisak#1055 (head 21d1b46) onto the rewritten scalar
buffer load: that path now has `raw_view` and a root-memory case, so the
UAV arm is added beside them with props (11 | 0x1000, 0), leaving the
read-only and root-memory arms at (11, 0). The PR's regression test is
taken unchanged.

Refs: Marvisak#1055 head 21d1b46
(cherry picked from commit b19c8b4e24918cef557672bd272eb5a7b8f4cff0)

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/valu_tests.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants