Skip to content

A loop limit for compute programs alone (hair strands no longer scatter with VICTORY_SHADER_LOOP_LIMIT=32) - #683

Open
Danigamer05 wants to merge 1 commit into
fxceless:mainfrom
Danigamer05:fix/compute-loop-limit
Open

Danigamer05 wants to merge 1 commit into
fxceless:mainfrom
Danigamer05:fix/compute-loop-limit

Conversation

@Danigamer05

Copy link
Copy Markdown

Problem

With VICTORY_SHADER_LOOP_LIMIT=32, which NVIDIA Turing cards run with (#5: without it the device is lost), character hair renders as scattered strands around the head that change every frame.

A lane that reaches the translated loop limit leaves the program without its writes (count_iteration / abort_block in lower.rs). The hair simulation's per-vertex constraint pass (smh_sim_*:CS_SolvePerVertConstraint, 8 variants) has a uniform loop with one iteration per strand vertex, more than 32 of them. So its lanes never stored, and the strands drawn from the simulation buffers came from stale or never-written positions.

How it was narrowed down (RTX 2080 SUPER, 2119b0e):

  • all 30 smh_sim_* programs skipped → no scattered strands (posing and interpolation are fine)
  • only CS_WavePerSplineConstraint_32 skipped → still scattered
  • only the 8 CS_SolvePerVertConstraint variants skipped → scattered strands gone (hair hangs loose, since nothing constrains it)
  • the disassembly of that pass is lane-local (no LDS, no lane reads, no exchange between host waves), but it has a uniform loop (0xa20 → 0x1b4c, n-1 iterations)
  • general limit raised to 1024 → hair in place in 12 of 12 sampled world frames, 30 min, no device loss

Change

VICTORY_SHADER_LOOP_LIMIT_CS=<n> (diagnostics builds) sets the loop limit for compute programs only. If it is unset, compute follows VICTORY_SHADER_LOOP_LIMIT exactly as before. The shader cache keys on it. The README documents it, and there is a unit test for the parsing (the two limit parsers now share one helper).

Measurements (RTX 2080 SUPER, c96b4f2 + this change, prologue world, 25–30 min each, no device loss in any run)

Settings Hair fps GPU ms/frame
LOOP_LIMIT=32 only scattered (unchanged) 0.98 664
LOOP_LIMIT=32 + LOOP_LIMIT_CS=128 in place in every sampled world frame (one stray strand in two) 1.02 609
LOOP_LIMIT=32 + LOOP_LIMIT_CS=1024 in place 0.85 719

With 1024 a smeared copy of the character also appears along the bottom of the screen: some other compute loop now runs to its end. 128 does not show it, so the README recommends VICTORY_SHADER_LOOP_LIMIT=32 VICTORY_SHADER_LOOP_LIMIT_CS=128.

Not tested on AMD or on cards that run without a loop limit; for them nothing changes unless the new variable is set.

🤖 Generated with Claude Code

…er with VICTORY_SHADER_LOOP_LIMIT=32)

A lane that reaches the translated loop limit leaves the program without
its writes. The low limit NVIDIA Turing cards run with
(VICTORY_SHADER_LOOP_LIMIT=32; fxceless#5 loses the device
without it) also cuts genuine compute loops short: the hair simulation's
per-vertex constraint pass (smh_sim_*:CS_SolvePerVertConstraint) loops
once per vertex of a strand, more than 32 times, so its lanes never
stored and the strands drawn from the simulation buffers scattered
around the head, different every frame.

VICTORY_SHADER_LOOP_LIMIT_CS=<n> (diagnostics builds) sets the limit for
compute programs only; unset, they follow VICTORY_SHADER_LOOP_LIMIT as
before. The shader cache keys on it.

Measured on an RTX 2080 SUPER (prologue world, 25-30 min runs, no device
loss in any):
- c96b4f2 + this, VICTORY_SHADER_LOOP_LIMIT=32 only: strands scattered
  (unchanged), 0.98 fps.
- + VICTORY_SHADER_LOOP_LIMIT_CS=128: hair in place in every sampled world
  frame (a single stray strand in two), 1.02 fps.
- + VICTORY_SHADER_LOOP_LIMIT_CS=1024: hair in place, 0.85 fps, and a
  smeared copy of the character along the bottom of the screen (another
  compute loop that now runs to its end).
Before that, on 2119b0e: with the eight SolvePerVertConstraint variants
skipped the scattered strands were gone (hair hung loose instead), and
with the general limit at 1024 the hair was in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Danigamer05
Danigamer05 force-pushed the fix/compute-loop-limit branch from 3de8598 to d7bb22d Compare November 25, 2026 09:12
@Danigamer05

Copy link
Copy Markdown
Author

Rebased onto main at 9376fd6 (it was conflicting after the shader cache key change). The only real change from the old version: compute_loop_limit() now goes into translation_fingerprint() next to the loop limit, so cached translations are redone when VICTORY_SHADER_LOOP_LIMIT_CS changes. Unit tests and clippy for victory-shader pass; the in-game check on 9376fd6 (RTX 2080 SUPER) is running now.

AI-assisted (Claude Code).

@Danigamer05

Copy link
Copy Markdown
Author

In-game check on 9376fd6 + this PR, RTX 2080 SUPER, VICTORY_SHADER_LOOP_LIMIT=32 VICTORY_SHADER_LOOP_LIMIT_CS=128, no programs skipped: hair is drawn as whole strands in the first gameplay scene, about 3 fps.

AI-assisted (Claude Code).

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.

1 participant