Skip to content

Shaders: a loop leaves with the host wave when a VCC test of a lane compare says so - #196

Open
JaumeMarRib wants to merge 1 commit into
fxceless:mainfrom
JaumeMarRib:pr/loop-exit-wave-vote
Open

JaumeMarRib wants to merge 1 commit into
fxceless:mainfrom
JaumeMarRib:pr/loop-exit-wave-vote

Conversation

@JaumeMarRib

Copy link
Copy Markdown

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/vccnz of 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 in DXGI_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 in Structured::wide, which already carry the wave-wide answer, are left alone.

Verification

  • Offline, for a 32-lane host, the 999 pixel, mesh and compute programs dumped from a hang: every program that translated before still does; 21 pixel shaders change, among them the four the per-command timing named slowest.
  • RTX 5070 (Windows 11), opening cutscene into the first scene: before, a device hang every run; with this change, several 5-7 minute runs with DRED on and no hang or device removal (one with the D3D12 debug layer: 0 errors).
  • cargo clippy --workspace --all-targets --locked -- -D warnings clean; cargo test --workspace --locked passes.

🤖 Generated with Claude Code

…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>
RicerBoy added a commit to RicerBoy/DropItLikeItsHot that referenced this pull request Nov 24, 2026
… with the host wave when a VCC test of a lane compare says so

Part of #16

@Flyander Flyander left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rocobalt1

Copy link
Copy Markdown

This is the fix for the trade-off I reported in #62: with it, a 4060 Ti at VICTORY_SHADER_LOOP_LIMIT=256 draws the room and the hair, which it could not do before.

Setup: RTX 4060 Ti 8 GB, driver 32.0.16.1656, Ryzen 9 5900X, Windows 11; 4e17478 + #32 #77 #81 #9 #40 #83 #38 #51 #234 #188 + this PR (48747d8), diag build, --console series-s, VICTORY_SHADER_LOOP_LIMIT=256, VICTORY_NO_WATCHDOG=1, fresh data dir. TdrDelay=60.

without this PR with it
ceiling of the cell block missing - its lights float against the sky drawn, with the lamps on it
cell wall missing drawn
hair at loop limit 256 correct correct
frame in the yard 312 - 460 ms (median 312) 213 - 433 ms (median 414 in 5 frames, one 12 057-draw frame at 3 537 ms)
shader refusals 4 4
device removal none none

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.

Bezouro added a commit to Bezouro/VIctory that referenced this pull request Nov 24, 2026
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)
@luisaugustz

luisaugustz commented Nov 24, 2026 •

Copy link
Copy Markdown

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 578d459 + a staging-release fix + this PR's commit 365c3b2 (applied cleanly), diag build, Series X, VICTORY_SHADER_LOOP_LIMIT=256, VICTORY_CUT_WRITES=1, texture queue 1024 MB / 1000 ms with VICTORY_TEXTURE_BUDGET_MB=6144, DRED off, 41 AMD CS_RaytracingResolve skips + 2 others. Same prologue, 10 minutes each, cold shader cache for each new executable.

build final picture G-buffer albedo at the window view
control (no PR) clean, lit, ~3 fps once settled room wall black (not drawn), shirt black
with this PR blown out to white/orange, content torn into shifted blocks, 0.1 to 3 fps while loading room's white block wall drawn, orange shirt, complete textures
this PR, vote changed to the console wave's own half (waveActiveBallot dword by lane index for console wave32, waveAnyTrue for wave64) blown out the same way, no detail left not checked

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), waveAnyTrue would span two console waves. Testing the vote over the console wave's own half did not change the picture, so that is not it.

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.

@luisaugustz

Copy link
Copy Markdown

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 (578d459 + staging fix): the patch uses Structured::wide, which that base does not have. My run script ignored the failed compile and kept using the previous executable, an unrelated experiment of mine (exact-copy texture views, the one I reported as negative on #3). So the "with this PR" and "half-wave vote" rows, the blow-out, and the G-buffer remarks all describe that other build, not this PR. I have not tested this PR on an RX 9070 XT yet.

Sorry for the noise. If I get it building (it probably needs the change that adds Structured::wide), I'll post real numbers in a new comment.

AI-assisted (Claude Code).

bodnjenie14 pushed a commit to bodnjenie14/VIctory that referenced this pull request Nov 25, 2026
Integrate the clustered-light loop correction from fxceless/victory-fork#196 (365c3b2).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants