Skip to content

Shaders: retain empty-EXEC guards around a reachable loop - #888

Draft
Yoshi-233 wants to merge 1 commit into
trustno1-coder:mainfrom
Yoshi-233:fix/empty-exec-loop-guards
Draft

Yoshi-233 wants to merge 1 commit into
trustno1-coder:mainfrom
Yoshi-233:fix/empty-exec-loop-guards

Conversation

@Yoshi-233

Copy link
Copy Markdown

In ir::without_skips, an empty wave can enter a loop the guest would have branched around. The old walk recognises cycles composed of fully decided branches. If a scalar test is unresolved, revisiting its state is treated as already explored. The outer guard can then disappear and a lowering that bounds loop iterations can return before later stores.

This change tracks states on the current path separately from fully explored states. A reachable cycle, or exhausting the existing analysis budget, keeps the guard. An ordinary vector compare under empty EXEC produces an empty predicate mask; following VCCZ/VCCNZ lets the analysis still remove the guard around a provably single-pass loop.

Reproduction on current main (63b902f)

The new unit test uses synthetic instructions. It covers a VCCZ backedge, a scalar loop whose initial value comes from an inactive vector lane, and the VCCNZ control that can still be simplified. On the unmodified base the test fails on the VCCZ case. With the patch, cargo test --locked -p victory-shader --lib passed all 208 enabled tests (2 ignored).

Runtime evidence and review scope

On an RTX 4070 Ti SUPER, the diagnostic captures in #739 identify two watchdog exits and 1,039 affected workgroups. A separate replay of a 56-program selection yielded 52 validated DXIL outputs on both builds, with four hashes changed and no outputs lost or gained. One timed run took 19.12 s before and 27.08 s after for the replay including validation. This is a single pair, and compile cost is worth reviewing.

#326 also protects scalar-test loops as part of its Wave32 water changes. This PR is limited to the current skip analysis and explicitly tests VCC-controlled backedges. I am leaving it in draft: the earlier in-game candidate/control shared shader and pipeline caches, so that comparison cannot establish a visual fix. I have not measured a gameplay FPS improvement from this change.

@Yoshi-233

Copy link
Copy Markdown
Author

I reran the underwater test on the RTX 4070 Ti SUPER with separate, initially empty shader and pipeline caches. Both builds used copies of the same v100 save, Series X, 2560×1440 input to 3840×2160 DLSS Quality M, frame generation off and the same diagnostic instrumentation. The actual game log confirmed all 53 BVH-builder pipelines in both runs. The candidate differs from the control by the patch in this PR (stable patch ID ec53bf5de618973750ef4064e558a1aab654acf4).

The GPU compiled different DXIL for 926c46bab3b86bd6. The input container had the same SHA-256 prefix 3f81993d6def in both runs. The DXIL prefixes were 64c2c8ad9824 on the control and 3c1d390965f2 on the candidate. I matched the first sampled dispatch, DLSS evaluation and presented frame by their guest frame number.

Fully submerged captures Matched frames 8×8 groups with watchdog exits Groups with the diagnostic colour in the DLSS input
Control 3 271, 324, 289 271, 322, 289
With this patch 5 0 in all five 0 in all five

In the control, 883 groups exited at guest offset 0x101a8 and one at 0x11f80. The locations of the exit codes and the retained companion texture values agreed at every pixel. With the patch, both outputs replaced every injected marker in the five fully submerged captures (14,400 groups per capture).

I also kept a sixth candidate capture with the camera crossing the waterline. The companion texture kept its marker in the top 28 tile rows and part of row 28. It had zero watchdog codes and no diagnostic colour in the DLSS input. A dark horizontal band is still visible in some underwater views. The captures support the fix for these two exits. Surface colour, the buoy rectangle and gameplay 1% lows need their own measurements.

@MrEjecutor

Copy link
Copy Markdown

Tried this on a tree without #348 (no paired form), since #739 says it removes the dark rectangle at the buoy. It does seem to help the water here, but 13 programs lose their wave32 lowering with it, and some of them are used in play.

