Skip to content

Shaders, GPU: root UAVs (stacked on #489) - #1077

Closed
DuarttBR wants to merge 5 commits into
Marvisak:mainfrom
DuarttBR:root-uav
Closed

DuarttBR wants to merge 5 commits into
Marvisak:mainfrom
DuarttBR:root-uav

Conversation

@DuarttBR

Copy link
Copy Markdown

Stacked on #489 (which carries #302): its four commits come first here; only the last commit, 873548f, is new.

What

A compute program can build a buffer descriptor around a root descriptor's address and write through it. Emit refused that as a root UAV or typed root view; only root CBVs and read-only root SRVs had a handle.

  • Shader: Shader::root_uav_handle declares u<slot> in the root-view space (ROOT_CBV_SPACE), as a RWByteAddressBuffer (raw buffer, PSV0 kind 7). lower.rs takes (Descriptor, Uav, class 0x100b) there; any other typed root view is still refused, now as a typed root view.
  • HostShader::root_uavs, stored by the shader cache next to the CBV and SRV lists.
  • Host: each root UAV is a one-view table (a D3D12_DESCRIPTOR_RANGE_TYPE_UAV range). In bind, its view is a raw UAV of the title buffer's host copy from the root address, at most 1 MiB (ROOT_UAV_BYTES: a root view has no size), in a dynamic slot per heap and address per list. The range is refreshed before the submission and copied back after it (Shadow::refresh + gpu_writes), as for a table's buffer UAV. Without a host copy, or not on 16 bytes, the view is null: writes are dropped instead of landing elsewhere.

Why

With the spill table read (#302, #489), the 34 compute programs with spilled root arguments that Grand Theft Auto VI's world dispatches get past resource tracking in 13 cases, and 11 of those then stop at this refusal. Among them is the program that dropped the most dispatches per world frame in our runs.

Measured

Offline, over those 34 programs (victory translate --validate --pipelines, RTX 3080, driver 617.42, dxil.dll 1.9.2609):

emitted validated host pipelines
main + #489 0 of 13 0 0
+ this commit 7 of 13 7 6

The seventh is a wave64 program this card refuses (WaveSize(64) on a 32-lane GPU), which the wave64 work (#189, #233) addresses separately. What still stops the other 6 of the 13 is unrelated: a select on an untracked mask (3), LDS writes of bytes or halves, buffer_load_ushort and one typed root view (1 each).

In the game (same stack plus #493, #483, #189, #333 and others on our integration branch, Series S mode, RTX 3080): 5.5 minutes in the world with no device removal and no error, and 3b90165a77d95cdf (about 1,040 dispatches per frame before) no longer in the drop summary. One run, so please take the runtime part as a data point.

Checks

  • cargo clippy --workspace --all-targets --locked -- -D warnings and with --all-features: clean.
  • cargo test --workspace --locked: passes (the shader cache round trip now includes a root UAV).
  • No test drives a root UAV on a GPU yet; if you want one, I can add a synthetic program to the emit tests.

AI use: Claude Code (Claude Fable 5.2 and Claude Opus 5.5) wrote the change, ran the checks and the measurements on my machine, and drafted this description; I reviewed and posted it.

🤖 Generated with Claude Code

dadou000 and others added 5 commits November 24, 2026 12:25
A compute program whose root signature does not fit the 16 user SGPRs
finds its arguments through a spill table: s[0:1] holds a pointer (high
dword masked to 40 bits, usually copied to s2/s3 first) to a table of
the user data, and the program s_loads descriptors and constants from
it. Table dword k is user SGPR 16 + k. The translator only knew
addresses that come from the declared root layout, so every such
program failed with "an address in an SGPR that is no root parameter".

For compute programs whose root layout lies entirely at user SGPR 16 and
above, loads from that pointer with a constant offset become s_mov_b32
copies of the user SGPRs the dwords stand for, before the SSA is built,
so resource tracking and lowering see what they see for ordinary root
arguments. Only straight-line code from the pointer's set-up is
rewritten (tags are dropped at branch targets and on any overwrite of
the pointer registers); other loads stay loads.

On the title's world shaders this took the "SGPR that is no root
parameter" failures from 34 programs to 4 in one run. Other failures
that were hidden behind it now show (address not from a root parameter,
root UAV or typed root view, an address from a phi...). Whether the
translated programs render correctly has not been checked beyond that.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The spill-table rewrite turned each load into `s_mov_b32 sK, s(16+k)`,
which reads what the register holds at that point. A program that has
already written SGPRs 16 and up (the destination of an earlier table
load, say) then reads the wrong root argument, with no refusal.

The program now first copies the user SGPRs its table loads stand for
into a block of SGPRs it never reads or writes, and the loads read that
block. Without such a block below VCC, or when a branch can return to
the program's entry, nothing is rewritten.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With 16 user SGPRs the hardware puts the thread-group ids in s16 and up,
where the spill rule reads root arguments, so a program reading both got
the root argument for the group id (reported on Marvisak#489). Such programs are
now left to fail as they do without the rule.

victory translate now builds with the same rule, so its counts match the
runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
s_and_b32 on the table pointer's high dword kept its provenance for any
literal mask up to 0xFFFF and any inline constant, so a mask such as 0x7f
or 1, which can point to another table, still had its loads rewritten to
the root arguments. Only a mask keeping the high dword's eight low bits
(40-bit addresses) keeps it now.

Co-authored-by: NexForever <37888211+NexForever@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a root view)

A descriptor built around a root descriptor's address with unordered access was refused in emit ("a root UAV or typed root view"). With the spill table read (Marvisak#302, Marvisak#489), 11 of the 34 compute programs with spilled root arguments that Grand Theft Auto VI's world dispatches stopped there, among them the one dropping the most dispatches per frame in our runs.

The translated shader now declares u<slot> in the root-view space (RWByteAddressBuffer, PSV0 kind 7). The host binds it as a one-view table: a raw view with unordered access of the title buffer's host copy from the root address, at most 1 MiB, refreshed before the submission and copied back after it like a table's buffer view. Without a host copy, or off 16 bytes, the view is null. The shader cache stores the new list.

Offline over those 34 programs (victory translate --validate --pipelines, RTX 3080, dxil.dll 1.9.2609): 0 emitted before, 7 emitted and validated after, 6 of them with a host pipeline (the seventh is a wave64 program this card refuses).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@NuraadGit

Copy link
Copy Markdown
Contributor

World sizing for this from an RTX 2080, on a stack with #489 but without root UAVs (JMAN730's fork + #493 + #189 + #206 + #667 + #704 + #878 + #489, 12 minutes, loop limit 32):

  • 15 compute programs are refused in the world with a root UAV or typed root view.
  • About 155 dropped dispatches per frame come from two of them: 3b90165a77d95cdf (~90) and c42a31951201f9a0 (~65). The stack drops about 665 per frame for a missing host pipeline in total, so that's close to a quarter. 3b90165a77d95cdf is the single most dropped program.
  • Two more sit next to them with another reason (an address not from a root parameter): 5062bc7a48e842f8 and 5279ae36796c31fc, ~65 per frame each.

These four are missing from victory translate --list of the shader archive here, so offline counts over the archive can't show their gain. A runtime count like yours can.

Overlap: #294 + #709 (wbkepler, itsRevela) also give root UAVs, as root descriptors with write-back. In a full offline census of my stack with #489 + #294/#709, a root UAV or typed root view is at 0 (I haven't run that build in the world). The designs differ: a one-view table per root UAV here, root descriptors there. It'd help to settle on one before both grow. If you post your 13 programs' hashes, I can say what each of them does offline with #294/#709, where they are in the archive.

AI-assisted (Claude Code): the runs and log analysis were automated. The hardware, title copy and runs are the user's.

@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 873548f: cargo test -p victory -p victory-gpu -p victory-shader passes, 176 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

@DuarttBR

Copy link
Copy Markdown
Author

Thanks, that matches what we see: 3b90165a77d95cdf was our single largest drop too, and it is one of the seven this PR gets through.

The 11 programs that stop at a root UAV or typed root view on main + #489:

Program With this PR (Series S runtime stack)
3b90165a77d95cdf emits, validates, host pipeline
4ddd6f9702fab2a7 emits, validates, host pipeline
c42a31951201f9a0 emits, validates, host pipeline
5c09eb42b7a3c362 emits, validates, host pipeline
bb55c842c391589f emits, validates, host pipeline
f94e5d8bf4e1cf05 emits, validates, host pipeline
14394a322f6dd5c2 emits and validates; pipeline refused on plain main (WaveSize(64) on a 32-lane card), made with #189
caa78b8ca62bc3d6 next: LDS without a uniform fence in split wave64 (with #189)
28918b7150a7aad5 next: same as above
e63d22c4def9ba6a next: a select on an untracked mask
5552dac6a2b7a1fd next: a typed root view (a formatted root UAV, not raw)

On the overlap with #294/#709: agreed it is worth settling on one. Our reason for a one-view table is the same as #493's for root SRVs: a root descriptor has no size, so a write past the title buffer's host copy lands in whatever follows it. A table view ends at the copy (capped at 1 MiB here), and out-of-range writes are dropped. If #294/#709 bound the range another way, I'm happy to rebase onto them, or to close this in their favour. I can run #294/#709 on the same stack in the world and report the drop counts.

AI use: Claude Code (Claude Opus 5.5) gathered the per-program results from our runs and drafted this reply; I reviewed and posted it.

Bezouro added a commit to Bezouro/VIctory that referenced this pull request Nov 24, 2026
Adapt the writable root view from Marvisak#1077 (873548f) and the bounded validation root signature from Marvisak#1175 (bfe5d2d) to the Linux backend. Resolve the backing resource and byte offset at bind time, retain and synchronise the view range, and keep dynamic slots alive through submission. Keep the existing stride table, diagnostics and cache entries usable.

Exercise a translated spilled root UAV through a guest heap and overlapping root bindings on the native GPU. Check final guest memory and an out-of-bounds control word.
@MamaLeVrai

Copy link
Copy Markdown

For reference: on top of the shader stack (#1319 to #1511) this merges without a conflict but does not compile, in two places. draw.rs pushes a root UAV's dynamic slot on self.dynamic, which #1056 replaced with the list's keep_dynamic; the stack's tests that build a HostShader lack the new root_uavs field. Both are fixed, with the rest of Impre-visible's list, in #1632. AI-assisted (Claude Code); no game data.

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…sak#709 on Marvisak#1077's root UAVs

Marvisak#709's test used Marvisak#294's Root::Uav; this host binds a zeroed root UAV
(SetComputeRootUnorderedAccessView) and reads it back after the views' UAVs.
Also the fork's track() signature, and stride-0 structured accesses keep the
fork's runtime stride-table view (Marvisak#193/Marvisak#704) after Marvisak#709's structured().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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.

Root UAVs stacked on #489/#302: main has HostShader::root_uavs, u<slot> space1 and title-memory root views (27c3dc9, 0f63757).

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.

7 participants