Repository navigation
Shaders: reads of uninitialized SGPRs read as zero, as VGPRs do - #432
Conversation
Compute programs read SGPRs the hardware does not initialize when two branches make the paths look like they allow a read before a write, even though the branch that skips the write does not reach the read. That stops translation with 'a hardware SGPR input is not supported' and drops the program's dispatches. ComputeIo::initialized_sgprs() counts the user SGPRs, the enabled system ones and the scratch wave offset. A read of a general SGPR (0..=105) at or above that count holds whatever the previous wave left, so no program can depend on its value: read it as zero, as unset VGPRs already are. Reserved registers (VCC, trap temporaries, M0, EXEC) keep their current handling.
|
Verified Not covered: GPU execution of the new zero-read paths on Windows/Wine and title behaviour (no game data here). |
mercuryVM
left a comment
There was a problem hiding this comment.
Tested f4438b3 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. The 12 embedded programs I have are all vertex and pixel, though, so this local check does not exercise the compute path this PR changes. I have not reproduced the meshlet-culling results in the table.
initialized_sgprsmatchessystem_sgprs: the user SGPRs, then group ids x/y/z (rsrc2 bits 7–9), then the info SGPR (bit 10), then the scratch wave offset whenSCRATCH_EN(bit 0) is set. I checked the three test values against the bit layout.- Only general SGPRs (
n <= 105) at or above that count read as zero. VCC, M0, EXEC and the trap temporaries keep their current handling, and non-compute stages are unchanged (None). - One risk, not blocking: if the hardware ever initializes an SGPR that
system_sgprsdoes not model, a read of it would now quietly become zero instead of failing with "a hardware SGPR input". Atracing::debug!when this zero substitution happens would make that easy to spot.
AI-assisted (Claude Code).
… read as zero, as VGPRs do Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compute programs read SGPRs the hardware does not initialize when two branches make the paths look like they allow a read before a write, even though the branch that skips the write does not reach the read. That stops translation with 'a hardware SGPR input is not supported' and drops the program's dispatches. ComputeIo::initialized_sgprs() counts the user SGPRs, the enabled system ones and the scratch wave offset. A read of a general SGPR (0..=105) at or above that count holds whatever the previous wave left, so no program can depend on its value: read it as zero, as unset VGPRs already are. Reserved registers (VCC, trap temporaries, M0, EXEC) keep their current handling. (cherry picked from commit f4438b3) Ported from Marvisak#432 (@Proudnoob4); the io.rs conflict with linux-bringup's per-vertex rows kept both fields.
… the tests compile cargo test -p victory-shader does not compile on main (cf0bb43): error[E0061]: this function takes 2 arguments but 1 argument was supplied --> crates/victory-shader/src/emit/lower.rs:6954:13 25b0f88 (Marvisak#432) gave the test helper lowers() an rsrc2 argument and updated its callers; 3c86053 (Marvisak#117), merged in the same wave, added the s_bitcmp test with a call of the old form. The helper used rsrc2 0 before, so the call passes 0. One argument, nothing else changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compute programs read SGPRs the hardware does not initialize when two branches make the paths look like they allow a read before a write, even though the branch that skips the write does not reach the read. That stops translation with 'a hardware SGPR input is not supported' and drops the program's dispatches. ComputeIo::initialized_sgprs() counts the user SGPRs, the enabled system ones and the scratch wave offset. A read of a general SGPR (0..=105) at or above that count holds whatever the previous wave left, so no program can depend on its value: read it as zero, as unset VGPRs already are. Reserved registers (VCC, trap temporaries, M0, EXEC) keep their current handling. (cherry picked from commit f4438b3, upstream Marvisak#432 by Proudnoob4) Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
|
A check after the merge, on Run on hardware (RTX 3070, driver 616.56, and WARP; the compute fixture of
So the boundary is where A read with no write anywhere now also reads zero. The case in the description has a write on another path (
I have not seen a title program of the second kind (no game files here); this is from the code and the probe. Not verified: AI-assisted (Claude Code). |
|
@upipibi thanks for checking after the merge. I have the title's files here, so I measured both points on its own programs. 1. Reads of SGPRs no instruction writes. I ran
The 4 are the I also logged every live-in read above the initialized SGPRs, whether or not the value is used. 12 distinct programs have one:
Each of these registers is written elsewhere in its program. No title program reads an SGPR that nothing writes. So your first option costs nothing here and keeps the signal. I have that change ready with two CPU-only tests: branch 2.
On the title, compute user-SGPR counts range from 4 to 14. In VIctory only compute decodes the count from Counts and program names only; no game data attached. AI-assisted (Claude Code); I ran the measurements on my machine. |
Shaders: reads of uninitialized SGPRs read as zero, as VGPRs do
Shaders: reads of uninitialized SGPRs read as zero, as VGPRs do
What
Some compute programs read SGPRs that the hardware never initializes, because two branches make it look as if a read can happen before the write — but the branch that skips the write does not reach the read. VIctory stops at
a hardware SGPR input is not supportedand drops the program's dispatches.ComputeIo::initialized_sgprs()counts the SGPRs the hardware does load: user SGPRs, enabled system ones and the scratch wave offset (rsrc2 bit 0). A read of a general SGPR (codes 0..=105, perir.rs) at or above that count holds whatever the last wave left, so no correct program depends on its value. Read it as zero, as already done for unset VGPRs (lower.rs"Registers no one set read as zero"). VCC, trap temporaries, M0 and EXEC keep their present handling.Evidence
Three real meshlet-culling programs fail on
mainat 0x3e0 with this reason. Instrumentedio.rs/lower.rslocally (temporary prints, not in the diff):They are written at 0xec/0xf4 on the path from
s_cbranch_vccz label_00CC; the fall-through at 0xb0 writes them and branches to 0x100, whilelabel_00CCreaches the 0x3c8 read. With this change all three translate, validate and get pipelines on an RTX 4080 (driver 621.01):main d2a4baeA local build combining this with #136's
image_gather4_lhunks took the seven known meshlet-culling programs from 0/7 → 4/7 → 7/7 emitted, validated and pipelined.Tests
cargo test -p victory-shader -- --skip emit::valu_tests: 63 passed, 0 failed (the 7 skipped ones are the known Windows 10 "no SM 6.6 device" failures in this test binary, discussed in Windows 10: the host device stops at shader model 6.5 (needs the D3D12 Agility SDK) #84).initialized_sgprs_covers_user_system_and_scratchcovers user + group ids, the info SGPR, and the scratch offset.rustfmt --checkon the three changed files andgit diff --checkpass.Caveat
This does not fix the NVIDIA world hang (#71): with all seven programs enabled the device was still removed, and a little earlier than without them. It only restores the dropped dispatches. I posted that correction on #71.
AI-assisted (Claude Code). I ran the tests on Windows 10, RTX 4080; the reasoning and code are mine.