Shaders: spill-table loads read the arguments as they were on entry (stacked on #302) #489
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!489
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/489/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?
@louketa on GitHub · 2026-11-24 04:00 UTC · original
spill-clobber→main· +424 −3 · 4 files · 4 commits · closed without mergingStacked on #302 (its commit
815178dis the first one here); only the second commit is new.What
#302 rewrites each spill-table load into
s_mov_b32 sK, s(16+k). That reads what s(16+k) holds at that point, not on entry. A program that has already written SGPRs 16 and up, for example as the destination of an earlier table load, then reads the wrong root argument, with no refusal. @r4tedx reported this on #302 with a synthetic repro.This commit makes the program first copy the user SGPRs its table loads stand for into a block of SGPRs it never reads or writes, and the rewritten loads read that block. If no free block exists below VCC, or a branch can return to the program's entry, nothing is rewritten, so the program fails as it does without #302 instead of binding the wrong argument.
It happens in the title's shaders
I ran the world (opening cutscene) with a local build that saves every container failing at run time. I then translated the 34 programs that fail with
an address in an SGPR that is no root parameteroffline: before #302, with #302, and with #302 plus this commit. Same stack as in my comment on #302, Windows 11, RTX 3080, v1.0.2.1.3b90165a77d95cdf(largest drop in my world run)an address in an SGPR that is no root parametera root UAV or typed root view6f6a359d1166bb27an address from a phian address from a root parameter that is no address3b90165a77d95cdfis the case r4tedx described: a 16-dword table load intos[8:23]overwrites what stands for table dwords 0..7 before a second load reads the root UAV address from table dword 2.Over the 34 programs:
an 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 parameteran address from a phia select on an untracked mask(emit)None of the 34 translate fully yet. The largest remaining group stops at root UAVs in emit, which #294 works on.
Tests
spill_table_loads_read_entry_values: a table load intos[12:19], then a load of table dwords 0..1. It checks that s16 and s17 are read on entry and that the second load's value traces back to s16's entry value. It fails on #302 alone (s16 read on entry) and passes here.spill_table_loads_read_user_sgprsnow also counts the entry copies.cargo test -p victory-shader --lib: 72 passed.cargo clippy -p victory-shader --all-targetsandcargo fmt --check: clean.cargo xtask policy: ok.Not verified
victory translatestill builds without the spill rule (noted on #302). For the offline numbers I applied the samespilledcondition inapps/victory/src/translate.rslocally; that change is not part of this PR.No game data attached.
🤖 Generated with Claude Code
@DaviTostes on GitHub · 2026-11-24 04:02 UTC · original
Verified
279eac1on Arch Linux x86_64 (rustc 1.98.1,cargo test -p victory-shader): 59 passed, 0 failed, 0 ignored.Not covered: the spill-table path on a real GPU and title shaders (no game data).
@marquezinii on GitHub · 2026-11-24 04:51 UTC · original
Ran the spill-table path on a GPU, since that was the part not covered: NVIDIA RTX 5070 (driver 621.24), Windows 11, the SDK's
dxil.dllvalidating. Three synthetic compute programs whose root layout sits wholly at user data 16 and up (8 root constants at 16..23 holding 100..107, a UAV table at 24), built throughir::buildwith spill tables on,resource::track,io,structure,lower, validated, and dispatched:815178dalone279eac1s_load_dwordx8 s[32:39], read s36s_load_dwordx8 s[20:27], s[0:1], 0x0, read s24The second row is a case beside the one r4tedx reported: within a single rewritten load, the
s_mov_b32run reads registers it has just written when the destination starts above the first source and overlaps it. This PR's entry-value block fixes both. All modules validate, andcargo test -p victory-shaderpasses here (includingspill_table_loads_read_entry_values). So on this evidence #302 should only go in together with this commit.One question for the gating in
emit/mod.rs(inherited from #302): it checks that every root parameter is at user SGPR 16 or above, but not the user SGPR count inrsrc2. With 16 or more user SGPRs the thread-group-id SGPRs land at s16 and up too,iowould call them GroupId whileresource::param_ofcalls them root parameters, andlower::inputslets the root parameter win. Gating on at most 16 user SGPRs would turn that into a refusal. I cannot tell from here whether a title does this.Not covered: the title (no game data here).
@ghost on GitHub · 2026-11-24 05:18 UTC · original
In game on AMD RDNA4 (RX 9060 XT, Windows 11), world / opening cutscene, one run:
d2a4bae+ #135 + #365 + #318 + #385 + #346 + #305 + #500 + this PR at279eac1(with #302's815178d),diagbuild plus a local logging patch. The next failures of the 34 programs match your offline#302 + thiscolumn exactly (12 / 11 / 8 / 1 / 0 / 2).Weighted by dropped dispatches of those 34 (about 2,200 per traced frame here, 6 frames):
a root UAV or typed root view(11 programs)an address from a root parameter that is no address(8)an address in an SGPR …(f6e47efa50226bebalone)an address not from a root parameter(12)a select on an untracked mask(2)So the one program still on the SGPR rule is the second-largest dropper after
3b90165a77d95cdf. Next here: the same stack with #294.AI-assisted (Claude Code, Claude Opus 5.5); no game data.
@fuzeofficlal on GitHub · 2026-11-24 05:23 UTC · original
I checked the GroupId question from @marquezinii's review on
279eac1. With 16 enabled user SGPRs,GroupId.xoccupies physicals16even when the spill table separately provides logical root argument 16. A synthetic compute dispatch reads both values into a fixed output buffer. All modules passed the SDK DXIL validator (1.8.2502.11) before dispatch.279eac1[100, 100][0, 100][1, 100]The fix gives spill inputs their own SSA identities and uses the same namespace for a root descriptor's high half. The source commit includes small IR and resource-tracing regressions. The shader suite reports 73 passed. Coverage is the synthetic runtime spill-lowering path. Incremental commit on
279eac1@upipibi on GitHub · 2026-11-24 05:51 UTC · original
Independent check of head
279eac1(this PR's commit on top of #302's815178d), which is based onmaind2a4bae. I read the comments above first; this adds to them and repeats nothing as new. I found no defect in what this commit does. The GroupId question raised by @marquezinii and answered with a commit by @fuzeofficlal is still open on this head and I did not re-test it.Read against the RDNA2 ISA (30-November-2020)
ADDR = SGPR[base] + inst_offset + { M0 or SGPR[offset] or zero }, "the two LSBs are ignored". The rewrite takes only loads with no SGPR offset (soffset= 125) andoffset >= 0 && offset % 4 == 0(ir.rs,spill_loads); anything else stays a load and is refused later as before. That is narrower than the hardware (which would drop the two low bits) but never wrong.kis user SGPR16 + k, and thats[0:1]is the table pointer, is the console compiler's convention, not ISA. Nothing I can cite confirms or contradicts it; the title counts posted on #302 are the evidence.Things I looked for and did not find
Fields::Sopwith adst, SMEM writes throughdata, VALU throughdst/carry; those are the only SGPR writers the decoder has.s_movk_i32 s2, 5between the pointer copy and the load leaves the load a load (probe below).s_mov_b32run shares the load's offset and the entry copies share the entry's. Inbuild_withthat makesendstrue for each of them when that offset is a block leader, which sets the block's exit to a jump to itself; the block's real last instruction then overwrites it, so the CFG comes out right. It works, but it depends on that overwrite: worth a comment there, or distinct offsets.effectsreports, so neither a load's destination nor the pointer copies can land in it. With no free block the original list is returned.Limits, conservative (still refused, as on
main)s_mov_b64 s[2:3], s[0:1], is not followed: the load froms[2:3]stays a load.an address in an SGPR ...program in the table above probably is.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: 72 passed, 0 failed (main: 69).with two local tests added: 74 passed, 0 failed.
build_with(.., spilled = true)), loads left /s_mov_b32count: load at a forward branch target 1 / 9; pointer copy overwritten bys_movk_i321 / 1;s_mov_b64pointer copy 1 / 0; load at a loop header 1 / 9; a load whose destination covers the pointer copy, then a second load through it 1 / 9. All as they should be.s0reused for a literal after the pointer copy), storing the constants it sees:s_load_dwordx8 s[40:47]s_load_dwordx8 s[16:23]first, then the same dwords intos[40:47]s_load_dwordx16 s[12:27](past the layout), then the two halves, second firstThe same three on #302 alone are in my note there.
Not checked: the title (no game files here), AMD hardware, the 16-or-more user SGPR case above.
AI-assisted (Claude Code).
@r4tedx on GitHub · 2026-11-24 06:24 UTC · original
@Brazlucas a late answer to your ping on #302: yes, this fixes the entry-value defect I reported there, and thank you for taking it on.
What I ran, on an RTX 5070 and WARP, with
279eac1merged with #294's0050ce5and the SDK'sdxil.dllvalidating. One hand-assembled compute program of the shape you describe for the world's largest dropper: every root argument at user data 16 and up, a 16-dword table load intos[8:23], the root UAV's address taken from table dwords 2 and 3, a built descriptor and abuffer_store.an address in an SGPR that is no root parameter[120, 135]through the root UAV on both adapters, as expectedSo the two PRs only pay off together for a program like that, which matches jeremygold02's and nullmarsh's title results on #294.
Two open points, neither new, both reproduced or read here:
s16(raised by marquezinii, with a fix commit from fuzeofficlal above). Reproduced on this head: with 16 user SGPRs and the group id enabled, a program that reads both gets[116, 116]where the console gives[116, 0]. I have not tested fuzeofficlal's commit.victory translatecounts differ from the runtime for these programs.For the tester tree (
integration/testerson my fork): #302 was left out for the defect this fixes. I will take #302 with this PR once the GroupId point is settled in it. #294 is a separate decision, because nullmarsh reports a device hang 16 to 23 s into the world on RDNA4 in every run with it.Hand-assembled programs only; the title was not used in these tests. AI-assisted.
@NexForever on GitHub · 2026-11-24 09:03 UTC · original
Hi! I've been investigating the spill-table handling in #302 and #489, including the proposed
Reg::Spillfix by @fuzeofficlal.During testing, I found an additional issue in
ir.rs::spill_loads: the pointer provenance tracker acceptss_and_b32masks that can clear significant bits of the 40-bit spill-table address.For example, masks such as
0x7for1may alter the pointer, but the translator still treats subsequent loads as accesses to the original spill table. This can silently produce incorrect root argument values.Fix: Preserve spill-pointer provenance only when the mask retains all eight significant bits of the address's high dword.
Verification:
-D warnings) and asset-policy checks passed.Fix commit:
github.com/NexForever/VIctory@0c0a3be730Development branch:
https://github.com/NexForever/VIctory/tree/fix/spill-pointer-mask-provenance
The branch includes #302, #489, and @fuzeofficlal's
205b276work, with attribution preserved. My pointer-provenance correction is isolated in commit0c0a3be.Since PR creation is currently restricted to collaborators, would you prefer to cherry-pick this fix or have me prepare a dedicated PR when contributions reopen?
Thanks for your work on VIctory!
Best,
NexForever
@upipibi on GitHub · 2026-11-24 10:19 UTC · original
On @NexForever's mask point: it is right, and my note above missed it. I checked which instructions write the tracked registers, not which mask values keep the tag.
Read at
279eac1,ir.rsspill_loads: ans_and_b32of a tag-2 register keeps tag 2 for any literal mask<= 0xFFFFand any inline constant 1..=64 ((129..=192).contains(k)), on either side. Sos_and_b32 s3, s1, 1or, 0x7fstill counts as the table pointer's high dword, and a followings_load_dwordthrough it is rewritten to the user SGPRs although the address is a different one. Dropping the tag unless the mask keeps every address bit of the high dword is the conservative fix.Which bits those are depends on the address width, which is the console's convention and nothing I can cite; the title's own masks (the values counted on #302) are the evidence for the set to accept. I have not built or run
0c0a3be.AI-assisted (Claude Code).
@qntic on GitHub · 2026-11-24 11:13 UTC · original
tested the spill table path on rx 6600 xt with an actual gpu execution test, all 64 lanes returned the expected sum of 1111. the negative control without spill rewriting fails as expected.
test:
https://github.com/qntic/VIctory/tree/pub/489-spill-table-test
@louketa on GitHub · 2026-11-24 12:42 UTC · original
Updated to
fe7210e: rebased onmain(ffe310e) and three review points taken in. Thanks to everyone who tested this.Rebase. #302's commit conflicted with
maininemit::translate(structurisation now runs before resource tracking). Kept both:build_with(.., spilled), thenstructure, thentrack(.., st.as_ref().ok()).GroupId in s16 (@marquezinii, reproduced by @fuzeofficlal and @r4tedx). The
spilledcondition moved toNativeProgram::spills_root_args, which now also requiresComputeIo::initialized_sgprs() <= 16: when the hardware puts a group id, the group info or the scratch offset in s16 or above, the rule is off and the program fails as onmaininstead of reading a root argument for the group id. This is the conservative gate marquezinii proposed, not @fuzeofficlal's205b276, which gives spill inputs their own identities and would keep such programs translating. If the title's spilled programs turn out to have 16 user SGPRs, that commit is the better fix and I will take it instead.Mask on the pointer's high dword (@NexForever, confirmed by @upipibi).
s_and_b32keeps the table tag only for a literal mask<= 0xFFFFwhose eight low bits are all set; inline constants drop it. Ported from0c0a3be(co-authored), with the tests adapted to this branch, since it does not haveReg::Spill.CLI.
victory translatenow builds with the same rule, so its counts match the runtime.Tests (Windows 11, Rust 1.98.1):
cargo test -p victory-shader --lib: 125 passed, 1 ignored, including the newroot_args_spill_only_with_s16_freeandspill_table_masks_keep_every_address_bit.cargo clippy -p victory-shader -p victory --all-targets -- -D warnings: clean.cargo xtask policy: ok.cargo fmt --checkis clean for the files this PR touches; it reports diffs in other files already onmain.Not verified yet: the s16 gate against the title. I will re-run the 34 programs from my earlier table and post whether any of them now hit the gate.
No game data attached.
@qntic on GitHub · 2026-11-24 13:24 UTC · original
re-tested the spill table execution test on the updated head
fe7210eon my rx 6600 xt.all 64 lanes still return the expected sum of 1111. the new ir tests also pass, along with the entire victory-shader suite (126 passed). clippy is clean in both configurations.
updated test:
github.com/qntic/VIctory@ebeca54@louketa on GitHub · 2026-11-24 13:26 UTC · original
Follow-up on the s16 gate, checked against the title as promised.
victory translate(release build offe7210eonmainffe310e) over the same 276 containers that failed at run time in my earlier world run (v1.0.2.1), once as pushed and once withcs.initialized_sgprs() <= 16removed fromspills_root_args: the two reports are identical, line for line. So none of the title's spilled programs in that run has a group id, group info or scratch offset in s16 or above; the gate costs nothing there, and205b276is not needed for them.The spill-related counts match my offline
#302 + thiscolumn:a root UAV or typed root view11,an address from a root parameter that is no address8,an address in an SGPR that is no root parameter1 (f6e47efa50226beb, still the only one). The CLI now reports these the same way the runtime does, without a local patch.Not covered: programs outside that one world run, and anything past translation (no DXIL is emitted for these yet).
No game data attached.
@louketa on GitHub · 2026-11-24 13:44 UTC · original
On
f6e47efa50226beb, the one program still atan address in an SGPR that is no root parameter(about 18% of the dropped dispatches in @nullmarsh's count above). It is not a spill-rule gap, and #710 moves it on.What it is. The spill rule does rewrite it: 26 entry copies, and the
s_load_dwordx16at entry becomes copies of user SGPRs 32..47. The failingglobal_loadat0x13ecreads throughs[10:11], which hold user data 34..35: dwords 2..3 of the program's 14-dword root-constant block (slot 8), checked against zero first. So it is a 64-bit address passed in root constants. The message is misleading becauseTracker::sumtakes an input as a base only at dword 0 of a parameter; at dword 2 the address becomes the dynamic term, andwhy_no_basethen reports any input as "no root parameter".With #710. I applied #710's three commits on
fe7210e(it conflicts after this rebase; see below) and ranvictory translateover the same 276 containers:fe7210ean address from a root parameter that is no addressa root UAV or typed root view(emit)an address from a phian address in an SGPR that is no root parameterf6e47efa50226beb)162216b9cfd91aafat0x8c)an address not from a root parameterf6e47efa50226bebgets past0x13ecand stops at0x15b0, onan address not from a root parameter: a table in the code (s_getpc_b64plus a literal) indexed by a per-lane value and brought back to SGPRs withv_readfirstlane_b32before ans_load_dwordx8. That is a separate case. Of #710's 8 programs, 5 now stop at root views, as in its own table, and 3 at phis, where #710 counts 2 phis and one other non-root address.Notes for @itsRevela on rebasing #710 onto this head, from doing it locally:
Resources::pairs:mainaddedwaterfallto the struct, and the two edits overlap.track, the pair collection has to come beforemain's earlyreturn Ok(out)whenlanesisNone, orpairsstays empty on that path.main'stracktakes a fourth argument (lanes), andHostShaderinwaterfall_tests.rsneedsaddress_srvs. Two of #710's tests need updating for that.With those,
cargo test -p victory-shader --libgives 134 passed, 1 ignored, andcargo test -p victory-gpu --libgives 53 passed, 1 ignored (Windows 11). Not run in the title on the GPU.No game data attached.
@louketa on GitHub · 2026-11-24 14:24 UTC · original
Status for review:
fe7210eis up to date withmain(0 behind) and merges cleanly.2a30b95), and #302 alone currently conflicts withmain. Merging this PR lands both, and #302 can be closed. Taking #302 alone would bring back the entry-value defect this PR fixes.No game data attached.
@NexForever on GitHub · 2026-11-24 15:44 UTC · original
Hi! Thanks for incorporating my earlier pointer-mask fix into
fe7210eand for preserving the co-author attribution!I've prepared a small follow-up with additional regression coverage for
ir.rs::spill_loads, based directly on the updated #489 head (fe7210e).The follow-up adds three synthetic regression tests covering:
s_and_b32operations, including instruction-decoding checks.The tests also check SSA sources and the fields of loads that must remain unchanged.
I've clarified the comments around the assumed 40-bit spill-pointer convention. The address-width assumption is still unverified; the comments document its limits without claiming to establish the console ABI.
Verification (local):
victory-shader: 128 reported as passed, 0 failed, 1 ignored. Four differential tests returned early because optional compilers were unavailable.-D warnings), formatting and policy checks passed.Incremental commit:
github.com/NexForever/VIctory@1333a88a19The commit is based directly on
fe7210eand contains only the additional tests and documentation.Would you be interested in cherry-picking these regression tests into #489, or would you prefer to keep them as a separate follow-up?
Thanks again!
NexForever
@Yaekai on GitHub · 2026-11-24 16:40 UTC · original
Independent verification on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head
fe7210e:cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests: 107 passed, 0 failed.cargo clippy -p victory-shader -- -D warnings: 0 warnings.1.0.2.1,--console series-s, 19-min world run): no regressions. Ready to merge!Pull request closed