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

Open
github-bot wants to merge 1 commit from github-bot/gh-683 into main AGit
Owner

@⁠Danigamer05 on GitHub · 2026-11-25 04:24 UTC · original
Danigamer05:fix/compute-loop-limit → main · +58 −12 · 3 files · 1 commits · open

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

**@⁠Danigamer05** on GitHub · 2026-11-25 04:24 UTC · [original](https://github.com/fxceless/victory-fork/pull/683) `Danigamer05:fix/compute-loop-limit` → `main` · +58 −12 · 3 files · 1 commits · open ## 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](https://claude.com/claude-code)
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/victory-fork#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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:48:54 +00:00
Author
Owner

@⁠Danigamer05 on GitHub · 2026-11-25 09:12 UTC · original

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** on GitHub · 2026-11-25 09:12 UTC · [original](https://github.com/fxceless/victory-fork/pull/683#issuecomment-7158019453) 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).
Author
Owner

@⁠Danigamer05 on GitHub · 2026-11-25 09:16 UTC · original

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).

**@⁠Danigamer05** on GitHub · 2026-11-25 09:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/683#issuecomment-7158115676) 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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/683/head:github-bot/gh-683'
git switch 'github-bot/gh-683'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-683'
git switch 'github-bot/gh-683'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-683'
git switch 'github-bot/gh-683'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-683'
git switch 'main'
git merge --squash 'github-bot/gh-683'
git switch 'main'
git merge --ff-only 'github-bot/gh-683'
git switch 'main'
git merge 'github-bot/gh-683'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.