Setup: RTX 5060 Ti 16 GB, Core Ultra 5 225F, 32 GB, Windows 11. Series S, 1920x1080, no DLSS, no frame generation, diagnostics profile, victory.exe run. 8fc2254 plus local commits (a port of VICTORY_THIN_BAKE, fxceless's tile-slot rewrite of GenerateTiles, cache-key names, scripted keys), with and without this commit cherry-picked on top; nothing else differs. Shader cache and pipelines made again for each build.

Offline (translate --list, VICTORY_HOST_WAVE=32):

programs with "no wave32 lowering" lines "emitted"
without #888 22 25,763
with #888 35 25,747

5dc3b25986622949 and 6f225b641c5b0708 change their emitted hash, as expected. The 13 that stop translating:

1f1fbd86759b3da2 39998898c90889b2 4e9b58cc637d9272 67353810417f6c19 7842e2ce8ccd9280 a1bf269d5b19f025 b8f3f7979d6bbc50 c042a10ed3428758 d24ad002f5250958 d89ff746914b8cf7 e5d3e62bd4dfc1fb eae3498e6553afa8 fcd8b294ee41c57f

By their names they are the four cascade-shadow classification programs, the ray-tile sort of the scattering system, a river-simulation one, a particle-emit count, a decal classification and five decal/triangle heap relocations.

In the game (boat mission after the prologue, 470 s; and the opening, one run each):

"shader does not translate" in the log median fps on the boat route
without #888 1 (6b82bc7d22016cb5) 19 to 20 (several earlier runs)
with #888 9 16.2 (one run)

The 9 are 6b82bc7d22016cb5, a10179ab7eda0dc3, four of the list above (eae3498e6553afa8, b8f3f7979d6bbc50, a1bf269d5b19f025, 1f1fbd86759b3da2), and three that fail with "a lane mask exchanged where not every lane runs" at 0x218 (17af85f170e66f30, 477b52e73ddeb6f2, 8b437ab61d8008fe), which did not show in runs without the commit.

Picture, one run: the water is lit and I saw no dark rectangle beside a moored boat on the route. The boat cutscene is clearly darker than without the commit: people and mangroves stand in shade, which would fit the cascade-shadow classification being dropped.

So on this tree the extra kept guards seem to push these programs out of every wave32 form. Perhaps the guard should be kept only where the lowering that bounds the loop is the one taken, or these programs need the same retry that 926c46bab3b86bd6 got.

Not tested: with #348 or the other open PRs; 63b902f itself (its one commit over 8fc2254 touches no translator file); the buoy and marker close up; more than one run per build, so the fps and the darker cutscene are single observations. The opening run with the commit ended at the title's watchdog during a load after 288 s; that happens now and then without it too, so I do not count it.

AI-assisted (Claude Code): the builds, the runs and this text; the captures were judged by eye on my PC. No game files attached.

@d0dev

d0dev commented Nov 28, 2026

Copy link
Copy Markdown

Confirming on an RTX 4070 Ti SUPER 16 GB (Ryzen 7 5800X3D, Series X 1440p DLSS Quality): 63b902fe + this PR fixes the dark tile blocks on the water around the floating bales in the chapter 1 plane drop (same as the crates in #955), and under boats.

Before: blocks around the bale, even with #45 and #822 on top. Leaving shaders out while playing pinned it to 5dc3b25986622949 (CS_TransmissionVolumetrics_Tiled): with only it left out, the blocks went away (dark water); with only 6f225b641c5b0708 left out, they stayed. With #888 both run and the water around the bale is clean, with its light.

(Build: 63b902fe + #45, #822, #1019, #1018, #1066 with its switches off, #703, and this PR.)

@oz-stanislav-zhukov

Copy link
Copy Markdown

I saw the same on another tree: @MrEjecutor's list holds up here, and the picture shows it.

Setup: RTX 5060 Ti 16 GB, i7-14700KF, Windows 10. trustno1 main 63b902fe plus #814, #923, #933, #934, #919, #973, #1014, #1019, #1005, #1066 and a few others. Series S 720p → 1080p, DLSS Quality, FG 2x, VICTORY_WATER_LIGHT=1. Release build.

grey house
grey street

I reverted it locally for now. I'm happy to test a version that keeps the guards only where the wave32 lowering still succeeds.

AI-assisted (Claude Code, Claude Opus 5.5); no game data.

@MrEjecutor

Copy link
Copy Markdown

A small change on top of this PR gave me the water fix without the lost lowerings: when a program does not translate with the guards kept, try it once more with the walk as it was before. It is the same pattern emit() already uses for the loop step (LOOPS_OFF).

What I changed locally (on 8fc2254 + this PR):

  • ir.rs: the old stalls walk kept beside the new one, chosen by a thread-local that emit sets (with_loose_guards).
  • emit/mod.rs: emit() runs as now; on Err(Unsupported) it runs once more inside with_loose_guards and returns that result.
// sketch: arguments as emit() has them
pub fn emit(c, native, p, st, io, res) -> Result<HostShader, ShaderError> {
    let kept = emit_loops(c, native, p, st, io, res);        // the body emit() has today
    if !matches!(kept, Err(ShaderError::Unsupported { .. })) {
        return kept;
    }
    ir::with_loose_guards(|| emit_loops(c, native, p, st, io, res))
}

Results, same PC and settings as my comment above (RTX 5060 Ti 16 GB, Series S, no DLSS, victory.exe run; shader cache and pipelines made again for each build):

"no wave32 lowering" offline "emitted" lines "does not translate" in play boat route, release, median fps
base 22 25,763 1 or 2 24.8, 24.1
+ #888 35 25,747 9 (16.2, diagnostics build)
+ #888 + retry 22 25,763 2 24.9, 24.7
  • The refused set is the same 22 programs as on the base, and the two in play are the same two (6b82bc7d22016cb5, a10179ab7eda0dc3; the second is not bound in every run, hence "1 or 2").
  • 5dc3b25986622949 and 6f225b641c5b0708 get the same emitted hashes as with Shaders: retain empty-EXEC guards around a reachable loop #888 alone; 47 programs change their translation against the base.
  • Picture, one diagnostics run on the boat route plus one of the opening: the cutscene has its normal light again (not the dark one), the water is lit, and I saw no dark rectangle by the bridge's lamp platforms, where one showed on the base. I have not been close to the buoy and marker with it yet.

It costs a second translation of every program that fails with the guards kept (once per program, cached). It does not say why those 13 stop translating; it only puts them back where they were, so the real fix may be narrower than this.

Not tested: 63b902f and the open PRs; the Series X profile; more than a few runs; under water.

AI-assisted (Claude Code): the change, the runs and this text; the captures were judged by eye on my PC. No game files attached.

@d0dev

d0dev commented Nov 28, 2026

Copy link
Copy Markdown

Tried the retry from the comment above on an RTX 4070 Ti SUPER (Series X 1440p, DLSS Quality), on 63b902f + #888 + the retry: the dark squares in the water around the dropped bale in chapter 1 are gone, the water is lit, and shadows and the boat cutscene's light look normal. Boat: 26-28 fps idle, 18-25 accelerating/turning, no frame over 100 ms.

I also tried #742 instead of #888: the squares around the bale are gone too, but in that run part of the boat was missing its texture. I can't say yet whether that comes from #742 or was a one-off.

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.

4 participants