Shaders: read root arguments the console spills to memory #302
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!302
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/302/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@dadou000 on GitHub · 2026-11-24 02:10 UTC · original
dadou000:spill-table-user-data→main· +214 −2 · 2 files · 1 commits · closed without mergingWhat
Compute programs whose root signature does not fit the 16 user SGPRs read their arguments through a spill table:
s[0:1]holds a pointer (high dword masked to 40 bits, usually copied tos2/s3first) to a table of user data, and the programs_loads descriptors and constants from it. Table dword k is user SGPR16 + k. The translator only knew addresses that come from the declared root layout, so all of these failed withan address in an SGPR that is no root parameter.For a compute program whose root layout lies entirely at user SGPR 16 and above, loads from that pointer with a constant offset become
s_mov_b32copies of the user SGPRs the dwords stand for. This happens before the SSA is built, so resource tracking and lowering see ordinary root arguments.Only straight-line code from the pointer's set-up is rewritten. Tags are dropped at branch targets and whenever a pointer register is overwritten. Any other load stays a load.
Evidence
Example from the world shaders (a 64-thread group; layout is two constants then two descriptors, user data 16 to 23):
One 64-thread-group dispatch in the title sets nine root parameters (about 35 dwords), and its shader loads at offsets 0x0, 0x20 and 0x4c, which is what a spill table of those arguments would look like.
On the world's compute shaders,
an address in an SGPR that is no root parameterwent from 34 programs to 4 in one run (RTX 4090, Windows 11). Failures that were hidden behind it now show:an address not from a root parameter,a root UAV or typed root view,an address from a phi,a descriptor read only as data.Not verified
cargo test -p victory-shader --libpasses (71 tests).🤖 Generated with Claude Code
@gw1337x on GitHub · 2026-11-24 02:26 UTC · original
In-game test on an RX 7800 XT (Windows 11 26200),
diagbuild. Build:maind2a4bae+ #135 + #242 + #230 + #124 + #130 + this PR (clean merge). One run into the world, measured with the drop summary the same way as in #293.The targeted reason drops a lot:
The two growing rows look like shaders that now get past the spill table and stop at the next unsupported construct. Draws and dispatches lost per frame went from about 1,770 to about 1,340 in total (rates averaged over the run, menus included).
The rates are not strictly comparable: this run was shorter, so the menus weigh less. It ended at 67 s on the known page fault inside freed textures (#135's remaining case); comparable builds reached 113–177 s. That is one run, and it may just be that more draws now reach those textures sooner. No world frame was captured, so I can't say whether the picture changed.
@matheushagedorn on GitHub · 2026-11-24 03:05 UTC · original
Tested on top of
d2a4bae(+ #177, #151, #55, #189), cross-built on Linux and run under Wine.victory translatedoes not apply the rule.apps/victory/src/translate.rsbuilds the IR withir::build(&p.patched_code(), p.wave64, p.vgprs), so the CLI statistics never see the rewrite, only the runtime path throughemit::translate_withdoes. Anyone measuring with the tool sees no change. Locally I used the same condition there:Maybe worth exposing one helper for that rule so the two call sites cannot drift.
XboxBvhBuilder.dll's 52 containers (victory translate <game dir>\XboxBvhBuilder.dll), which matter for the world on NVIDIA: every builder program the title uses failed withan address in an SGPR that is no root parameterbefore this PR. The one I disassembled has exactly the pattern described here (copy ofs[0:1]with the high dword masked to0xff,s0reused for a literal right after, thens_load_dwordx4at offset 0 ands_load_dwordx16at0x10; two root descriptors and 16 constants at user data 16, 18 and 20).What blocks them now:
resources: an address not from a root parameteremit: a root UAV or typed root viewemit: a select on an untracked maskresources: an address in an SGPR that is no root parameterresources: an address from a root parameter that is no addressresources: an address from a phiThe second row comes from the
Source::Builtarm inlower.rs, which handles root CBVs and raw root SRVs; the builder's root descriptors are UAVs (in the program I disassembled, both are), so they fall through. I haven't checked each of the 12.For context on why this matters: on Linux (RTX 5060 Ti, vkd3d-proton 3.2.0) the world's
Xid 13MMU fault (#71) goes away when one compute program of the BVH-preparation pass is skipped (48426bae580a080c, see my comment there), and since the builder never runs, my guess is that the title's ray-tracing shaders walk memory that was never built (see #274 on the console node format); I have not confirmed that part. This PR is the first step towards that builder translating.No game data attached.
@r4tedx on GitHub · 2026-11-24 03:08 UTC · original
Review note, with a small repro. The rewrite turns a spill-table load into
s_mov_b32 sK, s(16+k), which reads whatever that register holds at that point in the program, not the entry value. If the program has already written s16 and up (as the destination of an earlier load, say), a later load reads the wrong root argument, with no refusal.With this PR on
main(d2a4bae),ir::build_with(.., spilled = true)ongives
The second load's moves read the values the first load just wrote (
Value(8..11)), so s[8:11] become user data 24..27 instead of 16..19, andp.inputsnever contains s16.The example in the description loads into s8..s15, so it does not hit this, and the 34 to 4 count may well be unaffected. But nothing stops a program from loading into s16+. Could the rewrite read the entry values directly (the program's inputs for user SGPR 16+k) rather than the live registers, or be skipped once any of those registers has been written earlier in the scan?
This is the PR for the top row of #293, so it matters that it cannot bind the wrong argument silently. From a synthetic test only; I have no copy of the title.
@louketa on GitHub · 2026-11-24 03:46 UTC · original
Measured this PR against the title's own world shaders (v1.0.2.1). Summary: it clears the first failure of every program it targets, but none of them translate fully yet. The next stop for most is an address that comes out of the spill table.
How
maind2a4bae+ #346 #333 #307 #329 #309 #135 #160 #205 #352, then this PR on top.an address in an SGPR that is no root parameterwas the largest drop reason: 28 compute programs, about 55% of the draws and dispatches dropped per frame (for example3b90165a77d95cdf,f6e47efa50226beb,5552dac6a2b7a1fd).Merge note
This PR conflicts with #309 in
emit::translate. I kept both:ir::build_with(..., spilled)followed bysgpr_spill::forward(&mut p).Result: 34 programs that fail with
an address in an SGPR that is no root parameterwithout this PRan address not from a root parametera root UAV or typed root view(emit)an address from a root parameter that is no addressan address in an SGPR that is no root parameter(at a later instruction)an address from a phia select on an untracked mask(emit)The smallest case
3b90165a77d95cdfis a 22-instruction compute program. Its layout is two root descriptors and one root-constant block, all at user data 16 or above, sospilledis true. It reads the constants from the spill table, which this PR now resolves. It also loads the address of its root UAV from the table (the 64-bit value at that parameter's offset) and builds a buffer descriptor around it for abuffer_store. That address is still reported asan address in an SGPR that is no root parameterat the store. Treating a 64-bit spill-table load at a root-descriptor parameter's offset as that parameter's address looks like the natural next step. Most of the rows above look like the same case.Side note
victory translate(apps/victory/src/translate.rs) still callsir::build, so static scans do not apply the spill rule and show none of these programs failing the way they do at run time. With the samespilledcondition there, the CLI matches the runtime.No game data attached.
@louketa on GitHub · 2026-11-24 04:00 UTC · original
@dadou000 @r4tedx I opened #489 on top of this PR. It fixes the entry-value issue r4tedx reported: the user SGPRs the table loads stand for are copied into an unused SGPR block on entry, and the loads read that block.
It does show up in the title's shaders.
3b90165a77d95cdf(the largest drop in my world run) hits exactly that case, and with the fix it gets through resource tracking. Numbers over the 34 programs and a regression test that fails on this PR alone are in #489. dadou000, feel free to pull the commit into this branch if you'd rather keep it in one PR.@etcetera-yt on GitHub · 2026-11-24 05:36 UTC · original
translate_fornow builds compute programs whose root arguments all sit past the 16 user SGPRs withir::build_with(..., spilled), butvictory translatestill callsir::build(apps/victory/src/translate.rs,the per-program loop), so the CLI never applies the spill rewrite. Checking this PR from the command line therefore
shows no change for such programs, while the runtime path does use it.
Example: the ray-tracing builder's DLL (
XboxBvhBuilder.dll) holds 52 compute programs whose layout entries allstart at user-data dword 16 with 4 user SGPRs.
victory translate <dll> --listreports all 52 failing with"an address in an SGPR that is no root parameter" with this PR merged, while in a title run only 1 of the 35 used
ones still fails for that reason (the others fail later, on root UAVs and addresses in root constants).
Building the CLI's programs the way
translate_fordoes (samespilledtest,ir::build_with) would make the twoagree. Tested on Windows 10 19045, RTX 5060 Ti, with this PR on
d2a4baeplus other open PRs.AI use: Claude Code, Claude Opus 5.5.
@upipibi on GitHub · 2026-11-24 05:51 UTC · original
Independent check of head
815178donmaind2a4bae, read together with #489, which is stacked on it. I read the comments above first. The entry-value problem (@r4tedx, and the overlap case @marquezinii added on #489) is real and #489 fixes it; my run below is one more confirmation, with a shape that ends in a refusal rather than a wrong value. I found nothing else wrong in this commit; the details of what I checked in the rewrite itself are in my note on #489, since that is the version that should go in.Read against the RDNA2 ISA (30-November-2020)
ADDR = SGPR[base] + inst_offset + { M0 or SGPR[offset] or zero }, the two LSBs ignored. The rewrite takes loads with a constant, non-negative, dword-aligned offset and no SGPR offset; the rest stay loads. Narrower than the hardware, never wrong.s[0:1]holds the table pointer and table dwordkis user SGPR16 + kis the console compiler's convention, not ISA; the title counts above are the evidence for it.Run on hardware. NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1,
dxil.dllfrom the Windows SDK 10.0.26100 validating;cargo test -p victory-shader -- --test-threads=1:this PR on
main: 71 passed, 0 failed (main: 69).A local end-to-end probe (not pushed): a compute program whose whole layout is in the table (8 root constants at user data 16..23 holding 100..107, a UAV table at 24), which stores the constants it sees, on the GPU and on WARP:
s_load_dwordx8 s[40:47]s_load_dwordx8 s[16:23]first, then the same dwords intos[40:47]s_mov_b32of the first load iss16+k <- s16+k, so nothing is lost)s_load_dwordx16 s[12:27], then the table descriptor from dword 8 and the constantsan address in an SGPR that is no root parameterat the descriptor load, because s24 then holds what stood for table dword 12The third row is the shape described for
3b90165a77d95cdfabove: a wide load over s16 and up, then a load of an address from the table. Here it ends in the old refusal; with other registers it binds the wrong argument, as shown above.IR probes with
spilled = true: a load at a branch target (forward, and a loop header), a pointer copy overwritten bys_movk_i32, a pointer copied withs_mov_b64, and a load whose destination covers the pointer copy all leave the affected load a load. Correct, and conservative.Not raised above, small
s_mov_b32run shares the load's offset. Inbuild_withthat makes each of them "end" its block when that offset is a leader, setting a self-jump exit that the block's real last instruction then overwrites. It comes out right, but only through that overwrite.apps/victory/src/translate.rsstill callsir::build(already noted above); one helper for thespilledcondition would keep the CLI andemit::translatefrom drifting.Verdict from here: correct only together with #489's commit; I would merge them as one.
Not checked: the title (no game files here), AMD hardware, the 16-or-more user SGPR case discussed on #489.
AI-assisted (Claude Code).
@cybx on GitHub · 2026-11-24 11:22 UTC · original
The offline census (
victory translate) still builds every program withir::build, so it keeps counting spill-table compute programs under "an address in an SGPR that is no root parameter" even thoughtranslate_forrewrites their table loads. On a fork branch I moved the spill condition into one place,emit::build_ir(&NativeProgram), which bothtranslate_forandapps/victory/src/translate.rsnow call:github.com/cybx/VIctory@255e7cb3f2(8 lines, applies on top of this PR + #489; that branch also carries #645). Feel free to fold it in here so the census numbers match the runtime.@justlovett0 on GitHub · 2026-11-24 17:32 UTC · original
Runtime data point (Win10/RTX 3080, driver 621.24): on the actual world containers, this PR's spill-table rewrite does not clear the "an address in an SGPR that is no root parameter" class. We dumped the runtime failing containers and censused them: the XboxBvhBuilder computes (e.g.
3b90165a77d95cdf,f6e47efa50226beb) still fail with this reason after the PR is applied — thespilleddetection (layout entirely at user SGPR ≥ 16) doesn't fire for them, so their root arguments aren't rewritten.This matches the #1247 offline benchmark (#302/#489 gain 0 on the 195-program class). The runtime containers are "Wrapped" (root layout patched at runtime) and differ from the archive bytes, so the offline census understates the class; the runtime dump+census is the way to see it.
These few shaders are high-impact: XboxBvhBuilder builds the ray-tracing BVH, so without them the lighting has no BVH (a major part of the black final image). The detection needs to handle their actual spill pattern — happy to share the dumped containers (
compute-3b90165a77d95cdf.binetc.) for analysis.AI use: Qwen Code (underlying model name not disclosed by the tool); counts from a
victory translatecensus of captured runtime containers.@YaBulochka on GitHub · 2026-11-24 20:19 UTC · original
Retail-run confirmation on Linux/RADV: this is the change that turned a black screen into a visible, coloured 3D scene here.
1.0.2.1, Series X dumpffe310e+ #994 + #491 + #1548 + #1583 + #1319 + #1402 + this PRBefore, the run logged 27
GFX10 code at 0x30: an address in an SGPR that is no root parameter is not supportedlines (and more at 0x40/0x2c), and those programs' draws were dropped.After this PR: 4 such lines left, the scene reaches 3,770-3,881 draws/frame and, with
VICTORY_DEBUG_PS=1, a coloured 3D frame renders at 1.5 fps (menus at 2 fps). Without the debug pixel shader the same tree gets to the prologue and then the GPU is removed (0x887A0005) at 0.2 fps, which I read as the normal pixel path being far heavier, not as a fault of this PR.Merge note, in case someone stacks it the same way: on top of #1402 this PR conflicts in
crates/victory-shader/src/emit/mod.rs. I resolved it asir::build_with(..., spilled)from this PR, thenstructure::structure(&p), thenresource::track(&p, &native.layout, native.stage, st.as_ref().ok())(the four-argumenttrack), and it builds and runs.Remaining in the log: 4 x
a descriptor read only as data, anda structured buffer of unknown stride- the compute side, unrelated to this PR.@KevinPratap on GitHub · 2026-11-24 22:14 UTC · original
A note for when this lands:
victory translate(apps/victory/src/translate.rs) builds programs withir::build, without the spill rewrite thattranslate_forapplies throughbuild_with. So the offline report still counts these programs asan address in an SGPR that is no root parameter, although they translate in the title.Measured on a full shader pack,
--host-lanes 32-32, with the same decision shared (aNativeProgram::spills_roots()used by bothemitandtranslate.rs): that refusal goes from 247 to 197 programs, and compute programs emitted go from 2,425 to 2,445. It's a few lines; happy to send it as a pull request stacked on this one if that helps. AI-assisted.Pull request closed