Shaders: reads of uninitialized pixel SGPRs read as zero #1176
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!1176
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1176/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?
@Giiy0 on GitHub · 2026-11-24 16:20 UTC · original
Giiy0:fix/ps-uninitialized-sgprs→main· +158 −7 · 3 files · 2 commits · closed without mergingExtends #432 (
ComputeIo::initialized_sgprs()) to pixel shaders.Changes
SPI_SHADER_PGM_RSRC2_PSfrom pixel stage data (E+0x128) intoStageIo::Ps::rsrc2.ps_initialized_sgprs(rsrc2)counting GFX10.3/RDNA2 pixel hardware-initialized SGPRs:USER_SGPR(bits 1-5 plusUSER_SGPR_MSBat bit 27; bits 28-31 areSHARED_VGPR_CNT),prim_mask(always present),WAVE_CNT_EN(bit 7),LOAD_COLLISION_WAVEID(bit 25),LOAD_INTRAWAVE_COLLISION(bit 26), andSCRATCH_EN(bit 0).StageIo::initialized_sgprs()and wire it intoio::raiseso general SGPRs (0..=105) at or above the initialized count read as zero inemit::lower, while hardware-initialized SGPRs (such asprim_mask, POPS collision wave ID, and the scratch wave offset) remain refused with"a hardware SGPR input".native.rsand an end-to-end emission +dxil.dllvalidation regression test inemit/mod.rs.Validation
cargo xtask policy— 154 files okcargo clippy --workspace --all-targets --locked -- -D warnings— cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings— cleancargo test --workspace --locked— 344 passed, 0 failed, 6 ignored (Windows 11, RTX 3080, Rust 1.98.1)victory translate --validateon local shader archive (26,084 programs, SDK 10.0.26100.0dxil.dll):emit: a hardware SGPR inputdrops from 17 to 14 (the 3 programs reading an uninitialized SGPR advance to a later unsupported reason; the remaining 14 read hardware-initializedprim_maskor POPS collision wave ID and stay refused). Validated counts unchanged (12,155 VS/PS, 1,417 CS, 8,152 MS), 0 regressions. Not tested in gameplay.AI-assisted (Antigravity).
@TG0000 on GitHub · 2026-11-24 17:21 UTC · original
Two facts for
bec4bfa, from reading the diff and Mesa's register database (not run):ps_initialized_sgprsand its test take USER_SGPR_MSB from RSRC2 bit 28. That is GFX9; on GFX10.3 it is bit 27 (28 to 31 are SHARED_VGPR_CNT): Mesasrc/amd/registers/gfx103.json,SPI_SHADER_PGM_RSRC2_PS. With bit 28, a program with shared VGPRs gets 32 user SGPRs too many.src_pops_exiting_wave_id(Mesa 24.2radv_shader_args.c,aco_instruction_selection.cpp). Read as zero it means "no overlap", so the wait is skipped; without rasterizer ordered views the accesses it ordered can then race (overlapping cutout surfaces). Worth a line in the comment, or a refusal, instead of a general "uninitialized reads as zero".AI-assisted (Claude Code).
@shortselow-byte on GitHub · 2026-11-24 17:23 UTC · original
This PR has no CI run yet, so I ran the CI's checks at head
bec4bfa(onmainffe310e): Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2).cargo test --workspace --locked -- --test-threads=1: 344 passed, 0 failed, includingpixel_reads_of_uninitialized_sgprs_read_as_zeroandps_initialized_sgprs_covers_user_system_and_scratch.cargo clippy --workspace --all-targets --locked -- -D warnings, and with--all-features: clean.cargo xtask policy: ok.@Giiy0 on GitHub · 2026-11-24 17:53 UTC · original
Good catch @TG0000 — pushed a fix moving
USER_SGPR_MSBto GFX10.3 bit 27 (and asserting bits 28–31SHARED_VGPR_CNTdon't inflate the SGPR count), plus a doc comment noting why counting the POPS bits keepscollision_waveidrefused rather than zeroed.Thanks @shortselow-byte for running the full CI check on RDNA2!
@Zipettte on GitHub · 2026-11-24 18:00 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
bec4bfa:cargo test -p victory-shaderpasses, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@Marvisak on GitHub · 2026-11-25 00:33 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Uninitialised pixel SGPRs are handled in main (io.rs initialized_sgprs; lower.rs inputs(): the primitive mask and the ordered-section collision id read 0, others as in compute).
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.
Pull request closed