Shaders: the console's two nested waterfalls over a per-lane texture and sampler offset are proven by their shape (VICTORY_WATERFALL_NESTED, on unless 0) #4068

Closed
github-bot wants to merge 13 commits from github-bot/gh-4068 into main AGit
Owner

@⁠kMagic142 on GitHub · 2026-11-30 15:30 UTC · original
kMagic142:pr-waterfall → main · +1235 −823 · 33 files · 13 commits · closed without merging

What it changes

When a sample's texture and sampler both sit at per-lane table offsets, the console compiler wraps it in two nested waterfall loops. The outer loop reads the first waiting lane's sampler offset (v_readfirstlane_b32), narrows EXEC to the lanes with the same one (v_cmpx_eq_u32), keeps that EXEC and loads the sampler. The inner loop is the one Tracer::waterfall_shape (#458) proves, over the texture offset. A latch then moves the kept EXEC back and drops those lanes from the waiting ones (s_andn2_wrexec). Tracer::waterfall refuses the pair as "a waterfall loop nested in another or split over blocks", and waterfall_shape follows only the inner loop. So on main both stay loops: each pass has a first-lane read and a compare, and in a wave of 64 run as two host waves of 32, an exchange of the first lane's value between the halves.

Tracer::nested_waterfall_shape (resource.rs) proves the outer loop by its exact shape and the inner one with waterfall_shape. It runs only where waterfall and waterfall_shape both refuse. It requires:

  • the outer head holds only the first-lane reads and their v_cmpx_eq_u32/_i32 compares (the same rules as waterfall_shape), moves of EXEC, the table loads at those offsets, waits and s_nop; it runs straight into the inner loop and enters it with the EXEC the compares left;
  • the latch is reached from the inner loop alone and holds only a move of EXEC back to that value (checked by value), the s_andn2_wrexec retry, and the branch to the head;
  • the mask of waiting lanes is EXEC on every entry to the head, as for one loop: from outside, a move of the EXEC the loop is entered with; around the back edge, what the one retry wrote;
  • nothing past the loops reads an outer first-lane value or a copy of EXEC made in the head.

When all of that holds, every lane makes its access once, with both of its own table entries. One pass of per-lane loads does the same. As for one loop, both loads become non-uniform heap reads and the compares hold in every lane.

It is on by default, and VICTORY_WATERFALL_NESTED=0 leaves these loops as they are on main. The switch is in the shader cache key (KEYED in shader_cache.rs). Only programs that contain such a pair translate differently.

How it was tested

  • Where it comes from: our fork, which is based on v2026.11.28.03 with local changes. That tree is not main and does not have #458. There, an earlier version of this proof handled the same pair; it was opt-in at first and is on by default in our later builds. That version was built on our own single-loop proof instead of waterfall_shape. It also lacked the checks that nothing past the loops reads the outer offset or the EXEC copies. This PR is that proof ported onto waterfall_shape, with those checks added, so it is stricter than the version we ran.

  • GPU and profile: RTX 5090 on Windows, Series X profile, DLSS Quality, no frame generation, no ray tracing.

  • What we counted on our tree: with the single loop already proven, 698 console waterfall loops over first-lane table offsets were still unproven in the programs one gameplay run translated. 356 of those 698, in 42 programs, were these nested pairs. With #458 doing the single loop on main, the remaining set there may differ. The heaviest program with such pairs that we saw is the pixel program 94d281151ca58b4f of the mesh pass ef5409053e14aa82, which has nine such samples. Before the change, that draw took 0.29 and 0.38 ms of card time a frame in two runs.

  • Before and after: we did not measure this change on its own. No run isolates its effect on frame or card time, and there is no picture comparison for it alone. It has not been run on main.

  • For shader changes, the wave sizes tested: the new unit tests take the pair at 32 and at 64 lanes. In the title it ran only at the wave size our fork used for these programs, not at 32 and 64 separately.

  • cargo test passed for the crates it touches: yes, on main (41adb551) with this branch applied: cargo xwin check -p victory passes, and victory-shader's waterfall tests pass (35 passed, 0 failed), among them nested_console_waterfalls_over_a_texture_and_a_sampler_offset_are_one and the five variants that must stay unproven.

  • The new tests are in resource.rs. nested_console_waterfalls_over_a_texture_and_a_sampler_offset_are_one checks wave32 and wave64: two compares, two first-lane reads, and both loads per lane. Five variants must stay unproven:

    • the outer compare uses another lane value;
    • the outer head does other work;
    • the latch puts back the waiting lanes instead of the compared ones;
    • the waiting lanes do not start as EXEC;
    • code after the loops reads the outer offset.

    every_switch_of_the_translator_is_in_the_key in victory-gpu covers the new switch.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related:
    • #458 (merged) added waterfall_shape for the single loop. This proof uses it unchanged for the inner loop.
    • #1469 (merged) requires the final narrowing before a descriptor access. waterfall_shape keeps that check for the inner loop.
    • #2497 (open) also touches resource.rs, but in other functions (VALU address operands).
    • The KEYED list in shader_cache.rs gains one name, which may conflict textually with other open PRs that add switches there.
  • Our fork also proves the single waterfall over one first-lane table offset with a check of its own. Main does that with #458, so that part is not in this PR.
**@⁠kMagic142** on GitHub · 2026-11-30 15:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4068) `kMagic142:pr-waterfall` → `main` · +1235 −823 · 33 files · 13 commits · closed without merging ## What it changes When a sample's texture and sampler both sit at per-lane table offsets, the console compiler wraps it in two nested waterfall loops. The outer loop reads the first waiting lane's sampler offset (`v_readfirstlane_b32`), narrows EXEC to the lanes with the same one (`v_cmpx_eq_u32`), keeps that EXEC and loads the sampler. The inner loop is the one `Tracer::waterfall_shape` (#458) proves, over the texture offset. A latch then moves the kept EXEC back and drops those lanes from the waiting ones (`s_andn2_wrexec`). `Tracer::waterfall` refuses the pair as "a waterfall loop nested in another or split over blocks", and `waterfall_shape` follows only the inner loop. So on main both stay loops: each pass has a first-lane read and a compare, and in a wave of 64 run as two host waves of 32, an exchange of the first lane's value between the halves. `Tracer::nested_waterfall_shape` (`resource.rs`) proves the outer loop by its exact shape and the inner one with `waterfall_shape`. It runs only where `waterfall` and `waterfall_shape` both refuse. It requires: - the outer head holds only the first-lane reads and their `v_cmpx_eq_u32`/`_i32` compares (the same rules as `waterfall_shape`), moves of EXEC, the table loads at those offsets, waits and `s_nop`; it runs straight into the inner loop and enters it with the EXEC the compares left; - the latch is reached from the inner loop alone and holds only a move of EXEC back to that value (checked by value), the `s_andn2_wrexec` retry, and the branch to the head; - the mask of waiting lanes is EXEC on every entry to the head, as for one loop: from outside, a move of the EXEC the loop is entered with; around the back edge, what the one retry wrote; - nothing past the loops reads an outer first-lane value or a copy of EXEC made in the head. When all of that holds, every lane makes its access once, with both of its own table entries. One pass of per-lane loads does the same. As for one loop, both loads become non-uniform heap reads and the compares hold in every lane. It is on by default, and `VICTORY_WATERFALL_NESTED=0` leaves these loops as they are on main. The switch is in the shader cache key (`KEYED` in `shader_cache.rs`). Only programs that contain such a pair translate differently. ## How it was tested - Where it comes from: our fork, which is based on v2026.11.28.03 with local changes. That tree is not main and does not have #458. There, an earlier version of this proof handled the same pair; it was opt-in at first and is on by default in our later builds. That version was built on our own single-loop proof instead of `waterfall_shape`. It also lacked the checks that nothing past the loops reads the outer offset or the EXEC copies. This PR is that proof ported onto `waterfall_shape`, with those checks added, so it is stricter than the version we ran. - GPU and profile: RTX 5090 on Windows, Series X profile, DLSS Quality, no frame generation, no ray tracing. - What we counted on our tree: with the single loop already proven, 698 console waterfall loops over first-lane table offsets were still unproven in the programs one gameplay run translated. 356 of those 698, in 42 programs, were these nested pairs. With #458 doing the single loop on main, the remaining set there may differ. The heaviest program with such pairs that we saw is the pixel program `94d281151ca58b4f` of the mesh pass `ef5409053e14aa82`, which has nine such samples. Before the change, that draw took 0.29 and 0.38 ms of card time a frame in two runs. - Before and after: we did not measure this change on its own. No run isolates its effect on frame or card time, and there is no picture comparison for it alone. It has not been run on main. - For shader changes, the wave sizes tested: the new unit tests take the pair at 32 and at 64 lanes. In the title it ran only at the wave size our fork used for these programs, not at 32 and 64 separately. - `cargo test` passed for the crates it touches: yes, on main (41adb551) with this branch applied: `cargo xwin check -p victory` passes, and `victory-shader`'s waterfall tests pass (35 passed, 0 failed), among them `nested_console_waterfalls_over_a_texture_and_a_sampler_offset_are_one` and the five variants that must stay unproven. - The new tests are in `resource.rs`. `nested_console_waterfalls_over_a_texture_and_a_sampler_offset_are_one` checks wave32 and wave64: two compares, two first-lane reads, and both loads per lane. Five variants must stay unproven: - the outer compare uses another lane value; - the outer head does other work; - the latch puts back the waiting lanes instead of the compared ones; - the waiting lanes do not start as EXEC; - code after the loops reads the outer offset. `every_switch_of_the_translator_is_in_the_key` in `victory-gpu` covers the new switch. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: - #458 (merged) added `waterfall_shape` for the single loop. This proof uses it unchanged for the inner loop. - #1469 (merged) requires the final narrowing before a descriptor access. `waterfall_shape` keeps that check for the inner loop. - #2497 (open) also touches `resource.rs`, but in other functions (VALU address operands). - The `KEYED` list in `shader_cache.rs` gains one name, which may conflict textually with other open PRs that add switches there. - Our fork also proves the single waterfall over one first-lane table offset with a check of its own. Main does that with #458, so that part is not in this PR.
For a sample whose texture and sampler both sit at per-lane table
offsets, the console compiler emits two nested waterfall loops: the outer
one reads the first waiting lane's sampler offset, narrows EXEC to the
lanes with the same one and loads that sampler; the inner one is the loop
Tracer::waterfall_shape proves (#458), over the texture offset; then EXEC
goes back to the outer loop's lanes and they leave the waiting ones.
Tracer::waterfall refuses the pair as split over blocks, and
waterfall_shape follows the inner loop only, so both stay loops: per
pass, a first-lane read, the compare and, for a wave of 64 run as two
host waves, the exchange between the halves.

Tracer::nested_waterfall_shape proves the outer loop by its exact shape,
with the inner one proven by waterfall_shape:
- its head holds only the first-lane reads, their v_cmpx_eq compares (as
  in one loop), copies of EXEC, the table loads at those offsets, waits
  and s_nop, and runs into the inner loop, which it enters with the EXEC
  the compares left;
- its latch, reached from the inner loop alone, holds only a move of EXEC
  back to that value (a copy of it, by value), the s_andn2_wrexec retry
  and the branch back;
- the mask of waiting lanes is EXEC on every entry, as for one loop (a
  move of the entry EXEC; around the back edge, what the retry wrote);
- no outer first-lane value and no copy of EXEC made in the head is read
  past the loops.
Each lane then makes its access once with both of its own entries, which
is what one pass of per-lane loads does.

On by default; VICTORY_WATERFALL_NESTED=0 leaves the loops as before. The
switch is in the shader cache key. Tests: the pair in wave32 and wave64,
and five variants that must stay unproven (another lane value compared,
other work in the outer head, EXEC put back to the waiting lanes, waiting
lanes not starting as EXEC, the outer offset read after the loops).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 15:35:25 +00:00
Keeps main's VICTORY_VMEM_ALIGN4 and this branch's VICTORY_WATERFALL_NESTED
in the translator switch list (KEYED, now 48 names).
Author
Owner

@⁠VibeCodeGuy on GitHub · 2026-11-30 22:28 UTC · original

Offline corpus check (every shader container in a v1.0.2.1 dump: 25,699 unique programs), main e1251c31 against main + this PR at 4b1cf1de.

  • Newly failing: 0. Newly passing: 0.
  • DXIL output changed: 683 programs (602 Ps, 81 Cs); 683 of them pass the validator.
The 683 changed programs by family
  • 52 × PS_MirrorPedTextured_Eight
  • 52 × PS_PedAlphaPrepass
  • 52 × PS_PedAlphaPrepass_Decals
  • 52 × PS_PedTextured_Eight_Alpha
  • 52 × PS_PedTextured_Eight_Decals
  • 52 × PS_StudioPedTextured_Eight
  • 32 × PS_DeferredPedDecalTextured
  • 32 × PS_DeferredPedTexturedNC
  • 32 × PS_MirrorReflectionDeferredPedTexturedNC
  • 18 × PS_CascadeShadows_texture_alpha
  • 12 × PS_PedAlphaPrepass_Fire
  • 12 × PS_PedAlphaTransmission
  • 12 × PS_PedAlphaTransmission_Decals
  • 12 × PS_PedAlphaTransmission_Fire
  • 12 × PS_PedTextured_Eight_Fire
  • 10 × PS_DeferredPedTexturedNC_Packed
  • 9 × PS_MirrorReflectionTextured_Eight
  • 9 × PS_Textured_Eight
  • 9 × PS_VoxelizeVisiblity
  • 8 × PS_DeferredPedTextured_AlphaClipNC_Tint
  • 8 × PS_DeferredPedTextured_AlphaClip_Decal_Tint
  • 7 × PS_AlphaPrepass
  • 6 × PS_DeferredTextured_AlphaClip
  • 6 × PS_DeferredTextured
  • 6 × PS_MirrorReflectionDeferredDecalTextured
  • 6 × PS_MirrorReflectionDeferredTextured_AlphaClip
  • 6 × PS_MirrorReflectionDeferredTextured
  • 4 × PS_DeferredPedTextured_AlphaClipNC_Decal
  • 4 × PS_DeferredPedTextured_AlphaClipNC_Decal_Tint
  • 4 × PS_DeferredPedTextured_AlphaClipNC
  • 4 × PS_MirrorReflectionDeferredPedTextured_AlphaClipNC
  • 4 × PS_MirrorReflectionDeferredPedTextured_AlphaClipNC_Tint
  • 3 × ped_standard_garment_2lyr:CS_RaytracingResolve
  • 3 × ped_standard_lod_muv:CS_RaytracingResolve
  • 3 × ped_standard_lod_muv_cutout:CS_RaytracingResolve
  • 3 × ped_standard_lod_muv_emissive:CS_RaytracingResolve
  • 3 × ped_standard_muv:CS_RaytracingResolve
  • 3 × ped_standard_muv_anisotropy_sheen:CS_RaytracingResolve
  • 3 × ped_standard_muv_anisotropy_sheen_secmo:CS_RaytracingResolve
  • 3 × ped_standard_muv_blendshape:CS_RaytracingResolve
  • 3 × ped_standard_muv_blendshape_cutout:CS_RaytracingResolve
  • 3 × ped_standard_muv_cutout:CS_RaytracingResolve
  • 3 × ped_standard_muv_cutout_secmo:CS_RaytracingResolve
  • 3 × ped_standard_muv_diffraction:CS_RaytracingResolve
  • 3 × ped_standard_muv_diffraction_secmo:CS_RaytracingResolve
  • 3 × ped_standard_muv_emissive:CS_RaytracingResolve
  • 3 × ped_standard_muv_emissive_secmo:CS_RaytracingResolve
  • 3 × ped_standard_muv_iridescence:CS_RaytracingResolve
  • 3 × ped_standard_muv_iridescence_secmo:CS_RaytracingResolve
  • 3 × ped_standard_muv_retroreflection:CS_RaytracingResolve
  • 3 × ped_standard_muv_retroreflection_secmo:CS_RaytracingResolve
  • 3 × ped_standard_muv_secmo:CS_RaytracingResolve
  • 3 × weapon:CS_RaytracingResolve
  • 3 × weapon_garment_2lyr:CS_RaytracingResolve
  • 3 × weapon_muv_anisotropy_sheen:CS_RaytracingResolve
  • 3 × weapon_muv_clearcoat:CS_RaytracingResolve
  • 3 × weapon_muv_cutout:CS_RaytracingResolve
  • 3 × weapon_muv_emissive:CS_RaytracingResolve
  • 3 × weapon_muv_iridescence:CS_RaytracingResolve
  • 2 × PS_AlphaTransmission
  • 2 × PS_FPWeaponRedDotMotionBlurMask
  • 2 × PS_FPWeaponRedDot

How: victory translate <dump> --validate --list built for each side (release, cross-built with cargo-xwin, run under Wine), VICTORY_HOST_WAVE=32, plus the four shader-cache-key settings play starts with (VICTORY_EARLY_DEPTH=1, VICTORY_NAN_SCRUB=1, VICTORY_BVH_MISS=1, VICTORY_SAMPLED_MARKS=1). Validator: dxil.dll from DXC v1.9.2609. "Changed" compares translate's emitted hash of each module and its bindings. There was no GPU on this side, so no host pipelines were made and nothing was run on a card. On main the same run has 72 failures: 71 mesh programs over the 32 KiB output limit (the known shortcut in mesh_prologue) and CS_TraceShadowRays_FullAdaptive (#2993).

**@⁠VibeCodeGuy** on GitHub · 2026-11-30 22:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4068#issuecomment-7293899967) **Offline corpus check** (every shader container in a v1.0.2.1 dump: 25,699 unique programs), `main` e1251c31 against `main` + this PR at 4b1cf1de. - Newly failing: **0**. Newly passing: **0**. - DXIL output changed: **683** programs (602 Ps, 81 Cs); 683 of them pass the validator. <details><summary>The 683 changed programs by family</summary> - 52 × `PS_MirrorPedTextured_Eight` - 52 × `PS_PedAlphaPrepass` - 52 × `PS_PedAlphaPrepass_Decals` - 52 × `PS_PedTextured_Eight_Alpha` - 52 × `PS_PedTextured_Eight_Decals` - 52 × `PS_StudioPedTextured_Eight` - 32 × `PS_DeferredPedDecalTextured` - 32 × `PS_DeferredPedTexturedNC` - 32 × `PS_MirrorReflectionDeferredPedTexturedNC` - 18 × `PS_CascadeShadows_texture_alpha` - 12 × `PS_PedAlphaPrepass_Fire` - 12 × `PS_PedAlphaTransmission` - 12 × `PS_PedAlphaTransmission_Decals` - 12 × `PS_PedAlphaTransmission_Fire` - 12 × `PS_PedTextured_Eight_Fire` - 10 × `PS_DeferredPedTexturedNC_Packed` - 9 × `PS_MirrorReflectionTextured_Eight` - 9 × `PS_Textured_Eight` - 9 × `PS_VoxelizeVisiblity` - 8 × `PS_DeferredPedTextured_AlphaClipNC_Tint` - 8 × `PS_DeferredPedTextured_AlphaClip_Decal_Tint` - 7 × `PS_AlphaPrepass` - 6 × `PS_DeferredTextured_AlphaClip` - 6 × `PS_DeferredTextured` - 6 × `PS_MirrorReflectionDeferredDecalTextured` - 6 × `PS_MirrorReflectionDeferredTextured_AlphaClip` - 6 × `PS_MirrorReflectionDeferredTextured` - 4 × `PS_DeferredPedTextured_AlphaClipNC_Decal` - 4 × `PS_DeferredPedTextured_AlphaClipNC_Decal_Tint` - 4 × `PS_DeferredPedTextured_AlphaClipNC` - 4 × `PS_MirrorReflectionDeferredPedTextured_AlphaClipNC` - 4 × `PS_MirrorReflectionDeferredPedTextured_AlphaClipNC_Tint` - 3 × `ped_standard_garment_2lyr:CS_RaytracingResolve` - 3 × `ped_standard_lod_muv:CS_RaytracingResolve` - 3 × `ped_standard_lod_muv_cutout:CS_RaytracingResolve` - 3 × `ped_standard_lod_muv_emissive:CS_RaytracingResolve` - 3 × `ped_standard_muv:CS_RaytracingResolve` - 3 × `ped_standard_muv_anisotropy_sheen:CS_RaytracingResolve` - 3 × `ped_standard_muv_anisotropy_sheen_secmo:CS_RaytracingResolve` - 3 × `ped_standard_muv_blendshape:CS_RaytracingResolve` - 3 × `ped_standard_muv_blendshape_cutout:CS_RaytracingResolve` - 3 × `ped_standard_muv_cutout:CS_RaytracingResolve` - 3 × `ped_standard_muv_cutout_secmo:CS_RaytracingResolve` - 3 × `ped_standard_muv_diffraction:CS_RaytracingResolve` - 3 × `ped_standard_muv_diffraction_secmo:CS_RaytracingResolve` - 3 × `ped_standard_muv_emissive:CS_RaytracingResolve` - 3 × `ped_standard_muv_emissive_secmo:CS_RaytracingResolve` - 3 × `ped_standard_muv_iridescence:CS_RaytracingResolve` - 3 × `ped_standard_muv_iridescence_secmo:CS_RaytracingResolve` - 3 × `ped_standard_muv_retroreflection:CS_RaytracingResolve` - 3 × `ped_standard_muv_retroreflection_secmo:CS_RaytracingResolve` - 3 × `ped_standard_muv_secmo:CS_RaytracingResolve` - 3 × `weapon:CS_RaytracingResolve` - 3 × `weapon_garment_2lyr:CS_RaytracingResolve` - 3 × `weapon_muv_anisotropy_sheen:CS_RaytracingResolve` - 3 × `weapon_muv_clearcoat:CS_RaytracingResolve` - 3 × `weapon_muv_cutout:CS_RaytracingResolve` - 3 × `weapon_muv_emissive:CS_RaytracingResolve` - 3 × `weapon_muv_iridescence:CS_RaytracingResolve` - 2 × `PS_AlphaTransmission` - 2 × `PS_FPWeaponRedDotMotionBlurMask` - 2 × `PS_FPWeaponRedDot` </details> How: `victory translate <dump> --validate --list` built for each side (release, cross-built with cargo-xwin, run under Wine), `VICTORY_HOST_WAVE=32`, plus the four shader-cache-key settings `play` starts with (`VICTORY_EARLY_DEPTH=1`, `VICTORY_NAN_SCRUB=1`, `VICTORY_BVH_MISS=1`, `VICTORY_SAMPLED_MARKS=1`). Validator: `dxil.dll` from DXC v1.9.2609. "Changed" compares translate's `emitted` hash of each module and its bindings. There was no GPU on this side, so no host pipelines were made and nothing was run on a card. On `main` the same run has 72 failures: 71 mesh programs over the 32 KiB output limit (the known shortcut in `mesh_prologue`) and `CS_TraceShadowRays_FullAdaptive` (#2993).
github-bot closed this pull request 2026-12-01 18:50:44 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:46 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4068#issuecomment-7321528610) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!4068
No description provided.