Skip to content

Shaders: scalar loads from a root view's address read its memory - #1056

Open
adamdotpy wants to merge 1 commit into
Marvisak:mainfrom
adamdotpy:shader/root-view-scalar-loads
Open

adamdotpy wants to merge 1 commit into
Marvisak:mainfrom
adamdotpy:shader/root-view-scalar-loads

Conversation

@adamdotpy

Copy link
Copy Markdown

What

An s_load_dword* whose address comes from a root descriptor, and whose result the program never uses as a descriptor, reads that buffer's data. On main it goes to descriptor_data. That function finds no resource use of the load, so the program stops with "a descriptor read only as data". In the ffe310e census in #293 that row has 394 programs, 305 of them compute; I can't say how many of them are this case.

Such a load is now read the way global loads from a root view already are (Lower::flat):

  • a root SRV raw (rawBufferLoad on root_srv_handle);
  • a root CBV, or a root view the used-resource list does not name, as a constant buffer (cbufferLoadLegacy via cbuffer_dword);
  • a root UAV still stops, with its own reason: "a root UAV read with scalar loads".

A load whose result is used as a descriptor (a descriptor stored in a root buffer) goes to descriptor_data as before. loads_descriptor checks every descriptor source, Loaded and Fetched, for the load site.

Related, without overlap: #667 binds addresses passed in two root constants as root views. #709 reads structured buffer accesses through a root view's raw handle. Neither changes s_load from a root descriptor's address.

Test

scalar_loads_read_a_root_srv_and_a_root_cbv (new emit/root_view_tests.rs) runs a synthetic program with a root view in user SGPRs 0-1 and a table holding a raw UAV. It reads dwords 2 and 3 of the view's memory with one s_load_dwordx2 and stores them. The test:

  • checks every hand-written encoding by decoding it;
  • runs once with a root SRV and once with a root CBV;
  • checks the declared root view (root_srvs / root_cbvs);
  • compares the stored values with the buffer's.

The results are exact on an RTX 4060 Ti and on WARP. On main the program stops with "a descriptor read only as data".

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

An s_load_dword* whose address is a root descriptor's, and whose
result the program never uses as a descriptor, reads that buffer's
data. It stopped with "a descriptor read only as data". It is now read
as global loads from a root view already are: a root SRV raw, a root
CBV (or a root view the used-resource list does not name) as a
constant buffer. A root UAV still stops, with its own reason.

Test: dwords 2 and 3 of a root SRV and of a root CBV read with one
s_load_dwordx2 and stored, exact on the hardware GPU and WARP; main
refuses the program.

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

Copy link
Copy Markdown

Independent Linux/Wine validation of 417f4e30d22f8ffc1801d60e1b480bbc29781594, based on ffe310e. The new scalar_loads_read_a_root_srv_and_a_root_cbv regression passes: both root-view kinds produce the exact [0x2002, 0x2003] readback. The declared SRV/CBV root-view checks also pass.

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.

@shortselow-byte

Copy link
Copy Markdown

This PR has no CI run yet, so I ran the CI's checks at head 417f4e3 (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_loads_read_a_root_srv_and_a_root_cbv (AMD device and WARP).
  • cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: clean.
  • cargo xtask policy: ok.

@jtrudeau1530

jtrudeau1530 commented Nov 24, 2026 •

Copy link
Copy Markdown

Independent red/green check on RX 7900 XT / RADV 26.2.3, Wine 11.18 and vkd3d-proton 3.2.0 (cae8353): exact 417f4e3 source delta applied to ffe310e + the separate host-only copy fallback 61474f6.

emit::root_view_tests::scalar_loads_read_a_root_srv_and_a_root_cbv executed successfully, including both hardware: scalar loads from a root Srv exact and hardware: scalar loads from a root Cbv exact. The same fixture on the copy-only control, with production lowering unchanged, fails before dispatch with a descriptor read only as data at offset36.

Limits: dxil.dll validation was unavailable. The fixture's WARP-labelled Wine route also passed but used another hardware adapter; this is not a Windows WARP result. No title/world-rendering improvement is claimed from this synthetic check.

Update 16:44 UTC: repeated the same root-load test executable with Microsoft DXIL validator release 1.7.2308 available through VICTORY_DXIL. Both SRV and CBV modules validated and the exact hardware readbacks passed. The Wine WARP-labelled path still selects hardware; this does not add native Windows WARP coverage.

@adamdotpy

Copy link
Copy Markdown
Author

This is the red/green I asked for: the same fixture on the copy-only control fails before dispatch with a descriptor read only as data at offset 36, and the PR's lowering produces the exact [0x2002, 0x2003] readback on the RX 7900 XT. Combined with the Wine runs on two other adapters, that closes the question on this one — the fix is what makes the difference, not the environment. Noted on dxil.dll validation being unavailable in that run; the other two environments did validate.

@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 417f4e3: 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 417f4e3, baseline green on main. Together with the RX 7900 XT red/green this branch's scalar root-view loads are now confirmed on two RDNA3-era and one RDNA2-era part. Nothing actionable.

@Parakeet-Wheat

Parakeet-Wheat commented Nov 24, 2026 •

Copy link
Copy Markdown

Ran the offline corpus check on 417f4e3 (contains main ffe310e) against ffe310e, to answer how many of the 394 "a descriptor read only as data" programs are this case.

  • Setup: Windows 11 26300, NVIDIA GeForce RTX 3070 (8 GB, driver 610.88), Ryzen 5 5600X, Rust 1.98.1 (x86_64-pc-windows-msvc), dxil.dll 1.8.2502, title 1.0.2.1.
  • victory translate <exe> shaders.rpf --list --validate, matched program by program (25,891): 0 outcome changes (21,726 validated / 4,003 failed / 162 rejected on both). No failing program's message changed either: "a descriptor read only as data" stays at 394, so none of them is a scalar load from a root view's address in this title, at least on main alone.
  • cargo test -p victory-shader --locked: 121 passed, 0 failed, 1 ignored, including scalar_loads_read_a_root_srv_and_a_root_cbv.
  • Also 0 on top of Shaders: a select or carry-in on an untracked mask tests this lane's bit #1084 (which moves 205 compute programs from "a select on an untracked mask" to this refusal): with both merged, all 600 "a descriptor read only as data" programs still fail the same way; tests 122 passed, 0 failed, 1 ignored.

Offline translation and validation only; no shader contents or extracted data included. AI-assisted (Claude Code); run on my machine.

@adamdotpy

Copy link
Copy Markdown
Author

Thanks for the corpus check — that negative result is useful: it confirms none of the title's 394 "a descriptor read only as data" programs is a scalar load from a root view's address, so #1056 stays a correctness fix for the general case rather than a recovery for a known title program. The 0 outcome changes on 25,891 programs also matches what I measured locally on the head (unit + GPU tests green, no golden changes).

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.

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