Repository navigation
Shaders: a loop leaves with the host wave when a VCC test of a lane compare says so - #196
JaumeMarRib wants to merge 1 commit into
Conversation
…ompare says so The structurisation turns a branch on a wave-wide mask test into a branch on the lane's own bit: compiled code only skips work that lanes outside the mask would not change, or tests a value the same in every lane. A loop's exit on s_cbranch_vccz/vccnz of a compare that differs between lanes is neither. The console leaves with the whole wave as soon as one lane meets the exit; the lane's own bit keeps a lane whose own test never holds looping, up to the iteration limit. The title's clustered-light pixel shaders do that: the outer loop walks light-mask words from the first lane's start and leaves when the word index equals some lane's end (v_cmp_eq_u32 vcc, s79, v56; s_cbranch_vccz). In a wave that mixes clusters, a lane whose end lies before the first lane's start never matches and runs the loop, and the light loop inside it, about 2^20 times. On an RTX 5070, whose waves group pixels differently from the console's, single draws of one mesh group with these shaders took 100-130 ms in the first mission's intro, and lists of them ended in DXGI_ERROR_DEVICE_HUNG. Where one way of such a branch stays in a loop around the block (its header, or plain jumps to it) and the other leaves, the exit now also holds when it holds in some lane of the host wave (waveAnyTrue), as the console's wave-wide test does. A lane still leaves on its own exit, so a wave of helper lanes only, which wave votes leave out, keeps the old rule. Other branches keep the lane rule. A branch in Structured::wide already has the console's wave-wide answer in its condition, so the vote is skipped there. Translated offline for a 32-lane host, the 999 pixel, mesh and compute programs dumped from that run: 21 pixel shaders change, among them the slow ones the per-command timing named; every program that translated before still does. On the RTX 5070, 7-minute runs through the intro no longer hang the device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… with the host wave when a VCC test of a lane compare says so Part of #16
Flyander
left a comment
There was a problem hiding this comment.
The issue #107 timing and the 7-minute RTX 5070 run make the impact clear. One coverage gap before this lands: wave_loop_exit() changes branch conditions based on loop membership and a wave vote, but this PR adds no isolated regression test for that decision.
Could you add a synthetic program with a lane-dependent s_cbranch_vccz loop exit and check the emitted/executed result on a 32-lane GPU? In particular, it would pin that any lane reaching the exit ends the console wave's loop, while a wave with no participating lanes preserves the existing behavior. The game run is valuable integration evidence; this would make the control-flow rule reproducible without the title.
|
This is the fix for the trade-off I reported in #62: with it, a 4060 Ti at Setup: RTX 4060 Ti 8 GB, driver 32.0.16.1656, Ryzen 9 5900X, Windows 11;
So on this card the missing geometry was the loop exit, exactly as #62 suspected, and not a refused draw - the four refusals remain the same four (transpose vec/mat, shadow cascades alpha, shallow water reduce, water volumetrics). Nothing else regressed that I can see: the hair stays correct at 256 in the same frame that gained the ceiling, which is the pairing that was impossible before. No game data; counts only. |
For a compare feeding a nonzero VCC loop exit, use a host wave vote only when the pixel shader and target use the same 32-lane size. Exercise both branch polarities against a DXC reference on Vulkan. Inspired-by: fxceless/victory-fork#196 (365c3b2c)
|
RETRACTED: these results were not measured with this PR, see the correction below. RX 9070 XT (RDNA 4): with this PR the cell's wall and the character textures reach the G-buffer, but the lit picture is blown out and torn; a per-console-wave vote does not change that A data point from AMD, since the PR is verified on NVIDIA so far. Setup: RX 9070 XT, Adrenalin 32.0.32029.2010, Ryzen 7 5800X, 32 GB, Windows 11; fork
One run each, so read the first two rows as a lead and not a proof; I know the cell shell is intermittent on other cards. So on this card the PR does something real before lighting (the wall and the shirt colour exist in the albedo plane only with it), and something wrong in the lit output. My first guess was the vote's scope: if the host runs the console's 32-lane pixel shaders as wave64 (as PastiiJay found for the purple blocks), What I have not done: find which of the 21 changed pixel shaders is responsible, or check whether a lane's early exit leaves a light sum that the following code treats as clustered-light output. If it would help, I can test the PR with only the four slowest programs changed, by hash, to see whether the blow-out follows a subset. Counts and settings only; no game data. AI-assisted (Claude Code): measured on this machine with a diag build. |
|
Correction to my RX 9070 XT comment above: please disregard its results. They were not measured with this PR. My build of this PR failed on our base ( Sorry for the noise. If I get it building (it probably needs the change that adds AI-assisted (Claude Code). |
Integrate the clustered-light loop correction from fxceless/victory-fork#196 (365c3b2).
Problem
The structurisation turns a branch on a wave-wide mask test into a branch on the lane's own bit. That is right where compiled code only skips work, or where the tested value is the same in every lane, but not for a loop exit on
s_cbranch_vccz/vccnzof a compare that differs between lanes: the console leaves with the whole wave as soon as one lane meets the exit, while the per-lane rule keeps a lane whose own test never holds looping up to the iteration limit.The title's clustered-light pixel shaders do exactly that: the outer loop walks light-mask words from the first lane's start and leaves when the word index equals some lane's end (
v_cmp_eq_u32 vcc, s79, v56; s_cbranch_vccz). In a wave that mixes clusters, a lane whose end lies before the first lane's start never matches and runs the loop (and the light loop inside it) about 2^20 times. On an RTX 5070, single draws of one mesh group with these shaders took 100-130 ms in the first mission's intro (VICTORY_GPU_TIMING=1), and lists of them ended inDXGI_ERROR_DEVICE_HUNG.Change
crates/victory-shader/src/emit/lower.rs, +73 lines: where one way of such a branch stays in a loop around the block (its header, or plain jumps to it) and the other leaves, the exit also holds when it holds in some lane of the host wave (WaveActiveAnyTrue), as the console's wave-wide test does. A lane still leaves on its own exit, so a wave of helper lanes only (which wave votes leave out) keeps the old rule. Other branches keep the lane rule, and branches inStructured::wide, which already carry the wave-wide answer, are left alone.Verification
cargo clippy --workspace --all-targets --locked -- -D warningsclean;cargo test --workspace --lockedpasses.🤖 Generated with Claude Code