Shaders: a loop whose trip count the program fixes runs every iteration, past the stage's loop cap (PS_IntegrateEnvBRDF) #3844
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!3844
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3844"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@CowboyBingus on GitHub · 2026-11-30 09:11 UTC · original
CowboyBingus:fix/loop-cap-constant-trip→main· +462 −8 · 3 files · 2 commits · merged 2026-11-30 14:12 UTCWhat it changes
loop_cap(emit/lower.rs) stops a translated pixel loop after 128 iterations (vertex and mesh 256, compute 4,096). The cap is for loops whose exit count comes from data the host does not have yet. It also cut loops whose count is fixed in the program. PS_IntegrateEnvBRDF (a467d848ace5810d) has three such loops: its counter starts at 0 and is compared with 1,024 (s_cmpk_eq_i32 …, 0x400), stepping by 4, 4 and 2, which is 256, 256 and 512 iterations. All three were stopped at 128. On a conditional back edge the cap joins the loop's own exit, so the program carried on with what it had summed, and nothing was logged.This change exempts loops whose trip count the program fixes:
emit/lower/trips.rs,constant_trip. A loop qualifies when:s_cbranch_scc0/1;s_cmp_*ors_cmpk_*(eq, lg, gt, ge, lt, le;_i32or_u32) of an SGPR counter with a constant;s_add_i32/u32,s_sub_i32/u32,s_addk_i32).s_mov_b32of a constant or bys_movk_i32.loop_cap(h)is now per loop: the larger of the stage's cap and the loop's own trip count. A limit named byVICTORY_SHADER_LOOP_LIMITis used unchanged.Every program of a local
known-shaders.bin(19,108 programs: vertex, pixel, compute and mesh) was translated throughemit::translatewith and without the change. A test-only hook infind_trips, not part of this PR, recorded each loop whose proven trip count is above its stage's cap. The loops this changes are in three pixel programs:a467d848ace5810dPS_IntegrateEnvBRDF8992ac65c3b6b5ebPS_IntegrateEnvBRDF_Beckmannf9b6e2728e0628b0PS_IntegrateEnvBRDF_ThinFilmWithout the change the hook records none. One of the 19,108 programs does not translate, with or without the change.
The translator's source changes, so cached translations are made again on the first run.
How it was tested
VICTORY_BVH_BUILDER=1,VICTORY_BVH_SIZE_COPY=1,VICTORY_LDS_LAST_RESORT=1).host wave lanes min=32 max=32);a467d848ace5810dis a wave64 console program.cargo test -p victory-shader --locked: 465 passed, 0 failed, 9 ignored. Three new tests inemit/lower/tests.rs:a_loop_of_constant_trip_count_runs_every_iteration: a pixel loop of four adds to 0x400 gets a limit of 256, two adds to 0x400 gets 512, one add to 0x100 gets 256; one add to 10 keeps 128; a count of 2^16 is kept and 2^16 + 1 keeps 128; a counter that never meets its bound keeps 128.a_loop_bounded_by_data_keeps_the_cap: a bound loaded withs_load_dwordis not a constant trip; a bound in a root constant keeps the compute cap of 4,096; the same loop bounded bys_movk_i32gets its own count.constant_trips_count_down_swap_and_compare_signed:s_sub_i32from 0x400 by 4 untils_cmpk_lg_i32 …, 0gets 256;s_cmp_gt_u32 0x100, s2(constant first) gets 256; from -512 by 2 whiles_cmp_lt_i32 …, 0gets 256, and withs_cmp_lt_u32(one iteration) keeps 128; a counter set again bys_mov_b32in the body keeps 128.shader_cache::tests::every_switch_of_the_translator_is_in_the_key(victory-gpu) fails with and without this change, with the same message:VICTORY_SCALAR_SPLITS is not read by the translator any more.cargo clippy --workspace --all-targets --locked -- -D warnings) fails on main41adb551too.victory-loader/src/crash.rs:804,function unwind_copy is never used: https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46320380085--keep-going, main and this branch both give the same five errors: that one, plus four in victory-shader:unused import: PAIR_MEETINGS(emit/lower/analysis.rs:6);unused import: analysis::lane_regions(emit/lower.rs:594on main, 603 here: the same line, moved down by this change's lines above it);variables in the condition are not mutated in the loop body(emit/lower/analysis.rs:467);this function has too many arguments (8/7)(native.rs:1655).git blameputs all five lines in commits that predate this change.a467d848ace5810dtranslated with and without the change, thendxc -dumpbin: exactly three lines differ, the loop-counter compares (icmp uge i32 …, 128became 256, 256 and 512). Each is or'ed with the loop's ownicmp eq i32 …, 1024exit.41adb551+ #3265 (A) and A + this change's first commit (B), release builds with--features diagnostics, from boot to the end of an indoor scene early in the game. (The second commit adds the third test and an early return infind_tripswhen a program has no loops.)shaders from the cache and translated so farhits 3,426 to 3,494, misses 0 to 2, andhost pipeline library loaded282,621,440 to 282,772,268 bytes.Across the two compared runs of each build, the A/B pair of frames with the smallest mean absolute RGB difference outside the three regions is A frame 32692 and B frame 33525 (3.26; both 41.09 s after the builder started). Their regions: left wall 8.53 to 10.84, behind the bar 10.16 to 12.27, upper back wall 14.64 to 12.96 (darker after). With the same measure, the closest pair between A's two runs is 2.01 and between B's two runs 1.55.
frame timeslog lines' medians (one line about every second): A runs 59.4, 84.5 and 93.4 ms; B runs 90.2, 55.9 and 97.8 ms.Checked for overlap
loop_cap, loop limit, loop cap, constant trip, trip count, IntegrateEnvBRDF,a467d848, BRDF. Related: #3063 (open) adds a per-program limit switch (VICTORY_SHADER_LOOP_LIMIT_OF) and edits the sameloop_capfunction, so whichever of the two merges second needs a rebase. #1866 made the mesh loop limit leave through the loop's exit; that path uses the sameloop_cap. #2853 and #3336 mention the loop limit; neither changesloop_capor its values.🤖 Generated with Claude Code
@Yoruiopz on GitHub · 2026-11-30 12:41 UTC · original
Independent verification on Windows using the official .05 binary and a locked build of exact PR head
04ad9975. Both runs used the same four inputs and the same Wave32 and descriptor-range settings. The three BRDF shaders all first bound together during a separate .05 boot on this machine.I checked the emitted DXIL for each cap and the original
1024loop exits. Both builds validated all four shaders and created all four D3D12 test pipelines on the RTX 5070 Laptop GPU (driver 610.88). The unrelated tiled-water compute shader produced byte-identical DXIL.This independently confirms the loop-cap correction and pipeline creation on a second NVIDIA configuration. Matched in-game lighting and frame pacing were outside this check.