Repository navigation
Shaders: a loop whose trip count the program fixes runs every iteration, past the stage's loop cap (PS_IntegrateEnvBRDF) - #3844
Merged
trustno1-coder merged 2 commits intoNov 30, 2026
Conversation
…ast the stage's loop cap loop_cap cuts pixel loops at 128 iterations (vertex and mesh 256, compute 4096), for loops whose count comes from data the host does not have yet. A loop whose counter starts from a constant, steps by constants and leaves on a compare with a constant cannot run away; it now gets its own trip count (up to 2^16) as its limit. PS_IntegrateEnvBRDF a467d848ace5810d's loops of 256, 256 and 512 samples were cut to 128. Covered: one back edge, an s_cbranch_scc0/1 on an s_cmp(k) of an SGPR counter with a constant; the counter a header phi entering as one constant and coming back as itself plus constants (s_add/s_sub _i32/_u32, s_addk_i32). Everything else keeps the cap, as does a limit a switch names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mpares, a counter set again; find_trips returns early without loops Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Independent verification on Windows using the official .05 binary and a locked build of exact PR head
I checked the emitted DXIL for each cap and the original 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What 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 main 41adb55 too.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.--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: Ray tracing: the BVH rehydration programs stop at 32 rounds and the builder's memory is coherent only where it asks (+15 % fps in play with ray tracing) #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. Shaders: mesh groups in whole console waves, mesh loop limits through the loop's exit, 16-bit writes over registers the host lacks #1866 made the mesh loop limit leave through the loop's exit; that path uses the sameloop_cap. Shaders: a folded program reads the joins of its lane masks (the particle light atlas ran to the loop limit) #2853 and Shaders: VICTORY_WAVE_VERIFY=check, a report-only checker that proves wave64 forms meet their group barriers #3336 mention the loop limit; neither changesloop_capor its values.🤖 Generated with Claude Code