Shaders: model the compute thread-group info SGPR's wave count #521
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!521
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-521"
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?
@AnoHunted on GitHub · 2026-11-24 04:26 UTC · original
AnoHunted:thread-group-info-sgpr→main· +145 −2 · 2 files · 3 commits · openWhat
A compute program with
COMPUTE_PGM_RSRC2.TG_SIZE_EN(bit 10) gets the thread-group info SGPR right after the group ids. Lowering refused every such program (the thread-group info SGPR). It now supplies the value's low field, the waves in the group (ceil(threads / wave size), bits 5:0), when every reader of the SGPR is ans_and_b32with a mask inside bits 5:0 or ans_bfe_u32field inside bits 5:0.Anything else keeps refusing, with a more precise reason:
the thread-group info SGPR above the wave count. The rest of the register is not derived: per LLVM's AMDGPU docs it is{first_wavefront, 14'b0, ordered_append_term[10:0], threadgroup_size_in_wavefronts[5:0]}, and the first-wave flag and the ordered-append term cannot be produced correctly from the DXIL group model. Nothing else changes.The change is in
emit/lower.rs(group_info).valu_tests.rsgets a small refactor (lower_valu_cstakesrsrc2and the thread counts and returns the lowering error;build_valu_cscalls it unchanged).Why
#293 ranks
a hardware SGPR inputat ~37 lost draws/dispatches (2 shaders). The reason string is the fallback for any system SGPR the translator has no value for; I do not have those shaders and cannot say which one they read. The thread-group info SGPR is the one compute system SGPR that was recognised but refused, so this removes it from the unmodelled set where its use is the wave count. Other candidates (scratch wave offset, which needs scratch support, #265; the first-wave flag / ordered-append bits) are not touched. Honest caveat: this may not be what those 2 shaders read.Sources: LLVM AMDGPUUsage, "Initial Kernel Execution State" (SGPR order: user, work-group id X/Y/Z, work-group info, scratch wavefront offset; work-group info layout above);
AMDHSAKernelDescriptor.h(COMPUTE_PGM_RSRC2bit 10 = workgroup info enable).Tested
Windows 11, NVIDIA GeForce RTX 5080 and WARP, Rust 1.98.1,
VICTORY_DXILset so DXIL validation runs,--test-threads=1.thread_group_info_wave_count_matches_the_group: synthetic gfx10 compute programs (s_and_b32 s7, s6, 63ands_bfe_u32of bits 5:0), 1/32/33/64/96/256 threads, wave32, translated and run on both backends; results 1/1/2/2/3/8 as expected.thread_group_info_bits_above_the_wave_count_are_refused: a raw read and a 0xFFFF mask are refused.cargo test -p victory-shader thread_group_info: branch 2 passed; main has no such tests (0 run). On main the same programs hit the unconditional refusal inInput::GroupInfo(by reading the code; the tests were not run against main).cargo test --workspace -- --test-threads=1: main 264 passed, 0 failed, 4 ignored; branch 266 passed, 0 failed, 4 ignored.Not tested
AMD hardware. wave64 programs (count formula uses the program's wave size, not exercised). The 2 shaders of #293 (not available).
No game files were used.
A compute program with COMPUTE_PGM_RSRC2.TG_SIZE_EN reads the thread-group info SGPR after the group ids; lowering refused it outright. Bits 5:0 hold the waves in the group (LLVM AMDGPUUsage, "Initial Kernel Execution State": {first_wavefront, 14'b0, ordered_append_term[10:0], threadgroup_size_in_wavefronts[5:0]}), which is ceil(threads / wave size). The value is given only when every reader is an s_and_b32 mask or an s_bfe_u32 field confined to bits 5:0; the first-wave flag and the ordered-append term are not derived, so anything else still refuses, now with "the thread-group info SGPR above the wave count".@Raxstreams on GitHub · 2026-11-24 04:41 UTC · original
I ported the group-info change and both synthetic tests into a Windows integration. Both tests passed, including the GPU wave-count cases and the refusal of high-field reads. I haven't found a matching refusal in the captured first-scene shaders on this build, so I can't attribute a title pipeline or rendering change to this PR.
@Dathinel on GitHub · 2026-11-24 05:02 UTC · original
I found a full-width read that
group_infoaccepts on6ff46736. Its use check walks instruction reads. When the entry value feeds a phi, the next instruction reads the phi result, so it passes that check.In the existing
lower_valu_csfixture, setTG_INFO_RSRC2and[64, 1, 1]. With these four words as the body, the helper emits a shader:On the taken path the store can observe bits above 5:0, while the lowering supplies only the wave count. Could the use check follow phi results before accepting the input? There is a positive control worth preserving: insert
s_and_b32 s7, s6, 63at the join and reads7in the move. The current PR accepts that masked case. A local guard that rejected every phi input rejected it as well.Tested with synthetic inputs on Windows using
cargo test --frozen -p victory-shader --features host. The observation concerns what the translator accepts. I have no native RDNA2 comparison for this case. AI assistance was used to prepare and review the reproducer.@upipibi on GitHub · 2026-11-24 10:19 UTC · original
Independent check of head
6ff4673, on its own base and merged ontomainffe310e. I read the comments above first. @Dathinel's phi finding reproduces here on hardware; the rest adds a reference and some edge cases.It no longer merges.
mainnow has #432 in the samematcharm oflower.rsand new tests at the end ofvalu_tests.rs; both files conflict. The resolution is mechanical (keepReg::S(n) => match io_inputs.get(&v)frommainand put theSome(Input::GroupInfo)arm first; keep both sets of tests), and everything below was run on that resolution.The phi case, run. @Dathinel's four words in
lower_valu_cswithTG_INFO_RSRC2and[64, 1, 1]:s0 == s1(info reaches the store)s0 != s1v_mov_b32 v0, s6at the join2on RTX 3070 and WARP0s_and_b32 s7, s6, 63at the join,v0 = s720So the full-width read is accepted and gets the bare wave count; on the console the same store has the first-wave flag and the bits above 5:0 in it. The control is fine. Following phi results in the use check (or refusing an info value that reaches any phi) closes it.
References
AMDGPUUsage, "Initial Kernel Execution State" (release/18.x):Work-Group Info ... {first_wavefront, 14'b0000, ordered_append_term[10:0], threadgroup_size_in_wavefronts[5:0]}, placed after Work-Group Id X/Y/Z and before the scratch wavefront offset. The field layout and the SGPR's position in the PR match it.aco_instruction_selection.cpp, tagmesa-24.0.0, lines 8328-8341) reads this register in one place only, for the local invocation index: "The tg_size bits [6:11] contain the subgroup id", taken withs_bfe_u32 ..., 0x6 | 0x6 << 16on wave32 ands_and_b32 0xfc0, tg_sizeon wave64. It never reads bits 5:0. That is a PC driver, not the console compiler, but it suggests the two #293 programs, if this is the SGPR they read, want the wave index rather than the wave count, and those reads are still refused here (probe below). Nobody has the two shaders' reason at instruction level yet, so this stays a guess.Edge cases (RTX 3070 and WARP agree on every row that runs):
s_and_b32 s7, s6, 63, threads[8, 8, 4][1024, 1, 1]and[32, 32, 1]s_and_b32 s7, s6, 7, 256 threadss_bfe_u32offset 2 width 4, 256 threadss_bfe_u32offset 3 width 4 (reaches bit 6)s_bfe_u32offset 6 width 6 (ACO's subgroup id)s_and_b32 s7, 63, s6(mask as the first operand, the order ACO writes)s_mov_b32 s7, s6thens_and_b32 s7, s7, 63v_mov_b32 v0, s6, no joinThe last four refusals are conservative, not wrong. The two middle ones are cheap to accept if a real program turns out to need them: the mask on either side, and a plain copy followed like the phi.
Not covered: wave64.
group_infodivides byself.wave(), so a wave64 program getsceil(threads / 64), which is what the field means, but both tests and my probes are wave32.Suite. NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1, SDK 10.0.26100
dxil.dllvalidating,cargo test -p victory-shader -- --test-threads=1:mainffe310e+ this PR, 122 passed, 0 failed, 1 ignored (the bitcode benchmark), including the PR's two tests.Not checked: the title (no game files here), AMD hardware.
AI-assisted (Claude Code).
@AnoHunted on GitHub · 2026-11-24 10:40 UTC · original · edited 2026-11-24 10:45 UTC
Thanks @Dathinel for the reproducer, and @upipibi for the independent check and the rebase notes.
Fixed in a new commit on top of the rebased branch:
s_mov_b32copies before accepting it. Every reader it reaches must be ans_and_b32whose mask fits in bits 5:0, or ans_bfe_u32field within bits 5:0. The mask may be in either operand, so ACO'ss_and_b32 s7, 63, s6order is accepted. Everything else is refused, including the full-width read after the join.main. It keeps #432'sReg::S(n)arm, with theGroupInfoarm first.Tested on NVIDIA GeForce RTX 5080, Windows 11, Rust 1.98.1, main and branch side by side:
cargo test --workspace -- --test-threads=1goes from 342 passed onmainto 347 here, 0 failed. Wave64 is still untested.As @upipibi points out, the two #293 programs may read the wave index (bits 11:6 in ACO's use) rather than the wave count. This PR still refuses that, since nobody has the instruction-level reason yet.
@Marvisak on GitHub · 2026-11-25 00:23 UTC · original · edited 2026-11-25 22:28 UTC
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main:mainhas moved since the last triage, and the branch now conflicts incrates/victory-shader/src/emit/valu_tests.rs. It will be reviewed again once it is rebased onto currentmain.Previous verdict for this head: merge candidate.
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.