Shaders: an SGPR no instruction writes stays refused above the initialized ones #1261
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!1261
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1261"
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?
@Proudnoob4 on GitHub · 2026-11-24 16:53 UTC · original
Proudnoob4:fix/sgpr-zero-only-written→main· +62 −14 · 2 files · 1 commits · openFollow-up to #432, from @upipibi's check after the merge.
Problem
#432 lets a compute program's read of an SGPR above the ones the hardware initializes read zero. That rule exists for a read the paths only seem to allow, where the register is written on another path (the
s37/s38case in #432). But it also zeroes a register that no instruction writes. A read like that more likely means an input the translator does not know about, such as a system SGPR in a position we have wrong. Before #432 it was a refusal, and census tables counted it.Fix
In
Lower::inputs, a live-in SGPR aboveinitialized_sgprsnow reads zero only if some instruction in the program writes it. Otherwise it is refused asan SGPR no instruction writes, above the initialized ones. That keeps it apart froma hardware SGPR inputin tables.Measured on the title
I ran
victory translate --listonmainffe310eover the title's shaders:shaders.rpfplus the executable, 26,503 containers and 26,084 programs, 2,582 of them compute. The comparison rows used a local-only switch ininputs(), which is not part of this PR.mainmainI also logged every live-in SGPR read above the initialized ones, whether or not the value is used. 12 distinct programs (by code) have one:
s37,s38s46s83,s84Each of these registers is written elsewhere in its program; none is written nowhere. On this title the narrower rule changes no program and brings back the refusal for the case above.
The 4 programs in the last row are the
meshlet_culling_CS_BatchCullMeshlets*variants from #432's description. Onmainthey now get as far asimage_gather4_l.Tests
an_sgpr_written_on_another_path_reads_zero:s20is written only on the path a branch skips. The program translates, and it is validated whendxil.dllis present.an_sgpr_no_instruction_writes_is_refused. Withmain'slower.rsthis test fails because the program translates. Forcing the zero arm to refuse makes the first test fail, so that test does reach the rule.try_build_valu_csisbuild_valu_cswithout the validation, and it returns the refusal instead of panicking.cargo test -p victory-shader: 107 passed. The same 15 GPU tests fail on unchangedmainon this machine (Windows 10 without an SM 6.6 test device:neither hardware nor WARP SM 6.6 device available; see #84).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: ok. rustfmt: clean for the changed lines.Interplay with #1176
#1176 (open) gives pixel programs an
initialized_sgprstoo, so with both merged this narrowing also applies to pixel shaders. The two touch different lines (#1176:io.rs/native.rs; this PR:lower.rs/valu_tests.rs). I have not measured the pixel side yet. I'll run the corpus onmain+ #1176 with and without this change and post the counts here.Counts and hashes only; no game data attached. AI-assisted (Claude Code); I ran the measurements and tests on my machine.
@pablogonz12 on GitHub · 2026-11-24 17:16 UTC · original
Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main
ffe310eplus #1017 (main's host build fails without it:E0425 host_resource), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped).No program gained or lost, and the failure table is identical to the base, reason for reason — nothing in this capture reaches the class you lower. A no-regression result only.
Not tested: in-game.
@adamdotpy on GitHub · 2026-11-24 17:18 UTC · original
Reviewed at head
d493a13(worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked:1. The distinction is correct and the implementation matches it. In
inputs()(lower.rs:929), an SGPR read with no declared input andnin[initialized_sgprs, 105]used to unconditionally read 0, justified as a path artifact ("a branch past the write"). The PR adds the one check that separates the two cases: if no instruction in the whole program has the register inwrites, a path artifact is impossible — there is nothing to be on a path — so it is an unknown input (a system SGPR in another position) and stays refused (Val::Missing("an SGPR no instruction writes, above the initialized ones")). If any instruction writes it, the old read-zero behavior is kept.written()scansi.writesover all blocks, which is exactly the right over-approximation: a write anywhere means a path could produce it. Borrow-wise it copies theself.xreference before the mutable loop, compiles clean.2. Red/green proven here. With the PR's
valu_tests.rsagainst main'slower.rs,an_sgpr_no_instruction_writes_is_refusedfails (the read of an unwrittens20translates instead of refusing — panic "translated"), whilean_sgpr_written_on_another_path_reads_zeropasses. On the PR head both pass:cargo test -p victory-shader --lib an_sgpr2 passed / 0 failed. So the branch changes exactly the intended case and nothing else.3. Full checks on
d493a13:cargo test -p victory-shader --lib122 passed / 0 failed / 1 ignored (22 s, GPU tests included);cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warningsclean;cargo build --release -p victorybuilds;rustfmt --edition 2024 --checkon both changed files shows only the same 3 pre-existing hunks main has inlower.rs(shifted by the +16 lines),valu_tests.rsfully clean — the PR adds no new fmt diffs.4. One judgment call to be aware of (not a defect): this turns a silent read-of-stale-garbage into a refusal for programs that read an SGPR nothing writes. On real hardware an uninitialized SGPR holds the previous wave's value, not zero, so any shader that genuinely depended on that was already running on garbage; refusing surfaces it as a named
VSF2reason (the same diagnostic currency #1094 introduced) instead of a wrong frame. If a real title shader ever hits this reason, that itself is evidence of a decoding gap — which is the PR's point. Then <= 105bound and theinitialized_sgprsgate are unchanged, so hardware SGPRs above 105 still refuse as before.5. Test hygiene is good:
build_valu_csis now split intotry_build_valu_cs(returns the refusal) + the panicking wrapper that still runsdxil.dllvalidation when available, and the new refusal test asserts on the reason text. No game data, no GPU needed for the new tests.Nothing found that would block this.
@acetonahard-code on GitHub · 2026-11-24 18:13 UTC · original
Setup: Windows 11 (26200), RTX 4070 SUPER, driver 621.14, Rust 1.98.1 (repo toolchain). Base
mainatffe310e, PR headd493a13.maincargo test -p victory-shaderan_sgpr_no_instruction_writes_is_refused,an_sgpr_written_on_another_path_reads_zero.--nocapture, andrun_casesprinted no "no SM 6.6 ... device; skipped" lines, so the GPU tests ran on the hardware adapter and on WARP. The only skips were the 4 "no console / PC compiler" ones.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 154 files ok.cargo fmt --check -p victory-shaderreports the same 7 diffs onmainand on this PR. Inlower.rsthey're only shifted 16 lines by the new code. This PR adds none of them. They're older test code inlower.rs,mod.rs,resource.rsandstructure.rs.Code read:
writtenmatches on exactReg. I checked that this still works for wide writes.ir::effectsexpands every destination into oneRegper dword (Inst::writes: "Every register dword written"), so an SGPR filled bys_mov_b64ors_load_dwordx*counts as written. OnlyDROPPEDinstructions are left out ofinsts, and none of them write an SGPR. Looks correct to me.I didn't test with game data, so I can't confirm the "0 program outcomes changed" count.
@Marvisak on GitHub · 2026-11-25 01:20 UTC · original
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.