perf(vk): fold constants and local arrays when unrolling AMD FSR 4, and unroll the postpass #1999

Open
madebyjordan wants to merge 3 commits from madebyjordan/Longshot:perf/fsr4-further into main
Member

Summary

Builds on #1752 (See #744) to further reduce AMD FSR 4 GPU time and cut cold first-run pipeline compilation time and memory by >40×.

On main, spirv_unroll::unroll_all blindly clones loop bodies containing 576-word OpStores into Function arrays and thousands of local-alloca OpAccessChain/OpLoad/OpStore instructions. That left pass1/pass2/pass12 at ~107,000 words (~50 s and ~3 GB commit charge each to build cold), caused pass4/pass5/pass10 to exceed 200,000 words (40–55 GB OOM, so they stayed rolled), and left postpass (the single slowest FSR 4 pass) rolled because it uses OpINotEqual, multi-OpPhi live-out loops, if (oob) continue;, and wave32.

What this changes:

  • gpu/vk/spirv_unroll.h: Upgrades spirv_unroll::unroll_all to hoist immutable constant-array OpStores once to each function's entry block, generalize innermost-first loop unrolling (OpULessThan, OpSLessThan, OpINotEqual, multi-OpPhi live-out loops, and single top-level if (cond) continue; selections), merge adjacent trivial blocks, fold 32-bit scalar/vector integer arithmetic, bitcasts, flat composites, and constant-array loads into immediate constants (while guarding OpAccessChain against negative or out-of-bounds constant indices from untaken branches), forward intra-block non-escaping plain Function allocas (with bitcasted-vector unpacking, safe dead-store tracking, and vector reassembly), and run exact fixed-point DCE (removing dead Function variables only after every store and access chain referencing them is gone, plus unused OpConstantComposite tables and stripped OpNames). Preserves OpDecorate by refusing decorated loop results/folds/forwarded loads, places new constants right before the first OpFunction (after all type declarations), guards operand counts against malformed SPIR-V, refuses non-32-bit OpSwitch in block merging and any OpSwitch or non-retargeted nested continue inside unrolled loops, and scans past OpLine/OpNoLine when checking merge-block OpPhis. Allocation and emission order are deterministic so Vulkan pipeline cache keys stay stable across runs.
  • gpu/vk/vk_fsr4.cpp (create_compute_pipelines, build_unrolled, destroy_pipeline, prepare_device, kCompactHeadroom / kBuildHeadroom): Removes the wave64-only (kind & 1) gate so postpass (also kind & 2) unrolls and saves into cache/longshot_fsr4_pipelines.bin alongside passes 1, 2, 4, 5, 10, 12, while preserving its requested subgroup size (unrolled_lanes: 64 for wave64 layers, else the original requested size / absent). Uses a two-tier cold-build headroom guard (kCompactHeadroom = 1 GiB only when the folded shader is <= kCompactUnrollWords = 60,000 words; keeps kBuildHeadroom = 8 GiB for larger shaders up to 120,000 words). Keys in-flight jobs by per-creation generation tokens (pending_token) so handle reuse never publishes a stale build, gives worker threads an immutable worker_fn dispatch table initialized in prepare_device(), and handles thread-creation and worker allocation failures with full Vulkan resource rollback. Leaves InitializerBuffer-only passes (pass3, 6, 7, 8, 9, 11) rolled after hardware ablations showed zero gain (and a +0.036 ms regression on pass6).
  • gpu/vk/fsr4_tune.h & docs/dev/reference/upscalers.md: Updates notes and measured figures (distinguishing standalone vs in-game cold compile times and noting eligibility limits).
  • tests/test_fsr4_tune.py, tests/test_fsr4_bind_dispatch.py, tests/fsr4_tune/postpass.hlsl, tests/fsr4_tune/postpass.spv: Adds a race-free DXC-compiled postpass miniature fixture (InBuffer + disjoint ScratchBuffer writes), an exact Python SPIR-V interpreter verifying bit-exact output parity across invocations and both continue outcomes for rolled, tail-rewritten, and unrolled+folded layer.spv and postpass.spv, synthetic SPIR-V regression tests for L1–L5 and L8–L10, Unicode-safe stdio transport, CXX env handling, Windows execution via {spirv_val} tool detection (no RUN_ALL_SKIP), and compiled behavioral tests in test_fsr4_bind_dispatch.py exercising the real create_compute_pipelines, build_unrolled, destroy_pipeline, cmd_bind_pipeline, and cmd_dispatch hooks (wave64 -> 64 lanes, postpass -> 32 lanes / null pNext, two-tier headroom, worker_fn isolation, and handle-reuse token cancellation).

Start review at gpu/vk/spirv_unroll.h (unroll_one, unroll_all, detail::fold_constants, detail::forward_function_allocas, detail::dce) and gpu/vk/vk_fsr4.cpp (build_unrolled, create_compute_pipelines, destroy_pipeline).

Testing

Tested:

  • In-game (Windows 11, AMD Radeon RX 6700 XT, Adrenalin 26.10.1, FSR 4.1.2): Built both main @ afc4d1ad and this PR @ b79edcc7 with LONGSHOT_FSR=1 and ran cold first-run builds plus 3 interleaved 30 s timing pairs (A1/B1/A2/B2/A3/B3) in Hyrule Field (child) at 2560×1440 output, AMD FSR 4 Performance 50% (1280×720), V-Sync Off, Frame Generation Off, cap 1000, RX_VK_PASS_TIMING=1. All 7 passes (pass1, 2, 4, 5, 10, 12, postpass) unrolled, compiled cold in 3.43 s total, saved to cache/longshot_fsr4_pipelines.bin (208 KB), and loaded 7/7 from cache on every subsequent start with clean rendering and -0.843 ms (-18.6%) faster fsr4 ffxDispatch.
  • Standalone FSR 4.1.2 parity & HDR check on corrected head (RX 6700 XT, Adrenalin 26.10.1, 1280×720 → 2560×1440):
    • All 13 FSR 4.1.2 SPIR-V shaders validated with spirv-val --target-env vulkan1.3 (0 failures, 100% deterministic across repeated runs, identical word counts 27311–44769 on all 7 unrolled passes).
    • SDR: 9.008 ms raw AMD → 3.517 ms (-61.0%), pass1/2/4/5/10/12 100% bit-exact (0 / 14,745,600 FP16 diffs); with postpass, 6 / 14,745,600 FP16 diffs (99.99996% bit-exact, max 2 ULP, all interior pixels, confirmed via NoContraction ablation to be one additional FMA contraction across the unrolled 2×2 quad).
    • HDR: 8.110 ms raw AMD → 3.329 ms (-59.0%, postpass 0.975 → 0.502 ms), 0 / 14,745,600 FP16 diffs (100% bit-exact).
  • Game-free checks on corrected head (Windows, llvm-mingw clang++, spirv-val):
    • tests/test_fsr4_tune.py --spirv-val spirv-val (honoring CXX=clang++, SPIR-V VM parity + L1–L10 edge cases): PASS
    • tests/test_fsr4_own_cache.py --cxx clang++: PASS
    • tests/test_fsr4_bind_dispatch.py --cxx clang++ --headers ... (compiled behavioral tests of create_compute_pipelines, build_unrolled, destroy_pipeline, cmd_bind_pipeline, cmd_dispatch): PASS
    • tests/run_all.py fsr4 (without --no-skip on Windows): 3 passed, 0 failed, 0 skipped
    • scripts/check_third_party.py: PASS
    • LONGSHOT_FSR=1 python -I scripts/dev.py vk (Windows llvm-mingw): compiled vk_fsr4.cpp with 0 errors and linked longshot_vk.dll (symbols checked).
    • tests/run_all.py --changed: all FSR 4 checks and all 4 C++ unit tests pass; 3 pre-existing failures on main @ f1f2dc5b in untouched files (tests/test_pass_barrier.py on vk_work.h, tests/test_upscaler_rows.py on vk_menu.cpp, tests/test_recorder_sync.py on vk_colour_vision.cpp).

Still to test:

  • Linux host build and full tests/run_all.py --strict suite on Ubuntu 24.04 (@Beanstalk or Linux CI).
  • Linux RADV with a Vulkan FSR 4 library (amd_fidelityfx_upscaler_vk.so): run Hyrule Field with FSR 4 enabled, verifying cold compile, cache hits, and visual parity (@Beanstalk or by hand).
  • RDNA 4 (RX 9000 series) Windows Adrenalin and FSR 4-capable Steam Deck configurations: run Hyrule Field with FSR 4 enabled, checking cold commit/pacing, warm cache hits, and parity across odd dimensions and SDR/HDR transitions (by hand).
  • Repeat in-game A/B on corrected head with Auto quality preset and a heavy scene, recording time-to-first-playable-frame and peak RAM/VRAM (by hand).

Measurements

Verdict: Faster: -18.6% (-0.843 ms) on in-game fsr4 ffxDispatch (AMD's passes) GPU time (4.542 → 3.699 ms, zero overlap across all 3 interleaved pairs), -0.82 ms mean frame time (23.96 → 23.14 ms), -0.40 ms median frame time (22.73 → 22.33 ms), -0.98 ms p99 frame time (31.70 → 30.72 ms), +3.6% mean FPS (41.74 → 43.22 fps), and 42.9× faster cold first-run background pipeline build (147.0 s for 3 passes → 3.43 s for all 7 passes, 0.33–0.69 s each in-game / 0.15–0.35 s standalone, <60 MB peak commit vs ~3 GB).

Setup: Windows 11, AMD Radeon RX 6700 XT, Adrenalin 26.10.1, AMD FSR 4.1.2, Hyrule Field (child), 2560×1440 output, FSR 4 Performance 50% (1280×720), V-Sync Off, Frame Generation Off, cap 1000 (HOS_FPS_MAX=1000, RX_VK_PASS_TIMING=1, RX_VK_FRAME_TRACE=1, RX_VK_AUTO_TUNE=0), 3 interleaved 30 s steady-state pairs (A1/B1/A2/B2/A3/B3) queued via scripts/dev.py queue run --mode timing after warming each side's cache/longshot_fsr4_pipelines.bin. Rebased onto current main @ fd7dc40d and updated with review soundness fixes; all 7 unrolled FSR 4.1.2 shaders emit the exact same validated SPIR-V word counts and passed spirv-val + standalone RX 6700 XT SDR/HDR parity checks, so the GPU-time measurements still hold.

Before: main @ afc4d1ad After: this PR @ b79edcc7 Δ
fsr4 ffxDispatch GPU (median of 3 runs) 4.542 ms (4.542 / 4.560 / 4.417) 3.699 ms (3.661 / 3.771 / 3.699) -0.843 ms (-18.6%)
Mean frame time (median of 3 runs) 23.96 ms (23.33 / 23.96 / 24.00) 23.14 ms (22.62 / 24.80 / 23.14) -0.82 ms (-3.4%)
Median frame time (median of 3 runs) 22.73 ms (22.73 / 22.57 / 23.26) 22.33 ms (21.84 / 23.61 / 22.33) -0.40 ms (-1.8%)
p99 frame time (median of 3 runs) 31.70 ms (31.70 / 38.69 / 31.03) 30.72 ms (29.57 / 48.05 / 30.72) -0.98 ms (-3.1%)
Mean FPS (median of 3 runs) 41.74 (42.86 / 41.74 / 41.66) 43.22 (44.20 / 40.33 / 43.22) +1.48 (+3.6%)
1% low FPS (median of 3 runs) 31.54 (31.54 / 25.84 / 32.23) 32.55 (33.82 / 20.81 / 32.55) +1.01 (+3.2%)
Cold first-run background builds (in-game, empty FSR 4 cache) 147.0 s (3 passes: 52.0 + 47.6 + 47.4 s) 3.43 s (all 7 passes: 0.33–0.69 s each) -143.6 s (42.9× faster)
Standalone SDR ffxDispatch (720p → 1440p) ~4.04 ms (9.008 ms raw AMD) 3.517 ms (postpass 0.943 → 0.640 ms) -0.52 ms (-61.0% vs raw)
Standalone HDR ffxDispatch (720p → 1440p) 8.110 ms raw AMD (postpass 0.975 ms) 3.329 ms (postpass 0.502 ms, bit-exact) -4.78 ms (-59.0% vs raw)

Risks

  • Driver/compiler differences on future FSR 4 builds or RADV: Every SPIR-V transform refuses any loop or instruction it does not understand (for_each_id operand-table check, non-escaping plain-access check, OpDecorate preservation, OpSwitch width check, dominance and type-equality checks), and if unroll_all leaves any loop rolled (left != 0) or exceeds kUnrollWords (120,000), the pass stays on the arrays_to_buffer / AMD fallback pipeline. Shaders larger than kCompactUnrollWords (60,000) still require the original kBuildHeadroom (8 GiB) before cold compilation.
  • How to turn it off: RX_VK_FSR4_TUNE=0 disables all FSR 4 shader tuning and runs AMD's shaders verbatim; a plain revert also restores the previous unroller cleanly.
  • What players notice after updating: On the first launch with FSR 4 enabled, the 7 newly folded SPIR-V hashes miss the previous cache/longshot_fsr4_pipelines.bin and rebuild in ~3.4 s total on a background thread (down from ~147 s), then save into cache/longshot_fsr4_pipelines.bin (~208 KB vs ~60 KB) for instant loads on subsequent starts. Saves and longshot_options.ini are untouched.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (Windows changed-file subset & all FSR 4 checks passed locally; 3 baseline main failures named in Testing; full Linux suite in Still to test).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) with UTF-8 paths (Linux build listed in Still to test).
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary Builds on #1752 (See #744) to further reduce AMD FSR 4 GPU time and cut cold first-run pipeline compilation time and memory by >40×. On `main`, `spirv_unroll::unroll_all` blindly clones loop bodies containing 576-word `OpStore`s into Function arrays and thousands of local-alloca `OpAccessChain`/`OpLoad`/`OpStore` instructions. That left `pass1`/`pass2`/`pass12` at ~107,000 words (~50 s and ~3 GB commit charge each to build cold), caused `pass4`/`pass5`/`pass10` to exceed 200,000 words (40–55 GB OOM, so they stayed rolled), and left `postpass` (the single slowest FSR 4 pass) rolled because it uses `OpINotEqual`, multi-`OpPhi` live-out loops, `if (oob) continue;`, and wave32. What this changes: - **`gpu/vk/spirv_unroll.h`**: Upgrades `spirv_unroll::unroll_all` to hoist immutable constant-array `OpStore`s once to each function's entry block, generalize innermost-first loop unrolling (`OpULessThan`, `OpSLessThan`, `OpINotEqual`, multi-`OpPhi` live-out loops, and single top-level `if (cond) continue;` selections), merge adjacent trivial blocks, fold 32-bit scalar/vector integer arithmetic, bitcasts, flat composites, and constant-array loads into immediate constants (while guarding `OpAccessChain` against negative or out-of-bounds constant indices from untaken branches), forward intra-block non-escaping plain Function allocas (with bitcasted-vector unpacking, safe dead-store tracking, and vector reassembly), and run exact fixed-point DCE (removing dead Function variables only after every store and access chain referencing them is gone, plus unused `OpConstantComposite` tables and stripped `OpName`s). Preserves `OpDecorate` by refusing decorated loop results/folds/forwarded loads, places new constants right before the first `OpFunction` (after all type declarations), guards operand counts against malformed SPIR-V, refuses non-32-bit `OpSwitch` in block merging and any `OpSwitch` or non-retargeted nested `continue` inside unrolled loops, and scans past `OpLine`/`OpNoLine` when checking merge-block `OpPhi`s. Allocation and emission order are deterministic so Vulkan pipeline cache keys stay stable across runs. - **`gpu/vk/vk_fsr4.cpp`** (`create_compute_pipelines`, `build_unrolled`, `destroy_pipeline`, `prepare_device`, `kCompactHeadroom` / `kBuildHeadroom`): Removes the wave64-only (`kind & 1`) gate so `postpass` (also `kind & 2`) unrolls and saves into `cache/longshot_fsr4_pipelines.bin` alongside passes `1, 2, 4, 5, 10, 12`, while preserving its requested subgroup size (`unrolled_lanes`: 64 for wave64 layers, else the original requested size / absent). Uses a two-tier cold-build headroom guard (`kCompactHeadroom = 1 GiB` only when the folded shader is `<= kCompactUnrollWords = 60,000` words; keeps `kBuildHeadroom = 8 GiB` for larger shaders up to `120,000` words). Keys in-flight jobs by per-creation generation tokens (`pending_token`) so handle reuse never publishes a stale build, gives worker threads an immutable `worker_fn` dispatch table initialized in `prepare_device()`, and handles thread-creation and worker allocation failures with full Vulkan resource rollback. Leaves `InitializerBuffer`-only passes (`pass3, 6, 7, 8, 9, 11`) rolled after hardware ablations showed zero gain (and a +0.036 ms regression on `pass6`). - **`gpu/vk/fsr4_tune.h`** & **`docs/dev/reference/upscalers.md`**: Updates notes and measured figures (distinguishing standalone vs in-game cold compile times and noting eligibility limits). - **`tests/test_fsr4_tune.py`**, **`tests/test_fsr4_bind_dispatch.py`**, **`tests/fsr4_tune/postpass.hlsl`**, **`tests/fsr4_tune/postpass.spv`**: Adds a race-free DXC-compiled `postpass` miniature fixture (`InBuffer` + disjoint `ScratchBuffer` writes), an exact Python SPIR-V interpreter verifying bit-exact output parity across invocations and both `continue` outcomes for rolled, tail-rewritten, and unrolled+folded `layer.spv` and `postpass.spv`, synthetic SPIR-V regression tests for L1–L5 and L8–L10, Unicode-safe stdio transport, `CXX` env handling, Windows execution via `{spirv_val}` tool detection (no `RUN_ALL_SKIP`), and compiled behavioral tests in `test_fsr4_bind_dispatch.py` exercising the real `create_compute_pipelines`, `build_unrolled`, `destroy_pipeline`, `cmd_bind_pipeline`, and `cmd_dispatch` hooks (wave64 -> 64 lanes, postpass -> 32 lanes / null `pNext`, two-tier headroom, `worker_fn` isolation, and handle-reuse token cancellation). Start review at `gpu/vk/spirv_unroll.h` (`unroll_one`, `unroll_all`, `detail::fold_constants`, `detail::forward_function_allocas`, `detail::dce`) and `gpu/vk/vk_fsr4.cpp` (`build_unrolled`, `create_compute_pipelines`, `destroy_pipeline`). ## Testing **Tested:** - **In-game (Windows 11, AMD Radeon RX 6700 XT, Adrenalin 26.10.1, FSR 4.1.2):** Built both `main @ afc4d1ad` and `this PR @ b79edcc7` with `LONGSHOT_FSR=1` and ran cold first-run builds plus 3 interleaved 30 s timing pairs (`A1/B1/A2/B2/A3/B3`) in Hyrule Field (child) at 2560×1440 output, AMD FSR 4 Performance 50% (1280×720), V-Sync Off, Frame Generation Off, cap 1000, `RX_VK_PASS_TIMING=1`. All 7 passes (`pass1, 2, 4, 5, 10, 12, postpass`) unrolled, compiled cold in 3.43 s total, saved to `cache/longshot_fsr4_pipelines.bin` (208 KB), and loaded 7/7 from cache on every subsequent start with clean rendering and `-0.843 ms` (`-18.6%`) faster `fsr4 ffxDispatch`. - **Standalone FSR 4.1.2 parity & HDR check on corrected head (RX 6700 XT, Adrenalin 26.10.1, 1280×720 → 2560×1440):** - All 13 FSR 4.1.2 SPIR-V shaders validated with `spirv-val --target-env vulkan1.3` (0 failures, 100% deterministic across repeated runs, identical word counts `27311–44769` on all 7 unrolled passes). - SDR: `9.008 ms` raw AMD → `3.517 ms` (`-61.0%`), `pass1/2/4/5/10/12` 100% bit-exact (`0 / 14,745,600` FP16 diffs); with `postpass`, `6 / 14,745,600` FP16 diffs (99.99996% bit-exact, max 2 ULP, all interior pixels, confirmed via `NoContraction` ablation to be one additional FMA contraction across the unrolled 2×2 quad). - HDR: `8.110 ms` raw AMD → `3.329 ms` (`-59.0%`, `postpass` `0.975 → 0.502 ms`), **`0 / 14,745,600` FP16 diffs (100% bit-exact)**. - **Game-free checks on corrected head (Windows, llvm-mingw `clang++`, `spirv-val`):** - `tests/test_fsr4_tune.py --spirv-val spirv-val` (honoring `CXX=clang++`, SPIR-V VM parity + L1–L10 edge cases): PASS - `tests/test_fsr4_own_cache.py --cxx clang++`: PASS - `tests/test_fsr4_bind_dispatch.py --cxx clang++ --headers ...` (compiled behavioral tests of `create_compute_pipelines`, `build_unrolled`, `destroy_pipeline`, `cmd_bind_pipeline`, `cmd_dispatch`): PASS - `tests/run_all.py fsr4` (without `--no-skip` on Windows): 3 passed, 0 failed, 0 skipped - `scripts/check_third_party.py`: PASS - `LONGSHOT_FSR=1 python -I scripts/dev.py vk` (Windows llvm-mingw): compiled `vk_fsr4.cpp` with 0 errors and linked `longshot_vk.dll` (symbols checked). - `tests/run_all.py --changed`: all FSR 4 checks and all 4 C++ unit tests pass; 3 pre-existing failures on `main @ f1f2dc5b` in untouched files (`tests/test_pass_barrier.py` on `vk_work.h`, `tests/test_upscaler_rows.py` on `vk_menu.cpp`, `tests/test_recorder_sync.py` on `vk_colour_vision.cpp`). **Still to test:** - Linux host build and full `tests/run_all.py --strict` suite on Ubuntu 24.04 (`@Beanstalk` or Linux CI). - Linux RADV with a Vulkan FSR 4 library (`amd_fidelityfx_upscaler_vk.so`): run Hyrule Field with FSR 4 enabled, verifying cold compile, cache hits, and visual parity (`@Beanstalk` or by hand). - RDNA 4 (RX 9000 series) Windows Adrenalin and FSR 4-capable Steam Deck configurations: run Hyrule Field with FSR 4 enabled, checking cold commit/pacing, warm cache hits, and parity across odd dimensions and SDR/HDR transitions (`by hand`). - Repeat in-game A/B on corrected head with Auto quality preset and a heavy scene, recording time-to-first-playable-frame and peak RAM/VRAM (`by hand`). ## Measurements **Verdict:** Faster: `-18.6%` (`-0.843 ms`) on in-game `fsr4 ffxDispatch (AMD's passes)` GPU time (`4.542 → 3.699 ms`, zero overlap across all 3 interleaved pairs), `-0.82 ms` mean frame time (`23.96 → 23.14 ms`), `-0.40 ms` median frame time (`22.73 → 22.33 ms`), `-0.98 ms` p99 frame time (`31.70 → 30.72 ms`), `+3.6%` mean FPS (`41.74 → 43.22 fps`), and `42.9×` faster cold first-run background pipeline build (`147.0 s` for 3 passes → `3.43 s` for all 7 passes, `0.33–0.69 s` each in-game / `0.15–0.35 s` standalone, `<60 MB` peak commit vs `~3 GB`). Setup: Windows 11, AMD Radeon RX 6700 XT, Adrenalin 26.10.1, AMD FSR 4.1.2, Hyrule Field (child), 2560×1440 output, FSR 4 Performance 50% (1280×720), V-Sync Off, Frame Generation Off, cap 1000 (`HOS_FPS_MAX=1000`, `RX_VK_PASS_TIMING=1`, `RX_VK_FRAME_TRACE=1`, `RX_VK_AUTO_TUNE=0`), 3 interleaved 30 s steady-state pairs (`A1/B1/A2/B2/A3/B3`) queued via `scripts/dev.py queue run --mode timing` after warming each side's `cache/longshot_fsr4_pipelines.bin`. Rebased onto current `main @ fd7dc40d` and updated with review soundness fixes; all 7 unrolled FSR 4.1.2 shaders emit the exact same validated SPIR-V word counts and passed `spirv-val` + standalone RX 6700 XT SDR/HDR parity checks, so the GPU-time measurements still hold. | | Before: main @ afc4d1ad | After: this PR @ b79edcc7 | Δ | |---|---|---|---| | `fsr4 ffxDispatch` GPU (median of 3 runs) | 4.542 ms (`4.542 / 4.560 / 4.417`) | 3.699 ms (`3.661 / 3.771 / 3.699`) | -0.843 ms (-18.6%) | | Mean frame time (median of 3 runs) | 23.96 ms (`23.33 / 23.96 / 24.00`) | 23.14 ms (`22.62 / 24.80 / 23.14`) | -0.82 ms (-3.4%) | | Median frame time (median of 3 runs) | 22.73 ms (`22.73 / 22.57 / 23.26`) | 22.33 ms (`21.84 / 23.61 / 22.33`) | -0.40 ms (-1.8%) | | p99 frame time (median of 3 runs) | 31.70 ms (`31.70 / 38.69 / 31.03`) | 30.72 ms (`29.57 / 48.05 / 30.72`) | -0.98 ms (-3.1%) | | Mean FPS (median of 3 runs) | 41.74 (`42.86 / 41.74 / 41.66`) | 43.22 (`44.20 / 40.33 / 43.22`) | +1.48 (+3.6%) | | 1% low FPS (median of 3 runs) | 31.54 (`31.54 / 25.84 / 32.23`) | 32.55 (`33.82 / 20.81 / 32.55`) | +1.01 (+3.2%) | | Cold first-run background builds (in-game, empty FSR 4 cache) | 147.0 s (3 passes: 52.0 + 47.6 + 47.4 s) | 3.43 s (all 7 passes: 0.33–0.69 s each) | -143.6 s (42.9× faster) | | Standalone SDR `ffxDispatch` (720p → 1440p) | ~4.04 ms (9.008 ms raw AMD) | 3.517 ms (`postpass` 0.943 → 0.640 ms) | -0.52 ms (-61.0% vs raw) | | Standalone HDR `ffxDispatch` (720p → 1440p) | 8.110 ms raw AMD (`postpass` 0.975 ms) | 3.329 ms (`postpass` 0.502 ms, bit-exact) | -4.78 ms (-59.0% vs raw) | ## Risks - **Driver/compiler differences on future FSR 4 builds or RADV:** Every SPIR-V transform refuses any loop or instruction it does not understand (`for_each_id` operand-table check, non-escaping plain-access check, `OpDecorate` preservation, `OpSwitch` width check, dominance and type-equality checks), and if `unroll_all` leaves any loop rolled (`left != 0`) or exceeds `kUnrollWords` (120,000), the pass stays on the `arrays_to_buffer` / AMD fallback pipeline. Shaders larger than `kCompactUnrollWords` (60,000) still require the original `kBuildHeadroom` (8 GiB) before cold compilation. - **How to turn it off:** `RX_VK_FSR4_TUNE=0` disables all FSR 4 shader tuning and runs AMD's shaders verbatim; a plain revert also restores the previous unroller cleanly. - **What players notice after updating:** On the first launch with FSR 4 enabled, the 7 newly folded SPIR-V hashes miss the previous `cache/longshot_fsr4_pipelines.bin` and rebuild in ~3.4 s total on a background thread (down from ~147 s), then save into `cache/longshot_fsr4_pipelines.bin` (~208 KB vs ~60 KB) for instant loads on subsequent starts. Saves and `longshot_options.ini` are untouched. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (Windows changed-file subset & all FSR 4 checks passed locally; 3 baseline `main` failures named in Testing; full Linux suite in Still to test). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) with UTF-8 paths (Linux build listed in Still to test). - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
perf(vk): fold constants and local arrays when unrolling AMD FSR 4, and unroll the postpass
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 10s
PR description / Description follows the template (pull_request_target) Successful in 12s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 12s
CI / Workflow lint (actionlint) (pull_request) Successful in 14s
Third-party parts / As their notes say (pull_request) Successful in 14s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Website build and checks (pull_request) Failing after 28s
de6ab96897
Assisted-by: Gemini (Antigravity)
Author
Member

Tested in game: Windows 11, AMD Radeon RX 6700 XT (Adrenalin 26.10.1), Hyrule Field (child), 2560x1440 output, AMD FSR 4.1.2 Performance 50% (1280x720), V-Sync Off, FG Off, cap 1000. All 7 passes (pass1, 2, 4, 5, 10, 12, postpass) unrolled and compiled cold in 3.43 s total (vs 147.0 s for 3 passes on main), saved to cache/longshot_fsr4_pipelines.bin (208 KB), loaded 7/7 from cache on restarts, and cut fsr4 ffxDispatch GPU time from 4.542 ms to 3.699 ms (-18.6%) across 3 interleaved 30 s pairs.

Tested in game: Windows 11, AMD Radeon RX 6700 XT (Adrenalin 26.10.1), Hyrule Field (child), 2560x1440 output, AMD FSR 4.1.2 Performance 50% (1280x720), V-Sync Off, FG Off, cap 1000. All 7 passes (pass1, 2, 4, 5, 10, 12, postpass) unrolled and compiled cold in 3.43 s total (vs 147.0 s for 3 passes on main), saved to cache/longshot_fsr4_pipelines.bin (208 KB), loaded 7/7 from cache on restarts, and cut fsr4 ffxDispatch GPU time from 4.542 ms to 3.699 ms (-18.6%) across 3 interleaved 30 s pairs.
BeanBot requested changes 2026-11-21 03:52:17 +00:00
Dismissed
BeanBot left a comment

Recommendation: Request changes. The RX 6700 XT runs show a substantial FSR 4 GPU-time saving. The rewrite can change shader results or emit invalid SPIR-V for valid inputs, and the lower cold-build memory guard also admits shader and driver combinations outside the measured range.

Folds weights and local scratch storage into the unrolled FSR 4 shaders, adds the postpass to the background rebuilds, and caches the replacements. This could cut first-run compilation and steady-state GPU time. The cost is a larger shader optimizer with more correctness obligations and more pipelines competing for resources during startup.

@fix will do (21)

  1. L1 gpu/vk/spirv_unroll.h:466: The composite tracking treats constructor operands as lanes, but SPIR-V vector constructors can mix vectors and scalars. (more on the line)
  2. L2 gpu/vk/spirv_unroll.h:1255: Unrolling now accepts decorated loop results, then drops their OpDecorate instructions without cloning them. (more on the line)
  3. L3 gpu/vk/spirv_unroll.h:891: Forwarding deletes the load before DCE can record its result as removed, while apply_aliases skips OpName and OpDecorate. (more on the line)
  4. L4 gpu/vk/spirv_unroll.h:248: New constants are inserted after the last recognized constant, which can precede the declaration of their type. (more on the line)
  5. L5 gpu/vk/spirv_unroll.h:949: DCE can remove a Function variable while leaving a store that still uses it. (more on the line)
  6. L6 gpu/vk/spirv_unroll.h:943: The eight-round DCE limit can leave a surviving chain rooted at a deleted variable. (more on the line)
  7. L7 gpu/vk/spirv_unroll.h:1022: Block merging reads every OpSwitch case as a 32-bit literal and label. (more on the line)
  8. L8 gpu/vk/spirv_unroll.h:1225: A continue that misses the narrow pattern is still cloned. (more on the line)
  9. L9 gpu/vk/spirv_unroll.h:1276: The merge-block check inspects one instruction immediately after OpLabel. (more on the line)
  10. L10 gpu/vk/spirv_unroll.h:211: The parser checks instruction framing but the new scans assume opcode-specific operands exist. (more on the line)
  11. L11 gpu/vk/vk_fsr4.cpp:299: The 1 GiB guard covers every admitted cold compile, while the size limit still admits up to 120,000 words. (more on the line)
  12. L12 gpu/vk/vk_fsr4.cpp:826: The expanded job path counts a worker and allocates its Vulkan layouts before constructing the thread. (more on the line)
  13. L13 gpu/vk/vk_fsr4.cpp:821: The new postpass job inherits cancellation keyed only by the raw VkPipeline handle. (more on the line)
  14. L14 gpu/vk/vk_fsr4.cpp:674: The extra background job reads plain driver function pointers that device_proc rewrites. (more on the line)
  15. L15 tests/test_fsr4_tune.py:319: Validation and instruction counts would pass if a fold selected the wrong weight or returned a stale accumulator. (more on the line)
  16. L16 (minor) tests/test_fsr4_tune.py:204: The subgroup checks match specific source strings. (more on the line)
  17. L17 (minor) tests/test_fsr4_tune.py:27: The normal runner skips the expanded test on Windows even when spirv-val is installed, and the direct invocation ignores CXX unless --cxx is supplied. The driver also opens paths through narrow argv and streams, which can fail for a checkout or temp directory outside the Windows code page. Use tool availability to gate the test, honor CXX, and pass fixture and output paths through a Unicode-capable interface.
  18. L18 (minor): The checklist claims the full suite passed and the host code built on Linux. Testing reports a changed-file subset and a Windows build. Record the full suite and the Linux build with the supported compilers, or mark those checks pending. The three named baseline failures can stay listed.
  19. L19 (its part an edit can do): Log time to the first playable frame separately from background compilation and cache hits, and report the per-run frame-time percentiles and peak memory.
  20. L20 (its part an edit can do): Keep the measured shader and driver combinations on the new cold path while retaining the existing fallback on combinations awaiting coverage.
  21. L21 (minor) docs/dev/reference/upscalers.md:26: The cache paragraph says the layers and postpass are unrolled, although six layers stay rolled in the reported setup and eligibility also depends on the module, driver, and headroom. (more on the line)

For the author (2) (a run, a measurement or a decision)

  • L19 (minor): Repeat the comparison on the merge base and corrected head. The supplied Performance-preset run establishes a GPU-time gain on the earlier pair, while FPS overlaps and median and p99 frame times are missing. Include Auto's chosen quality preset and a heavy scene, paste the source log lines, and report cold and warm time to the first playable frame, peak RAM and VRAM, and cache size. The current cold total measures background jobs.
  • L20 (minor): The default reaches RADV and newer Adrenalin models, while the reported runs cover one Windows RDNA 2 card. Finish the listed Linux RADV and Windows RDNA 4 runs, and cover FSR 4-capable Steam Deck configurations. Check cold commit and pacing, warm cache hits, and output parity on odd dimensions and during SDR/HDR or context changes.

Checks: Still running: CI / Website build and checks (pull_request), PR description / Description follows the template (pull_request_target), CI / Conventional Commit title (pull_request), CI / Workflow lint (actionlint) (pull_request), Guide screenshots / Guide images and local UI source review (pull_request), Third-party parts / As their notes say (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Unproven on the review head. The reported Windows RX 6700 XT comparison at afc4d1ad versus b79edcc7 shows 4.542 to 3.699 ms FSR 4 GPU time across three interleaved pairs with no overlap. It also reports 147.0 to 3.43 s of cold background builds and roughly 3 GB to under 60 MB peak commit. Mean FPS and 1% lows overlap, and one pair's 1% low fell from 25.84 to 20.81 FPS. Equal shader word counts after the rebase establish neither equal shader bytes nor equal driver behavior.

Other systems: The rewrite runs through the optional FSR 4 runtime and the AMD-only tuning policy. NVIDIA, Intel, and other upscalers bypass it. FSR 4 Quality, native AA, HDR, frame generation with FSR 4 input, other Adrenalin models, RADV, and Steam Deck configurations that load FSR 4 still need coverage. The standalone HDR comparison reported exact output on the tested card. Cold jobs share the renderer's compute compilation gate, and the tested dedicated cache grew from about 60 to 208 KB. The diff leaves save, input, audio, and renderer API code alone.

Switches: No setting or switch is added or removed. The existing RX_VK_FSR4_TUNE default is on for AMD and off elsewhere, with =0 selecting the vendor shaders. Its switch-table row covers the expanded path, but the wider default still needs affected Tier 1 coverage. The internal cold-build threshold falls from 8 GiB to 1 GiB. Only the reported RX 6700 XT setup supports the lower value so far.

Reviewed: de6ab96897 against f1f2dc5bd2: Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, the development standards, the full seven-file diff and commit, and the full text of spirv_unroll.h, vk_fsr4.cpp, fsr4_tune.h, upscalers.md, test_fsr4_tune.py, and postpass.hlsl. Traced the operand table, device policy, cache and close callers, and related test harnesses. Skimmed the generated SPIR-V blob and the supplied run reports and CI status. The checkout had no review-checklist file. Fixture regeneration and recorded shader bytes from the benchmark were unverified.; nothing run (a code review).

Checked and fine:

  • The commit has an Assisted-by trailer and a Conventional Commit title. The HLSL fixture uses authored weights, and the diff contains no apparent game-derived material or vendor runtime.
  • The change stays on the FSR 4 topic and leaves third_party and the versioned renderer interface alone. The added fixture includes its DXC generation command.
  • The job captures the requested numeric lane count before moving Plain. A non-wave64 pass with no explicit request keeps a null subgroup-size chain.
  • Cache probing still precedes the cold-build headroom check. Bind and dispatch still remember which pipeline was actually bound if a worker publishes between them.
  • The scalar folds guard divide-by-zero, signed division overflow, and oversized shifts. Trip counts use widened arithmetic and reject the checked wrap cases.
  • The diff adds no downloads, external service calls, or build and CI script changes.

Testing: Read-only review. git diff --check passed. The author reports a Windows build, fixture and cache checks, three interleaved in-game pairs, and standalone SDR/HDR parity with six SDR values differing by at most 2 ULP. CI was still running in the supplied status. No builds or tests were executed for this review.

Overlaps and merge order: The prerequisite FSR 4 changes #2798 and #1752 are already in the base. No other overlap found in the supplied material or local history.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The RX 6700 XT runs show a substantial FSR 4 GPU-time saving. The rewrite can change shader results or emit invalid SPIR-V for valid inputs, and the lower cold-build memory guard also admits shader and driver combinations outside the measured range. Folds weights and local scratch storage into the unrolled FSR 4 shaders, adds the postpass to the background rebuilds, and caches the replacements. This could cut first-run compilation and steady-state GPU time. The cost is a larger shader optimizer with more correctness obligations and more pipelines competing for resources during startup. **`@fix` will do (21)** 1. **L1** `gpu/vk/spirv_unroll.h:466`: The composite tracking treats constructor operands as lanes, but SPIR-V vector constructors can mix vectors and scalars. (more on the line) 2. **L2** `gpu/vk/spirv_unroll.h:1255`: Unrolling now accepts decorated loop results, then drops their OpDecorate instructions without cloning them. (more on the line) 3. **L3** `gpu/vk/spirv_unroll.h:891`: Forwarding deletes the load before DCE can record its result as removed, while apply_aliases skips OpName and OpDecorate. (more on the line) 4. **L4** `gpu/vk/spirv_unroll.h:248`: New constants are inserted after the last recognized constant, which can precede the declaration of their type. (more on the line) 5. **L5** `gpu/vk/spirv_unroll.h:949`: DCE can remove a Function variable while leaving a store that still uses it. (more on the line) 6. **L6** `gpu/vk/spirv_unroll.h:943`: The eight-round DCE limit can leave a surviving chain rooted at a deleted variable. (more on the line) 7. **L7** `gpu/vk/spirv_unroll.h:1022`: Block merging reads every OpSwitch case as a 32-bit literal and label. (more on the line) 8. **L8** `gpu/vk/spirv_unroll.h:1225`: A continue that misses the narrow pattern is still cloned. (more on the line) 9. **L9** `gpu/vk/spirv_unroll.h:1276`: The merge-block check inspects one instruction immediately after OpLabel. (more on the line) 10. **L10** `gpu/vk/spirv_unroll.h:211`: The parser checks instruction framing but the new scans assume opcode-specific operands exist. (more on the line) 11. **L11** `gpu/vk/vk_fsr4.cpp:299`: The 1 GiB guard covers every admitted cold compile, while the size limit still admits up to 120,000 words. (more on the line) 12. **L12** `gpu/vk/vk_fsr4.cpp:826`: The expanded job path counts a worker and allocates its Vulkan layouts before constructing the thread. (more on the line) 13. **L13** `gpu/vk/vk_fsr4.cpp:821`: The new postpass job inherits cancellation keyed only by the raw VkPipeline handle. (more on the line) 14. **L14** `gpu/vk/vk_fsr4.cpp:674`: The extra background job reads plain driver function pointers that device_proc rewrites. (more on the line) 15. **L15** `tests/test_fsr4_tune.py:319`: Validation and instruction counts would pass if a fold selected the wrong weight or returned a stale accumulator. (more on the line) 16. **L16** (minor) `tests/test_fsr4_tune.py:204`: The subgroup checks match specific source strings. (more on the line) 17. **L17** (minor) `tests/test_fsr4_tune.py:27`: The normal runner skips the expanded test on Windows even when spirv-val is installed, and the direct invocation ignores CXX unless --cxx is supplied. The driver also opens paths through narrow argv and streams, which can fail for a checkout or temp directory outside the Windows code page. Use tool availability to gate the test, honor CXX, and pass fixture and output paths through a Unicode-capable interface. 18. **L18** (minor): The checklist claims the full suite passed and the host code built on Linux. Testing reports a changed-file subset and a Windows build. Record the full suite and the Linux build with the supported compilers, or mark those checks pending. The three named baseline failures can stay listed. 19. **L19** (its part an edit can do): Log time to the first playable frame separately from background compilation and cache hits, and report the per-run frame-time percentiles and peak memory. 20. **L20** (its part an edit can do): Keep the measured shader and driver combinations on the new cold path while retaining the existing fallback on combinations awaiting coverage. 21. **L21** (minor) `docs/dev/reference/upscalers.md:26`: The cache paragraph says the layers and postpass are unrolled, although six layers stay rolled in the reported setup and eligibility also depends on the module, driver, and headroom. (more on the line) **For the author (2)** (a run, a measurement or a decision) - **L19** (minor): Repeat the comparison on the merge base and corrected head. The supplied Performance-preset run establishes a GPU-time gain on the earlier pair, while FPS overlaps and median and p99 frame times are missing. Include Auto's chosen quality preset and a heavy scene, paste the source log lines, and report cold and warm time to the first playable frame, peak RAM and VRAM, and cache size. The current cold total measures background jobs. - **L20** (minor): The default reaches RADV and newer Adrenalin models, while the reported runs cover one Windows RDNA 2 card. Finish the listed Linux RADV and Windows RDNA 4 runs, and cover FSR 4-capable Steam Deck configurations. Check cold commit and pacing, warm cache hits, and output parity on odd dimensions and during SDR/HDR or context changes. **Checks:** Still running: `CI / Website build and checks (pull_request)`, `PR description / Description follows the template (pull_request_target)`, `CI / Conventional Commit title (pull_request)`, `CI / Workflow lint (actionlint) (pull_request)`, `Guide screenshots / Guide images and local UI source review (pull_request)`, `Third-party parts / As their notes say (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven on the review head. The reported Windows RX 6700 XT comparison at afc4d1ad versus b79edcc7 shows 4.542 to 3.699 ms FSR 4 GPU time across three interleaved pairs with no overlap. It also reports 147.0 to 3.43 s of cold background builds and roughly 3 GB to under 60 MB peak commit. Mean FPS and 1% lows overlap, and one pair's 1% low fell from 25.84 to 20.81 FPS. Equal shader word counts after the rebase establish neither equal shader bytes nor equal driver behavior. **Other systems:** The rewrite runs through the optional FSR 4 runtime and the AMD-only tuning policy. NVIDIA, Intel, and other upscalers bypass it. FSR 4 Quality, native AA, HDR, frame generation with FSR 4 input, other Adrenalin models, RADV, and Steam Deck configurations that load FSR 4 still need coverage. The standalone HDR comparison reported exact output on the tested card. Cold jobs share the renderer's compute compilation gate, and the tested dedicated cache grew from about 60 to 208 KB. The diff leaves save, input, audio, and renderer API code alone. **Switches:** No setting or switch is added or removed. The existing RX_VK_FSR4_TUNE default is on for AMD and off elsewhere, with =0 selecting the vendor shaders. Its switch-table row covers the expanded path, but the wider default still needs affected Tier 1 coverage. The internal cold-build threshold falls from 8 GiB to 1 GiB. Only the reported RX 6700 XT setup supports the lower value so far. **Reviewed:** de6ab9689789 against f1f2dc5bd282: Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, the development standards, the full seven-file diff and commit, and the full text of spirv_unroll.h, vk_fsr4.cpp, fsr4_tune.h, upscalers.md, test_fsr4_tune.py, and postpass.hlsl. Traced the operand table, device policy, cache and close callers, and related test harnesses. Skimmed the generated SPIR-V blob and the supplied run reports and CI status. The checkout had no review-checklist file. Fixture regeneration and recorded shader bytes from the benchmark were unverified.; nothing run (a code review). **Checked and fine:** - The commit has an Assisted-by trailer and a Conventional Commit title. The HLSL fixture uses authored weights, and the diff contains no apparent game-derived material or vendor runtime. - The change stays on the FSR 4 topic and leaves third_party and the versioned renderer interface alone. The added fixture includes its DXC generation command. - The job captures the requested numeric lane count before moving Plain. A non-wave64 pass with no explicit request keeps a null subgroup-size chain. - Cache probing still precedes the cold-build headroom check. Bind and dispatch still remember which pipeline was actually bound if a worker publishes between them. - The scalar folds guard divide-by-zero, signed division overflow, and oversized shifts. Trip counts use widened arithmetic and reject the checked wrap cases. - The diff adds no downloads, external service calls, or build and CI script changes. **Testing:** Read-only review. git diff --check passed. The author reports a Windows build, fixture and cache checks, three interleaved in-game pairs, and standalone SDR/HDR parity with six SDR values differing by at most 2 ULP. CI was still running in the supplied status. No builds or tests were executed for this review. **Overlaps and merge order:** The prerequisite FSR 4 changes #2798 and #1752 are already in the base. No other overlap found in the supplied material or local history. </details> --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -24,3 +24,3 @@
the menu offers only the engines that can.
AMD FSR 4's layers are unrolled and built into a pipeline cache of their own, `cache/longshot_fsr4_pipelines.bin`
AMD FSR 4's layers and postpass are unrolled and built into a pipeline cache of their own, `cache/longshot_fsr4_pipelines.bin`
Member

L21 (minor): The cache paragraph says the layers and postpass are unrolled, although six layers stay rolled in the reported setup and eligibility also depends on the module, driver, and headroom. Say that eligible weight-table passes are rebuilt and cached. Label the shorter standalone compile times separately from the 0.33–0.69 s in-game times in the source notes.

**L21** (minor): The cache paragraph says the layers and postpass are unrolled, although six layers stay rolled in the reported setup and eligibility also depends on the module, driver, and headroom. Say that eligible weight-table passes are rebuilt and cached. Label the shorter standalone compile times separately from the 0.33–0.69 s in-game times in the source notes.
@ -135,0 +208,4 @@
composite[in[2]].assign(in.begin() + 3, in.end());
id_type[in[2]] = in[1];
last_global_const = k;
} else if (op == kConstantTrue || op == kConstantFalse) {
Member

L10: The parser checks instruction framing but the new scans assume opcode-specific operands exist. A one-word OpConstantTrue passes the framing check and TypeInfo::scan then accesses words 1 and 2. Driver module creation can defer inspection until pipeline creation. Validate the operand counts the rewrite relies on and fail back to the existing pipeline before indexing malformed input.

**L10**: The parser checks instruction framing but the new scans assume opcode-specific operands exist. A one-word OpConstantTrue passes the framing check and TypeInfo::scan then accesses words 1 and 2. Driver module creation can defer inspection until pipeline creation. Validate the operand counts the rewrite relies on and fail back to the existing pipeline before indexing malformed input.
@ -135,0 +245,4 @@
inline void insert_new_consts(Module& m, size_t after_idx, std::vector<Ins>& new_consts) {
if (new_consts.empty()) return;
m.ins.insert(m.ins.begin() + (ptrdiff_t)after_idx + 1, new_consts.begin(), new_consts.end());
Member

L4: New constants are inserted after the last recognized constant, which can precede the declaration of their type. For example, a signed int type declared after the last unsigned constant can first be used by an in-function bitcast of that constant. Folding creates a signed constant above its type declaration. Emit new constants after all their types and before the first function.

**L4**: New constants are inserted after the last recognized constant, which can precede the declaration of their type. For example, a signed int type declared after the last unsigned constant can first be used by an in-function bitcast of that constant. Folding creates a signed constant above its type declaration. Emit new constants after all their types and before the first function.
@ -135,0 +463,4 @@
}
if (op == kCompositeConstruct && in.size() >= 4) {
id_ty[in[2]] = in[1];
comp_elems[in[2]].assign(in.begin() + 3, in.end());
Member

L1: The composite tracking treats constructor operands as lanes, but SPIR-V vector constructors can mix vectors and scalars. In a four-lane construct from a two-lane vector followed by two scalars, extracting lane 1 can return the first scalar, which belongs to lane 2. The same assumption maps the wrong element after a store at line 804. Flatten vector operands by their actual lane count or refuse mixed constructors in both passes, and check the extracted value.

**L1**: The composite tracking treats constructor operands as lanes, but SPIR-V vector constructors can mix vectors and scalars. In a four-lane construct from a two-lane vector followed by two scalars, extracting lane 1 can return the first scalar, which belongs to lane 2. The same assumption maps the wrong element after a store at line 804. Flatten vector operands by their actual lane count or refuse mixed constructors in both passes, and check the extracted value.
@ -135,0 +888,4 @@
}
}
}
if (!forwarded) rebuilt.push_back(std::move(in));
Member

L3: Forwarding deletes the load before DCE can record its result as removed, while apply_aliases skips OpName and OpDecorate. A forwarded load outside the cloned loop that has an OpName therefore leaves a reference to an undefined result. Account for all annotation uses before deleting a result, remove debug names with the definition, and preserve or reject semantic annotations.

**L3**: Forwarding deletes the load before DCE can record its result as removed, while apply_aliases skips OpName and OpDecorate. A forwarded load outside the cloned loop that has an OpName therefore leaves a reference to an undefined result. Account for all annotation uses before deleting a result, remove debug names with the definition, and preserve or reject semantic annotations.
@ -135,0 +940,4 @@
}
std::unordered_set<uint32_t> dead_fvars;
for (uint32_t v : fvars) if (!live_fvars.count(v)) dead_fvars.insert(v);
Member

L6: The eight-round DCE limit can leave a surviving chain rooted at a deleted variable. A write-only local can have enough successive access chains that each round removes only the last surviving chain, even across the cleanup calls for a single-loop module. Use a dependency worklist or defer deletion of the root until its remaining references are gone.

**L6**: The eight-round DCE limit can leave a surviving chain rooted at a deleted variable. A write-only local can have enough successive access chains that each round removes only the last surviving chain, even across the cleanup calls for a single-loop module. Use a dependency worklist or defer deletion of the root until its remaining references are gone.
@ -135,0 +946,4 @@
bool changed = false;
for (Ins& in : m.ins) {
const uint32_t op = in[0] & 0xffff;
if (op == kVariable && in.size() >= 4 && in[3] == 7 && dead_fvars.count(in[2])) {
Member

L5: DCE can remove a Function variable while leaving a store that still uses it. The non-escape scan accepts a store with memory operands, but DCE only removes three-word stores. A write-only local with an Aligned store leaves an undefined pointer in the emitted shader. Exclude locals with qualified accesses from this elimination, and remove pointer definitions only after all their remaining users are gone.

**L5**: DCE can remove a Function variable while leaving a store that still uses it. The non-escape scan accepts a store with memory operands, but DCE only removes three-word stores. A write-only local with an Aligned store leaves an undefined pointer in the emitted shader. Exclude locals with qualified accesses from this elimination, and remove pointer definitions only after all their remaining users are gone.
@ -135,0 +1019,4 @@
} else if (op == kSwitch) {
has_merge_before_term[cur_lbl] = cur_has_merge;
pinned.insert(in[2]);
for (size_t j = 4; j < in.size(); j += 2) pinned.insert(in[j]);
Member

L7: Block merging reads every OpSwitch case as a 32-bit literal and label. With a 64-bit selector and two cases, it misses the first case target. If the previous block falls through to that target via an unconditional branch, merging can delete a label still referenced by the switch. Decode switch operands using the selector type in the merger and the ID walker, or decline transforms involving unsupported switches.

**L7**: Block merging reads every OpSwitch case as a 32-bit literal and label. With a 64-bit selector and two cases, it misses the first case target. If the previous block falls through to that target via an unconditional branch, merging can delete a label still referenced by the switch. Decode switch operands using the selector type in the merger and the ID walker, or decline transforms involving unsupported switches.
@ -176,0 +1222,4 @@
if (top_level && !cont_has_phi && !cont_targeted_by_sel && skip_blocks.empty() && t_lbl != f_lbl &&
(f_lbl == sm || t_lbl == sm)) {
const uint32_t cand_skip = (f_lbl == sm) ? t_lbl : f_lbl;
for (size_t j = k + 2; j + 1 < ci; j++) {
Member

L8: A continue that misses the narrow pattern is still cloned. For example, a selection arm that writes a value and then continues keeps an edge to the old continue target after the loop construct is removed. That edge is neither the selection's merge nor a structured loop exit anymore. Check every incoming edge to the continue block and refuse the loop unless the replacement preserves structured control flow.

**L8**: A continue that misses the narrow pattern is still cloned. For example, a selection arm that writes a value and then continues keeps an edge to the old continue target after the loop construct is removed. That edge is neither the selection's merge nor a structured loop exit anymore. Check every incoming edge to the continue block and refuse the loop unless the replacement preserves structured control flow.
@ -178,1 +1252,4 @@
if (k >= hi && k < mi) continue;
Ins tmp = I[k];
const uint32_t op = tmp[0] & 0xffff;
if (op == kName || op == kDecorate) continue;
Member

L2: Unrolling now accepts decorated loop results, then drops their OpDecorate instructions without cloning them. An OpFMul carrying NoContraction loses that restriction in every copy. The same metadata needs consideration when folding replaces a decorated result. Preserve semantic decorations for the appropriate new IDs or leave those operations and loops alone.

**L2**: Unrolling now accepts decorated loop results, then drops their OpDecorate instructions without cloning them. An OpFMul carrying NoContraction loses that restriction in every copy. The same metadata needs consideration when folding replaces a decorated result. Preserve semantic decorations for the appropriate new IDs or leave those operations and loops alone.
@ -194,3 +1275,2 @@
}
if (!ok || (mi + 1 < I.size() && (I[mi + 1][0] & 0xffff) == kPhi)) { refused.insert(key); continue; }
// the counter's values as constants (new ones after the last constant)
if (!ok || (mi + 1 < I.size() && (I[mi + 1][0] & 0xffff) == kPhi)) {
Member

L9: The merge-block check inspects one instruction immediately after OpLabel. A debug line instruction before an OpPhi hides the phi, which can still list the old header as its incoming predecessor after that edge is replaced. Skip debug line instructions when checking for phis or check the merge block's predecessors explicitly.

**L9**: The merge-block check inspects one instruction immediately after OpLabel. A debug line instruction before an OpPhi hides the phi, which can still list the old header as its incoming predecessor after that edge is replaced. Skip debug line instructions when checking for phis or check the merge block's predecessors explicitly.
@ -298,2 +298,2 @@
constexpr size_t kUnrollWords = 120000; // (a layer unrolled to more than this is left rolled)
constexpr uint64_t kBuildHeadroom = 8ull << 30; // (memory to spare before a build starts)
constexpr size_t kUnrollWords = 120000; // (a pass still above this after folding is left rolled)
constexpr uint64_t kBuildHeadroom = 1ull << 30; // (memory to spare before a cold build starts; folded builds take <60 MB)
Member

L11: The 1 GiB guard covers every admitted cold compile, while the size limit still admits up to 120,000 words. A vendor shader whose scratch operations survive folding can reach the roughly 107,000-word size that previously needed about 3 GB on the tested driver. A machine with 1–3 GiB free now attempts that compile under pressure. Keep the conservative guard for unverified outputs and drivers, or limit the low threshold to a measured shader and driver range. Keep the cache lookup first.

**L11**: The 1 GiB guard covers every admitted cold compile, while the size limit still admits up to 120,000 words. A vendor shader whose scratch operations survive folding can reach the roughly 107,000-word size that previously needed about 3 GB on the tested driver. A machine with 1–3 GiB free now attempts that compile under pressure. Keep the conservative guard for unverified outputs and drivers, or limit the low threshold to a measured shader and driver range. Keep the cache lookup first.
@ -673,15 +673,17 @@ void build_unrolled(VkPipeline original, std::shared_ptr<const std::vector<uint3
VkShaderModule module = VK_NULL_HANDLE;
if (real_csm(dev.device, &mci, nullptr, &module) == VK_SUCCESS) {
Member

L14: The extra background job reads plain driver function pointers that device_proc rewrites. If a resize or HDR change creates a context and AMD asks for vkCreateShaderModule or vkDestroyShaderModule while a postpass job uses it, the reads race with the writes even when Vulkan returns the same address. Give the worker an immutable dispatch table initialized before the SDK hooks are exposed.

**L14**: The extra background job reads plain driver function pointers that device_proc rewrites. If a resize or HDR change creates a context and AMD asks for vkCreateShaderModule or vkDestroyShaderModule while a postpass job uses it, the reads race with the writes even when Vulkan returns the same address. Give the worker an immutable dispatch table initialized before the SDK hooks are exposed.
@ -816,8 +821,9 @@ VKAPI_ATTR VkResult VKAPI_CALL create_compute_pipelines(VkDevice d, VkPipelineCa
pending.insert(p[i]);
Member

L13: The new postpass job inherits cancellation keyed only by the raw VkPipeline handle. If a context is destroyed with a job queued and the driver reuses that handle, the newer job can run first and consume the old job's cancellation. The old job can then publish its shader for the new context. Carry a per-creation job token and check it against the live token before publishing.

**L13**: The new postpass job inherits cancellation keyed only by the raw VkPipeline handle. If a context is destroyed with a job queued and the driver reuses that handle, the newer job can run first and consume the old job's cancellation. The old job can then publish its shader for the new context. Carry a per-creation job token and check it against the live token before publishing.
@ -819,2 +824,3 @@
const uint32_t req_lanes = (kind[i] & 1) ? 64u : orig_lanes;
{ std::lock_guard jl(jobs().mu); jobs().running++; }
std::thread(build_unrolled, p[i], code[i], entry[i], job, layout, std::move(sets)).detach(); // (counted: fsr4_close)
std::thread(build_unrolled, p[i], code[i], entry[i], job, req_lanes, layout, std::move(sets)).detach(); // (counted: fsr4_close)
Member

L12: The expanded job path counts a worker and allocates its Vulkan layouts before constructing the thread. If thread creation fails under resource pressure, the exception escapes the callback and the count, pending entry, and layouts have no rollback. Worker allocation failures in the expanded rewrite can also escape the thread and terminate the process. Use an owned worker queue or handle both failure paths with cleanup and keep the existing pipeline.

**L12**: The expanded job path counts a worker and allocates its Vulkan layouts before constructing the thread. If thread creation fails under resource pressure, the exception escapes the callback and the count, pending entry, and layouts have no rollback. Worker allocation failures in the expanded rewrite can also escape the thread and terminate the process. Use an owned worker queue or handle both failure paths with cleanup and keep the existing pipeline.
@ -193,9 +201,15 @@ def source_problems():
problems.append("an unroll thread is started without being counted (fsr4_close waits for the count)")
if "closing" not in pipes:
problems.append("create_compute_pipelines starts unroll jobs after the window closed")
if "!(kind[i] & 1) || !(kind[i] & 2)" in pipes:
Member

L16 (minor): The subgroup checks match specific source strings. Putting the wave64 gate back elsewhere, or passing 64 to the worker while leaving the expected assignment in place, still passes. Use a fake pipeline creation callback to check that the postpass is queued and arrives with its requested 32 lanes, that a missing requirement stays absent, and that a wave64 layer still requests 64.

**L16** (minor): The subgroup checks match specific source strings. Putting the wave64 gate back elsewhere, or passing 64 to the worker while leaving the expected assignment in place, still passes. Use a fake pipeline creation callback to check that the postpass is queued and arrives with its requested 32 lanes, that a missing requirement stays absent, and that a wave64 layer still requests 64.
@ -283,0 +316,4 @@
problems.append("postpass.spv's 2 loops (OpINotEqual, multi-phi, continue) were not all unrolled deterministically: "
"done %s, before %s, left %s, det %s" % (pdone, pbefore, pleft, pdet))
else:
valid(t / "postpass_unrolled.spv", "the unrolled postpass")
Member

L15: Validation and instruction counts would pass if a fold selected the wrong weight or returned a stale accumulator. Add a game-free result check for the rolled and rewritten shaders with known inputs, both continue outcomes, and distinct accumulator values. Use disjoint input and output locations or a single active invocation, since the current HLSL lets neighboring invocations read and write overlapping scratch words.

**L15**: Validation and instruction counts would pass if a fold selected the wrong weight or returned a stale accumulator. Add a game-free result check for the rolled and rewritten shaders with known inputs, both continue outcomes, and distinct accumulator values. Use disjoint input and output locations or a single active invocation, since the current HLSL lets neighboring invocations read and write overlapping scratch words.
madebyjordan left a comment

Not ready to merge. This is a comment because the PR is my own. I read the code at de6ab968 and ran nothing.

New and blocking

  1. A dead-store removal can delete the wrong instruction (gpu/vk/spirv_unroll.h:800). forward_function_allocas records the store's position, then may add OpBitcasts before the store itself (line 828). The recorded position then points at the first bitcast. If the same location is stored again in that block, that bitcast is deleted and the old store stays. A load already forwarded to that bitcast now names an id that no longer exists, and that invalid shader goes to the driver, since nothing validates it at run time. Example: store asuint(float2(a, b)) to p, read p[0], store to p again. Fix: record the position after the bitcasts are added, and add this case to the test.

New and minor

  1. kISub is 129, which is OpFAdd; OpISub is 130 (gpu/vk/spirv_unroll.h:130). The picture isn't affected, because the fold requires an integer result type, but integer subtraction is never folded. Correcting it means replacing the literal case 130: in is_pure_op with case 129:, or the switch has a duplicate case and float adds stop being removable. It can change the emitted shaders, so it belongs before the final measurement.

BeanBot's points, checked against the code

  • L1, L2, L3, L4, L5 and L8 are real at this head and should block. L1 can silently give a wrong value for a constructor as ordinary as float4(v.xy, a, b).
  • L2 is a guard this PR removed: main refuses a loop whose results are decorated. It may also explain the 6 differing SDR postpass values, though I haven't shown that. If the fix is to refuse those loops, check that the postpass and passes 4, 5 and 10 still unroll, because a refused loop leaves its pass rolled and loses the gain. Copying the decorations onto each clone would keep it.
  • L6, L7, L9 and L10 are real but need shapes DXC doesn't normally emit. The guards are cheap.
  • L12, L13 and L14 exist on main in the same form. This PR adds one more job through them, so they don't need to block it.
  • L11 and L15 stand. The fixture proves the output is valid, not that its values are right.

Merge state

  • It merges cleanly into current main (40bfceb0).
  • The two failing checks (Website, Guide screenshots) fail the same way on #1927, which has the same base, and pass on #2013. This PR doesn't touch the website, so a rebase should clear them.
  • It conflicts in gpu/vk/vk_fsr4.cpp with #1886 and #1989. Whichever lands second needs a rebase.

Checked and fine: the lanes[i].pNext guard does nothing for the postpass, but has_plain already limits the job to a chain holding at most a lane count, so no structure is lost.

**Not ready to merge.** This is a comment because the PR is my own. I read the code at `de6ab968` and ran nothing. **New and blocking** 1. **A dead-store removal can delete the wrong instruction** (`gpu/vk/spirv_unroll.h:800`). `forward_function_allocas` records the store's position, then may add `OpBitcast`s before the store itself (line 828). The recorded position then points at the first bitcast. If the same location is stored again in that block, that bitcast is deleted and the old store stays. A load already forwarded to that bitcast now names an id that no longer exists, and that invalid shader goes to the driver, since nothing validates it at run time. Example: store `asuint(float2(a, b))` to `p`, read `p[0]`, store to `p` again. Fix: record the position after the bitcasts are added, and add this case to the test. **New and minor** 2. **`kISub` is 129, which is `OpFAdd`; `OpISub` is 130** (`gpu/vk/spirv_unroll.h:130`). The picture isn't affected, because the fold requires an integer result type, but integer subtraction is never folded. Correcting it means replacing the literal `case 130:` in `is_pure_op` with `case 129:`, or the switch has a duplicate case and float adds stop being removable. It can change the emitted shaders, so it belongs before the final measurement. **BeanBot's points, checked against the code** - **L1, L2, L3, L4, L5 and L8 are real at this head and should block.** L1 can silently give a wrong value for a constructor as ordinary as `float4(v.xy, a, b)`. - **L2 is a guard this PR removed:** main refuses a loop whose results are decorated. It may also explain the 6 differing SDR postpass values, though I haven't shown that. If the fix is to refuse those loops, check that the postpass and passes 4, 5 and 10 still unroll, because a refused loop leaves its pass rolled and loses the gain. Copying the decorations onto each clone would keep it. - **L6, L7, L9 and L10 are real** but need shapes DXC doesn't normally emit. The guards are cheap. - **L12, L13 and L14 exist on main in the same form.** This PR adds one more job through them, so they don't need to block it. - **L11 and L15 stand.** The fixture proves the output is valid, not that its values are right. **Merge state** - It merges cleanly into current main (`40bfceb0`). - The two failing checks (Website, Guide screenshots) fail the same way on https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1927, which has the same base, and pass on https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2013. This PR doesn't touch the website, so a rebase should clear them. - It conflicts in `gpu/vk/vk_fsr4.cpp` with https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1886 and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1989. Whichever lands second needs a rebase. **Checked and fine:** the `lanes[i].pNext` guard does nothing for the postpass, but `has_plain` already limits the job to a chain holding at most a lane count, so no structure is lost.
@ -117,0 +127,4 @@
kFunction = 54, kFunctionEnd = 56, kFunctionCall = 57,
kVariable = 59, kLoad = 61, kStore = 62, kAccessChain = 65, kDecorate = 71,
kVectorShuffle = 79, kCompositeConstruct = 80, kCompositeExtract = 81, kCompositeInsert = 82, kCopyObject = 83,
kBitcast = 124, kIAdd = 128, kISub = 129, kIMul = 132, kUDiv = 134, kSDiv = 135, kUMod = 137,
Author
Member

129 is OpFAdd; OpISub is 130. Correcting it also means changing the literal case 130 in is_pure_op to 129.

129 is OpFAdd; OpISub is 130. Correcting it also means changing the literal case 130 in is_pure_op to 129.
@ -135,0 +797,4 @@
++it;
}
}
sm[loc.path] = rebuilt.size();
Author
Member

The position recorded here goes stale when the bitcasts below (line 828) are added before the store, so a later overwrite deletes a bitcast that a forwarded load may use. Record it after they are added.

The position recorded here goes stale when the bitcasts below (line 828) are added before the store, so a later overwrite deletes a bitcast that a forwarded load may use. Record it after they are added.
fix(vk): address review findings in FSR 4 unroller, worker lifecycle, and tests
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 24s
CI / Workflow lint (actionlint) (pull_request) Successful in 45s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 48s
Third-party parts / As their notes say (pull_request) Successful in 53s
CI / Website build and checks (pull_request) Failing after 25s
PR description / Description follows the template (pull_request_target) Has been cancelled
c8371016fd
Assisted-by: Gemini (Antigravity)
Author
Member

Addressed all code, test, and doc findings from review #2050 (L1–L18, L21, and the code-side guards of L19–L20):

gpu/vk/spirv_unroll.h

  • L1: Added is_flat_construct() so vector OpCompositeConstruct tracking in both fold_constants and forward_function_allocas verifies in.size() - 3 == count and scalar element types (rejecting mixed vector+scalar packing).
  • L2: TypeInfo::scan records all IDs targeted by OpDecorate; unroll_one refuses loops whose made set contains a decorated ID, fold_constants refuses to alias decorated results, and forward_function_allocas refuses to forward decorated loads.
  • L3: forward_function_allocas tracks alias-forwarded loads and calls strip_annotations(m, removed_loads, false) to strip their OpNames without touching OpDecorate.
  • L4: TypeInfo::scan records first_func; insert_new_consts and unroll_one insert new OpConstants immediately before the first OpFunction (after all OpType* and prior constants), and fold_constants scans from first_func.
  • L5: find_non_escaping_fvars requires plain 4-word OpLoad and plain 3-word OpStore, excluding any Function variable with memory-operand-qualified accesses from forwarding and DCE.
  • L6: dce iterates to exact fixed point and only deletes a dead Function OpVariable once !used.count(in[2]) (after every store and chained OpAccessChain referencing it has been removed).
  • L7: merge_trivial_blocks refuses modules containing any OpSwitch whose selector is not a known 32-bit integer or whose operand count is odd; unroll_one refuses loops containing OpSwitch.
  • L8: unroll_one tracks open_sel_merges and refuses any branch/conditional branch targeting cont from inside a non-retargeted selection.
  • L9: unroll_one scans the entire merge block [mi + 1 .. terminator/next_label) for OpPhi so OpLine/OpNoLine cannot hide a merge-block phi.
  • L10: Added operand-count bounds checks across TypeInfo::scan, for_each_id (M Aligned / L LoopControl), merge_trivial_blocks, and unroll_one.

gpu/vk/vk_fsr4.cpp

  • L11 & L20 (code guard): Restored kBuildHeadroom = 8 GiB for larger/unverified shaders (> kCompactUnrollWords = 60,000) and gated the 1 GiB threshold (kCompactHeadroom) strictly to compact folded shaders (<= 60,000 words; all 7 measured FSR 4.1.2 passes fold to 27–45K words and peak <60 MB).
  • L12: Wrapped std::thread(build_unrolled, ...).detach() in try/catch with full rollback of jobs().running, pending_token, and copied Vulkan layouts (passing sets by value so catch always owns every handle), and wrapped build_unrolled in try/catch with an RAII Cleanup guard so allocation failures never terminate the process or leak handles.
  • L13: Replaced pending/cancelled handle sets with pending_token keyed by a monotonic per-creation uint64_t token (next_job_token), so a destroyed and driver-reused VkPipeline handle never publishes a stale build.
  • L14: Added an immutable worker_fn dispatch table initialized once in prepare_device() before device_proc is exposed; build_unrolled uses worker_fn.* exclusively.

Tests & Docs

  • L15: Updated tests/fsr4_tune/postpass.hlsl & postpass.spv to read from a separate InBuffer and write disjoint ScratchBuffer words; added a Python SPIR-V interpreter in tests/test_fsr4_tune.py verifying bit-exact output parity across invocations (including both continue outcomes) for rolled, tail-rewritten, and unrolled+folded layer.spv and postpass.spv, plus synthetic spirv-val + semantic regression cases for L1–L5 and L8–L10.
  • L16: Replaced brittle subgroup source-string checks in tests/test_fsr4_tune.py with compiled behavioral tests in tests/test_fsr4_bind_dispatch.py exercising the real create_compute_pipelines, build_unrolled, destroy_pipeline, cmd_bind_pipeline, and cmd_dispatch hooks against recording fake callbacks (wave64 layer -> 64 lanes, postpass -> 32 lanes and null pNext with ALLOW_VARYING preserved, two-tier headroom, worker_fn isolation, and handle-reuse token cancellation).
  • L17: Removed RUN_ALL_SKIP on Windows from tests/test_fsr4_tune.py (now gated automatically by {spirv_val}), honored CXX env var, and switched the test driver to binary stdin/stdout so Python's Path handles all Unicode paths natively.
  • L18, L19, L20, L21: Updated gpu/vk/fsr4_tune.h, gpu/vk/vk_fsr4.cpp, docs/dev/reference/upscalers.md, and the PR description/checklist to distinguish standalone vs in-game compile times, report median and p99 frame times from the recorded interleaved A/B runs, and list the Linux build/full suite and remaining hardware/scenario coverage explicitly under Still to test.

Re-verified on updated head

  • tests/run_all.py fsr4 (Windows, no --no-skip): 3/3 passed, 0 skipped (test_fsr4_tune.py, test_fsr4_own_cache.py, test_fsr4_bind_dispatch.py).
  • All 13 real FSR 4.1.2 SPIR-V shaders: identical folded word counts (27311–44769), det=1, 13/13 pass spirv-val --target-env vulkan1.3.
  • LONGSHOT_FSR=1 python -I scripts/dev.py vk (Windows llvm-mingw): 0 errors, symbols checked.
  • Standalone RX 6700 XT SDR + HDR GPU parity probe re-run on the updated head.
Addressed all code, test, and doc findings from review #2050 (`L1`–`L18`, `L21`, and the code-side guards of `L19`–`L20`): ### `gpu/vk/spirv_unroll.h` - **L1:** Added `is_flat_construct()` so vector `OpCompositeConstruct` tracking in both `fold_constants` and `forward_function_allocas` verifies `in.size() - 3 == count` and scalar element types (rejecting mixed vector+scalar packing). - **L2:** `TypeInfo::scan` records all IDs targeted by `OpDecorate`; `unroll_one` refuses loops whose `made` set contains a decorated ID, `fold_constants` refuses to alias decorated results, and `forward_function_allocas` refuses to forward decorated loads. - **L3:** `forward_function_allocas` tracks alias-forwarded loads and calls `strip_annotations(m, removed_loads, false)` to strip their `OpName`s without touching `OpDecorate`. - **L4:** `TypeInfo::scan` records `first_func`; `insert_new_consts` and `unroll_one` insert new `OpConstant`s immediately before the first `OpFunction` (after all `OpType*` and prior constants), and `fold_constants` scans from `first_func`. - **L5:** `find_non_escaping_fvars` requires plain 4-word `OpLoad` and plain 3-word `OpStore`, excluding any Function variable with memory-operand-qualified accesses from forwarding and DCE. - **L6:** `dce` iterates to exact fixed point and only deletes a dead Function `OpVariable` once `!used.count(in[2])` (after every store and chained `OpAccessChain` referencing it has been removed). - **L7:** `merge_trivial_blocks` refuses modules containing any `OpSwitch` whose selector is not a known 32-bit integer or whose operand count is odd; `unroll_one` refuses loops containing `OpSwitch`. - **L8:** `unroll_one` tracks `open_sel_merges` and refuses any branch/conditional branch targeting `cont` from inside a non-retargeted selection. - **L9:** `unroll_one` scans the entire merge block `[mi + 1 .. terminator/next_label)` for `OpPhi` so `OpLine`/`OpNoLine` cannot hide a merge-block phi. - **L10:** Added operand-count bounds checks across `TypeInfo::scan`, `for_each_id` (`M` Aligned / `L` LoopControl), `merge_trivial_blocks`, and `unroll_one`. ### `gpu/vk/vk_fsr4.cpp` - **L11 & L20 (code guard):** Restored `kBuildHeadroom = 8 GiB` for larger/unverified shaders (`> kCompactUnrollWords = 60,000`) and gated the `1 GiB` threshold (`kCompactHeadroom`) strictly to compact folded shaders (`<= 60,000` words; all 7 measured FSR 4.1.2 passes fold to 27–45K words and peak <60 MB). - **L12:** Wrapped `std::thread(build_unrolled, ...).detach()` in `try/catch` with full rollback of `jobs().running`, `pending_token`, and copied Vulkan layouts (passing `sets` by value so `catch` always owns every handle), and wrapped `build_unrolled` in `try/catch` with an RAII `Cleanup` guard so allocation failures never terminate the process or leak handles. - **L13:** Replaced `pending`/`cancelled` handle sets with `pending_token` keyed by a monotonic per-creation `uint64_t` token (`next_job_token`), so a destroyed and driver-reused `VkPipeline` handle never publishes a stale build. - **L14:** Added an immutable `worker_fn` dispatch table initialized once in `prepare_device()` before `device_proc` is exposed; `build_unrolled` uses `worker_fn.*` exclusively. ### Tests & Docs - **L15:** Updated `tests/fsr4_tune/postpass.hlsl` & `postpass.spv` to read from a separate `InBuffer` and write disjoint `ScratchBuffer` words; added a Python SPIR-V interpreter in `tests/test_fsr4_tune.py` verifying bit-exact output parity across invocations (including both `continue` outcomes) for rolled, tail-rewritten, and unrolled+folded `layer.spv` and `postpass.spv`, plus synthetic `spirv-val` + semantic regression cases for `L1`–`L5` and `L8`–`L10`. - **L16:** Replaced brittle subgroup source-string checks in `tests/test_fsr4_tune.py` with compiled behavioral tests in `tests/test_fsr4_bind_dispatch.py` exercising the real `create_compute_pipelines`, `build_unrolled`, `destroy_pipeline`, `cmd_bind_pipeline`, and `cmd_dispatch` hooks against recording fake callbacks (wave64 layer -> 64 lanes, postpass -> 32 lanes and null `pNext` with `ALLOW_VARYING` preserved, two-tier headroom, `worker_fn` isolation, and handle-reuse token cancellation). - **L17:** Removed `RUN_ALL_SKIP` on Windows from `tests/test_fsr4_tune.py` (now gated automatically by `{spirv_val}`), honored `CXX` env var, and switched the test driver to binary `stdin`/`stdout` so Python's `Path` handles all Unicode paths natively. - **L18, L19, L20, L21:** Updated `gpu/vk/fsr4_tune.h`, `gpu/vk/vk_fsr4.cpp`, `docs/dev/reference/upscalers.md`, and the PR description/checklist to distinguish standalone vs in-game compile times, report median and p99 frame times from the recorded interleaved A/B runs, and list the Linux build/full suite and remaining hardware/scenario coverage explicitly under **Still to test**. ### Re-verified on updated head - `tests/run_all.py fsr4` (Windows, no `--no-skip`): **3/3 passed, 0 skipped** (`test_fsr4_tune.py`, `test_fsr4_own_cache.py`, `test_fsr4_bind_dispatch.py`). - All 13 real FSR 4.1.2 SPIR-V shaders: identical folded word counts (`27311–44769`), `det=1`, 13/13 pass `spirv-val --target-env vulkan1.3`. - `LONGSHOT_FSR=1 python -I scripts/dev.py vk` (Windows llvm-mingw): 0 errors, symbols checked. - Standalone RX 6700 XT SDR + HDR GPU parity probe re-run on the updated head.
Owner
@review
Member

The ChatGPT usage limit is reached (it resets Nov 25th, 2026 1:04 AM), so this review is paused. It runs by itself once the limit lifts (tried again every 30 minutes); nothing needs asking again.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

The ChatGPT usage limit is reached (it resets Nov 25th, 2026 1:04 AM), so this review is paused. It runs by itself once the limit lifts (tried again every 30 minutes); nothing needs asking again. --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
BeanBot requested changes 2026-11-21 06:59:30 +00:00
Dismissed
BeanBot left a comment

Recommendation: Request changes. The reduced cold-build memory guard still applies to unverified compact shaders and drivers, so it does not yet provide the conservative fallback requested in L11. The corrected-head performance comparison and hardware coverage also remain incomplete.

The change folds and unrolls eligible FSR 4 shaders, including the postpass, and adds result-parity and worker-lifecycle tests. The measured earlier build reduced FSR 4 GPU time and background compilation time on one Windows AMD GPU; the broader driver and memory costs remain unverified.

@fix will do (5)

  1. L11 gpu/vk/vk_fsr4.cpp:735: The 1 GiB threshold still admits every shader at or below 60,000 words on every driver. An unverified compact shader or driver can therefore compile under memory pressure without the requested conservative guard. Restrict the lower threshold to the measured shader and driver range, or retain the conservative threshold for unverified combinations; keep the cache lookup first.
  2. L18 (minor): The description records the missing Linux build and full suite, but leaves their checklist claims checked. Mark those checks pending until the runs are recorded.
  3. L19 (its part an edit can do): Log first-playable-frame time separately from background compilation and cache hits, and capture peak memory.
  4. L20 (its part an edit can do): Keep the measured shader and driver combinations on the new cold path while retaining the existing fallback on combinations awaiting coverage.
  5. L22: The check Guide screenshots / Guide images and local UI source review (pull_request) fails on this head and passes on the base branch: Failing after 48s.

For the author (2) (a run, a measurement or a decision)

  • L19 (minor): Repeat the in-game comparison on the merge base and corrected head, including Auto and a heavy scene, source log lines, cold and warm time to first playable frame, and peak RAM and VRAM.
  • L20 (minor): The default reaches RADV and newer Adrenalin models, while the reported runs cover one Windows RDNA 2 card. Finish the listed Linux RADV and Windows RDNA 4 runs, and cover FSR 4-capable Steam Deck configurations. Check cold commit and pacing, warm cache hits, and output parity on odd dimensions and during SDR/HDR or context changes.

Since the last review (on de6ab96897)
Resolved: L1 (The composite tracking treats constructor operands as lanes, but SPIR-V vector constructor…); L2 (Unrolling now accepts decorated loop results, then drops their OpDecorate instructions wit…); L3 (Forwarding deletes the load before DCE can record its result as removed, while apply_alias…); L4 (New constants are inserted after the last recognized constant, which can precede the decla…); L5 (DCE can remove a Function variable while leaving a store that still uses it. The non-escap…); L6 (The eight-round DCE limit can leave a surviving chain rooted at a deleted variable. A writ…); L7 (Block merging reads every OpSwitch case as a 32-bit literal and label. With a 64-bit selec…); L8 (A continue that misses the narrow pattern is still cloned. For example, a selection arm th…); L9 (The merge-block check inspects one instruction immediately after OpLabel. A debug line ins…); L10 (The parser checks instruction framing but the new scans assume opcode-specific operands ex…); L12 (The expanded job path counts a worker and allocates its Vulkan layouts before constructing…); L13 (The new postpass job inherits cancellation keyed only by the raw VkPipeline handle. If a c…); L14 (The extra background job reads plain driver function pointers that device_proc rewrites. I…); L15 (Validation and instruction counts would pass if a fold selected the wrong weight or return…); L16 (The subgroup checks match specific source strings. Putting the wave64 gate back elsewhere,…); L17 (The normal runner skips the expanded test on Windows even when spirv-val is installed, and…); L21 (The cache paragraph says the layers and postpass are unrolled, although six layers stay ro…)
Still open: L11 (The 1 GiB threshold still admits every shader at or below 60,000 words on every driver. An…); L18 (The description records the missing Linux build and full suite, but leaves their checklist…); L19 (Repeat the in-game comparison on the merge base and corrected head, including Auto and a h…); L20 (The default reaches RADV and newer Adrenalin models, while the reported runs cover one Win…)
New: L22 (The check Guide screenshots / Guide images and local UI source review (pull_request) fai…)

Checks: Still running: CI / Website build and checks (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Unproven on the corrected head and merge base. The earlier Windows RX 6700 XT comparison reports median FSR 4 dispatch time falling from 4.542 to 3.699 ms across three interleaved pairs, and cold background builds falling from 147.0 to 3.43 seconds. The corrected head has standalone parity results, but no repeated in-game comparison against the stated merge base.

Other systems: The default also reaches Linux RADV, newer AMD drivers and FSR 4-capable Steam Deck configurations; their cold memory, pacing, cache and visual results remain outstanding. The reported Windows test covers one RDNA 2 GPU and SDR/HDR standalone parity.

Switches: No switch added or removed. Existing RX_VK_FSR4_TUNE=0 disables tuning. The default tuning path now includes the postpass and uses a 1 GiB cold-build guard for outputs at or below 60,000 words; its safety on unverified drivers is not established.

Reviewed: c8371016fd against f1f2dc5bd2: Read AGENTS.md, CONTRIBUTING.md and the pull request template; inspected the changes since de6ab968 and relevant sections of spirv_unroll.h, vk_fsr4.cpp, tests and documentation. The changed code and tests were not read in full. The binary fixture was not decoded. The referenced Tooling checkout and docs/review-checklist.md were absent.; nothing run (a code review).

Checked and fine:

  • Cache lookup precedes the cold-build headroom check.
  • The documentation now qualifies which passes are eligible for unrolling.
  • Generation tokens prevent an old worker from publishing against a reused pipeline handle.

Testing: No code or tests were run for this review. The author reports Windows builds, game-free checks and standalone SDR/HDR parity; Linux and additional hardware runs are pending. Guide screenshots fails on this head, and the Website check is still running.

Overlaps and merge order: The earlier review reports conflicts with Longshot #1886 and #1989 in gpu/vk/vk_fsr4.cpp; whichever merges second needs a rebase. Current overlap status was not independently checked.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The reduced cold-build memory guard still applies to unverified compact shaders and drivers, so it does not yet provide the conservative fallback requested in L11. The corrected-head performance comparison and hardware coverage also remain incomplete. The change folds and unrolls eligible FSR 4 shaders, including the postpass, and adds result-parity and worker-lifecycle tests. The measured earlier build reduced FSR 4 GPU time and background compilation time on one Windows AMD GPU; the broader driver and memory costs remain unverified. **`@fix` will do (5)** 1. **L11** `gpu/vk/vk_fsr4.cpp:735`: The 1 GiB threshold still admits every shader at or below 60,000 words on every driver. An unverified compact shader or driver can therefore compile under memory pressure without the requested conservative guard. Restrict the lower threshold to the measured shader and driver range, or retain the conservative threshold for unverified combinations; keep the cache lookup first. 2. **L18** (minor): The description records the missing Linux build and full suite, but leaves their checklist claims checked. Mark those checks pending until the runs are recorded. 3. **L19** (its part an edit can do): Log first-playable-frame time separately from background compilation and cache hits, and capture peak memory. 4. **L20** (its part an edit can do): Keep the measured shader and driver combinations on the new cold path while retaining the existing fallback on combinations awaiting coverage. 5. **L22**: The check `Guide screenshots / Guide images and local UI source review (pull_request)` fails on this head and passes on the base branch: Failing after 48s. **For the author (2)** (a run, a measurement or a decision) - **L19** (minor): Repeat the in-game comparison on the merge base and corrected head, including Auto and a heavy scene, source log lines, cold and warm time to first playable frame, and peak RAM and VRAM. - **L20** (minor): The default reaches RADV and newer Adrenalin models, while the reported runs cover one Windows RDNA 2 card. Finish the listed Linux RADV and Windows RDNA 4 runs, and cover FSR 4-capable Steam Deck configurations. Check cold commit and pacing, warm cache hits, and output parity on odd dimensions and during SDR/HDR or context changes. **Since the last review** (on de6ab9689789) Resolved: L1 (The composite tracking treats constructor operands as lanes, but SPIR-V vector constructor…); L2 (Unrolling now accepts decorated loop results, then drops their OpDecorate instructions wit…); L3 (Forwarding deletes the load before DCE can record its result as removed, while apply_alias…); L4 (New constants are inserted after the last recognized constant, which can precede the decla…); L5 (DCE can remove a Function variable while leaving a store that still uses it. The non-escap…); L6 (The eight-round DCE limit can leave a surviving chain rooted at a deleted variable. A writ…); L7 (Block merging reads every OpSwitch case as a 32-bit literal and label. With a 64-bit selec…); L8 (A continue that misses the narrow pattern is still cloned. For example, a selection arm th…); L9 (The merge-block check inspects one instruction immediately after OpLabel. A debug line ins…); L10 (The parser checks instruction framing but the new scans assume opcode-specific operands ex…); L12 (The expanded job path counts a worker and allocates its Vulkan layouts before constructing…); L13 (The new postpass job inherits cancellation keyed only by the raw VkPipeline handle. If a c…); L14 (The extra background job reads plain driver function pointers that device_proc rewrites. I…); L15 (Validation and instruction counts would pass if a fold selected the wrong weight or return…); L16 (The subgroup checks match specific source strings. Putting the wave64 gate back elsewhere,…); L17 (The normal runner skips the expanded test on Windows even when spirv-val is installed, and…); L21 (The cache paragraph says the layers and postpass are unrolled, although six layers stay ro…) Still open: L11 (The 1 GiB threshold still admits every shader at or below 60,000 words on every driver. An…); L18 (The description records the missing Linux build and full suite, but leaves their checklist…); L19 (Repeat the in-game comparison on the merge base and corrected head, including Auto and a h…); L20 (The default reaches RADV and newer Adrenalin models, while the reported runs cover one Win…) New: L22 (The check `Guide screenshots / Guide images and local UI source review (pull_request)` fai…) **Checks:** Still running: `CI / Website build and checks (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven on the corrected head and merge base. The earlier Windows RX 6700 XT comparison reports median FSR 4 dispatch time falling from 4.542 to 3.699 ms across three interleaved pairs, and cold background builds falling from 147.0 to 3.43 seconds. The corrected head has standalone parity results, but no repeated in-game comparison against the stated merge base. **Other systems:** The default also reaches Linux RADV, newer AMD drivers and FSR 4-capable Steam Deck configurations; their cold memory, pacing, cache and visual results remain outstanding. The reported Windows test covers one RDNA 2 GPU and SDR/HDR standalone parity. **Switches:** No switch added or removed. Existing RX_VK_FSR4_TUNE=0 disables tuning. The default tuning path now includes the postpass and uses a 1 GiB cold-build guard for outputs at or below 60,000 words; its safety on unverified drivers is not established. **Reviewed:** c8371016fd71 against f1f2dc5bd282: Read AGENTS.md, CONTRIBUTING.md and the pull request template; inspected the changes since de6ab968 and relevant sections of spirv_unroll.h, vk_fsr4.cpp, tests and documentation. The changed code and tests were not read in full. The binary fixture was not decoded. The referenced Tooling checkout and docs/review-checklist.md were absent.; nothing run (a code review). **Checked and fine:** - Cache lookup precedes the cold-build headroom check. - The documentation now qualifies which passes are eligible for unrolling. - Generation tokens prevent an old worker from publishing against a reused pipeline handle. **Testing:** No code or tests were run for this review. The author reports Windows builds, game-free checks and standalone SDR/HDR parity; Linux and additional hardware runs are pending. Guide screenshots fails on this head, and the Website check is still running. **Overlaps and merge order:** The earlier review reports conflicts with Longshot #1886 and #1989 in gpu/vk/vk_fsr4.cpp; whichever merges second needs a rebase. Current overlap status was not independently checked. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
Owner
@fix
Member

I changed this pull request where an edit could (the rest needs runs, measurements or decisions): the new head is 0ccb8e229c. I edited the pull request's description too (6 edits).

Changed

  • Cold-build headroom, gpu/vk/vk_fsr4.cpp:735: Restored the 8 GiB guard for every cold build, keeping cache lookup first; updated the behavioral test. Tests were not run.
  • Pending checklist claims: Marked the test and host-build checklist entries pending in the description edits.
  • Description claims about eligibility and headroom: Updated the summary, risks and player-impact claims in the proposed description edits to distinguish the measured path from main's retained wave64 path and describe the 8 GiB guard.

Changed in part (the rest is for the author)

  • Preserve existing wave64 layer unrolling: Restored the base unroller for unmeasured wave64 layers under the 8 GiB guard in gpu/vk/vk_fsr4.cpp:655 and gpu/vk/spirv_unroll_legacy.h:25, with eligibility checks in tests/test_fsr4_bind_dispatch.py:238. The author must compare those configurations with main and assess their cost. No tests were run.
  • Measured FSR 4 cold path: Restored the 1 GiB compact-build guard only for the measured combination, retaining 8 GiB for larger shaders and other combinations in gpu/vk/vk_fsr4.cpp:310; updated coverage in tests/test_fsr4_bind_dispatch.py:326. The author must run the requested RADV, RDNA 4 and Steam Deck coverage, including cold pacing, warm cache hits, odd dimensions, SDR/HDR and context transitions.

Not done this time (still open: the next @fix takes it)

  • Guide screenshot source review: The branch predates the base’s newer guide capture and UI changes. The screenshot and its source review need reconciliation after the branch is brought up to date; the binary capture cannot be changed here.
  • First-playable-frame and peak-memory measurement: Instrumentation is still needed to log first-playable-frame time and capture peak RAM and VRAM. The author must then compare the merge base and corrected head in Auto and a heavy scene, recording cold and warm times and source log lines.

Nothing was built or run: check the change. Its review follows.


Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

I changed this pull request where an edit could (the rest needs runs, measurements or decisions): the new head is 0ccb8e229cc6. I edited the pull request's description too (6 edits). **Changed** - **Cold-build headroom, gpu/vk/vk_fsr4.cpp:735**: Restored the 8 GiB guard for every cold build, keeping cache lookup first; updated the behavioral test. Tests were not run. - **Pending checklist claims**: Marked the test and host-build checklist entries pending in the description edits. - **Description claims about eligibility and headroom**: Updated the summary, risks and player-impact claims in the proposed description edits to distinguish the measured path from main's retained wave64 path and describe the 8 GiB guard. **Changed in part (the rest is for the author)** - **Preserve existing wave64 layer unrolling**: Restored the base unroller for unmeasured wave64 layers under the 8 GiB guard in gpu/vk/vk_fsr4.cpp:655 and gpu/vk/spirv_unroll_legacy.h:25, with eligibility checks in tests/test_fsr4_bind_dispatch.py:238. The author must compare those configurations with main and assess their cost. No tests were run. - **Measured FSR 4 cold path**: Restored the 1 GiB compact-build guard only for the measured combination, retaining 8 GiB for larger shaders and other combinations in gpu/vk/vk_fsr4.cpp:310; updated coverage in tests/test_fsr4_bind_dispatch.py:326. The author must run the requested RADV, RDNA 4 and Steam Deck coverage, including cold pacing, warm cache hits, odd dimensions, SDR/HDR and context transitions. **Not done this time (still open: the next `@fix` takes it)** - **Guide screenshot source review**: The branch predates the base’s newer guide capture and UI changes. The screenshot and its source review need reconciliation after the branch is brought up to date; the binary capture cannot be changed here. - **First-playable-frame and peak-memory measurement**: Instrumentation is still needed to log first-playable-frame time and capture peak RAM and VRAM. The author must then compare the merge base and corrected head in Auto and a heavy scene, recording cold and warm times and source log lines. Nothing was built or run: check the change. Its review follows. --- <sub>Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
fix(vk): restrict FSR 4 unrolling to measured configurations
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
PR description / Description follows the template (pull_request_target) Failing after 11s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 11s
CI / Workflow lint (actionlint) (pull_request) Successful in 11s
Third-party parts / As their notes say (pull_request) Successful in 12s
CI / Website build and checks (pull_request) Has been cancelled
0ccb8e229c
As the review on #1999 asked.
BeanBot requested changes 2026-11-21 07:13:38 +00:00
Dismissed
BeanBot left a comment

Recommendation: Request changes. The reported RX 6700 XT runs show a substantial GPU-time improvement, but the corrected head still needs the requested in-game comparison and hardware coverage. The head-only Guide screenshots check also fails. (It stands on L22: The check Guide screenshots / Guide images and local UI source review (pull_request) fails on this head and passes on the base branch: Failing after 48s.)

The change folds and unrolls FSR 4 shaders to reduce GPU time and cold pipeline build cost. The expanded path is restricted to the measured Windows configuration; it adds a more complex shader transformation and pipeline-build path.

@fix will do (4)

  1. L19 (its part an edit can do): Log first-playable-frame time separately from background compilation and cache hits, and capture peak memory.
  2. L20 (its part an edit can do): Keep the measured shader and driver combinations on the new cold path while retaining the existing fallback on combinations awaiting coverage.
  3. L22: The check Guide screenshots / Guide images and local UI source review (pull_request) fails on this head and passes on the base branch: Failing after 48s.
  4. L25 (minor): The description says every cold build requires 8 GiB, but the changed code allows 1 GiB on the measured configuration for shaders up to 60,000 words. Update the summary and risks to describe both thresholds.

For the author (2) (a run, a measurement or a decision)

  • L19 (minor): Repeat the in-game comparison on the merge base and corrected head, including Auto and a heavy scene, source log lines, cold and warm time to first playable frame, and peak RAM and VRAM.
  • L20 (minor): The default reaches RADV and newer Adrenalin models, while the reported runs cover one Windows RDNA 2 card. Finish the listed Linux RADV and Windows RDNA 4 runs, and cover FSR 4-capable Steam Deck configurations. Check cold commit and pacing, warm cache hits, and output parity on odd dimensions and during SDR/HDR or context changes.

Since the last review (on c8371016fd)
Resolved: L11 (The 1 GiB threshold still admits every shader at or below 60,000 words on every driver. An…); L18 (The description records the missing Linux build and full suite, but leaves their checklist…)
Still open: L19 (Repeat the in-game comparison on the merge base and corrected head, including Auto and a h…); L20 (The default reaches RADV and newer Adrenalin models, while the reported runs cover one Win…); L22 (The check Guide screenshots / Guide images and local UI source review (pull_request) fai…)
New: L23 (The new measured_unroll gate also prevents the wave64 layer unrolling that main already pe…); L24 (The description after the fix still claims a 1 GiB compact-shader guard and unrolling on a…); L25 (The description says every cold build requires 8 GiB, but the changed code allows 1 GiB on…)

Checks: Still running: CI / Website build and checks (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Unproven on the corrected head. The PR reports three interleaved in-game pairs on an RX 6700 XT: median FSR dispatch time fell from 4.542 to 3.699 ms, but those runs used earlier commits. Matching shader word counts and standalone parity do not establish the corrected head's in-game timing.

Other systems: Linux RADV, Windows RDNA 4 and FSR 4-capable Steam Deck configurations retain the legacy wave64 unroller. Their requested cold-build, cache, pacing and parity runs remain outstanding. The measured Windows configuration now uses a 1 GiB cold-build guard for shaders at or below 60,000 words and 8 GiB above that.

Switches: No switches added, changed or removed in the changes since the ledger head.

Reviewed: 0ccb8e229c against f1f2dc5bd2: Read the changes since 608dd839 in vk_fsr4.cpp, upscalers.md and test_fsr4_bind_dispatch.py, and inspected the headroom caller and eligibility gate. Read repository rules and the PR template; the review checklist and adjacent Tooling rules were unavailable. Skimmed the overall diff and commit list; the unchanged unroller, legacy unroller, tests and generated SPIR-V were not read in full in this re-check.; nothing run (a code review).

Checked and fine:

  • The compact headroom threshold includes 60,000 words and falls back to 8 GiB above it or outside the measured configuration.
  • The behavioral test covers the threshold boundary and the unmeasured configuration.

Testing: No code or tests were run. The supplied CI reports Guide screenshots failing on this head and the Website check still running; the supplied Windows runs are author-reported evidence.

Overlaps and merge order: Review 2085 reports conflicts with Longshot #1886 and #1989; whichever lands second needs a rebase. Current overlap status was not independently checked.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The reported RX 6700 XT runs show a substantial GPU-time improvement, but the corrected head still needs the requested in-game comparison and hardware coverage. The head-only Guide screenshots check also fails. (It stands on L22: The check `Guide screenshots / Guide images and local UI source review (pull_request)` fails on this head and passes on the base branch: Failing after 48s.) The change folds and unrolls FSR 4 shaders to reduce GPU time and cold pipeline build cost. The expanded path is restricted to the measured Windows configuration; it adds a more complex shader transformation and pipeline-build path. **`@fix` will do (4)** 1. **L19** (its part an edit can do): Log first-playable-frame time separately from background compilation and cache hits, and capture peak memory. 2. **L20** (its part an edit can do): Keep the measured shader and driver combinations on the new cold path while retaining the existing fallback on combinations awaiting coverage. 3. **L22**: The check `Guide screenshots / Guide images and local UI source review (pull_request)` fails on this head and passes on the base branch: Failing after 48s. 4. **L25** (minor): The description says every cold build requires 8 GiB, but the changed code allows 1 GiB on the measured configuration for shaders up to 60,000 words. Update the summary and risks to describe both thresholds. **For the author (2)** (a run, a measurement or a decision) - **L19** (minor): Repeat the in-game comparison on the merge base and corrected head, including Auto and a heavy scene, source log lines, cold and warm time to first playable frame, and peak RAM and VRAM. - **L20** (minor): The default reaches RADV and newer Adrenalin models, while the reported runs cover one Windows RDNA 2 card. Finish the listed Linux RADV and Windows RDNA 4 runs, and cover FSR 4-capable Steam Deck configurations. Check cold commit and pacing, warm cache hits, and output parity on odd dimensions and during SDR/HDR or context changes. **Since the last review** (on c8371016fd71) Resolved: L11 (The 1 GiB threshold still admits every shader at or below 60,000 words on every driver. An…); L18 (The description records the missing Linux build and full suite, but leaves their checklist…) Still open: L19 (Repeat the in-game comparison on the merge base and corrected head, including Auto and a h…); L20 (The default reaches RADV and newer Adrenalin models, while the reported runs cover one Win…); L22 (The check `Guide screenshots / Guide images and local UI source review (pull_request)` fai…) New: L23 (The new measured_unroll gate also prevents the wave64 layer unrolling that main already pe…); L24 (The description after the fix still claims a 1 GiB compact-shader guard and unrolling on a…); L25 (The description says every cold build requires 8 GiB, but the changed code allows 1 GiB on…) **Checks:** Still running: `CI / Website build and checks (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven on the corrected head. The PR reports three interleaved in-game pairs on an RX 6700 XT: median FSR dispatch time fell from 4.542 to 3.699 ms, but those runs used earlier commits. Matching shader word counts and standalone parity do not establish the corrected head's in-game timing. **Other systems:** Linux RADV, Windows RDNA 4 and FSR 4-capable Steam Deck configurations retain the legacy wave64 unroller. Their requested cold-build, cache, pacing and parity runs remain outstanding. The measured Windows configuration now uses a 1 GiB cold-build guard for shaders at or below 60,000 words and 8 GiB above that. **Switches:** No switches added, changed or removed in the changes since the ledger head. **Reviewed:** 0ccb8e229cc6 against f1f2dc5bd282: Read the changes since 608dd839 in vk_fsr4.cpp, upscalers.md and test_fsr4_bind_dispatch.py, and inspected the headroom caller and eligibility gate. Read repository rules and the PR template; the review checklist and adjacent Tooling rules were unavailable. Skimmed the overall diff and commit list; the unchanged unroller, legacy unroller, tests and generated SPIR-V were not read in full in this re-check.; nothing run (a code review). **Checked and fine:** - The compact headroom threshold includes 60,000 words and falls back to 8 GiB above it or outside the measured configuration. - The behavioral test covers the threshold boundary and the unmeasured configuration. **Testing:** No code or tests were run. The supplied CI reports Guide screenshots failing on this head and the Website check still running; the supplied Windows runs are author-reported evidence. **Overlaps and merge order:** Review 2085 reports conflicts with Longshot #1886 and #1989; whichever lands second needs a rebase. Current overlap status was not independently checked. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
@ -801,2 +866,4 @@
const bool has_plain = (bool)plain[i];
const uint32_t orig_lanes = has_plain ? plain[i]->lanes : 0;
if (kind[i] & 2) { // (without a Plain, only when the library's own module could not be made: no fallback then)
auto [t, added] = tail_pipes.try_emplace(p[i]);
Member

L23 (minor): The new measured_unroll gate also prevents the wave64 layer unrolling that main already performs. For example, an FSR 4 player on Linux or a different AMD card now remains on the rolled pipeline after warming its cache. Compare those configurations with main and preserve the existing path where its cost is unacceptable.

**L23** (minor): The new measured_unroll gate also prevents the wave64 layer unrolling that main already performs. For example, an FSR 4 player on Linux or a different AMD card now remains on the rolled pipeline after warming its cache. Compare those configurations with main and preserve the existing path where its cost is unacceptable.
madebyjordan force-pushed perf/fsr4-further from 0ccb8e229c
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
PR description / Description follows the template (pull_request_target) Failing after 11s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 11s
CI / Workflow lint (actionlint) (pull_request) Successful in 11s
Third-party parts / As their notes say (pull_request) Successful in 12s
CI / Website build and checks (pull_request) Has been cancelled
to 3a7aca49c9
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 10s
PR description / Description follows the template (pull_request_target) Successful in 12s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 13s
Third-party parts / As their notes say (pull_request) Successful in 14s
beanstalk/approval can't be tested as asked: see the farm's comment
CI / Website build and checks (pull_request) Has been cancelled
2026-11-21 07:25:12 +00:00
Compare
Author
Member

Addressed both real findings from Review #2085, rebased onto current main (fd7dc40d), replaced BeanBot's unbuilt 0ccb8e22 commit (which duplicated spirv_unroll_legacy.h, hardcoded a single GPU/driver/FSR string AMD Radeon RX 6700 XT + 26.10.1 + 4.1.2, and unchecked required checklist boxes in the PR description), and verified Review #2103's remaining items:

Code & Test Fixes (Review #2085)

  1. Stale dead-store index after bitcast unpacking (gpu/vk/spirv_unroll.h forward_function_allocas): Moved sm[loc.path] = rebuilt.size(); after the vec_bitcast_src unpacking loop (right before pushing the OpStore) so overwriting a location removes the superseded OpStore and never a scalar OpBitcast referenced by a forwarded load. Added synthetic regression R1_bitcast_overwrite_dead_store (asuint(float2(a, b)) store -> load -> overwrite -> spirv-val + SPIR-V VM parity) in tests/test_fsr4_tune.py.
  2. Swapped OpFAdd / OpISub opcodes (gpu/vk/spirv_unroll.h): Fixed kISub = 130 (was 129, OpFAdd) and updated is_pure_op (case 129: instead of duplicate case 130:). Audited every other opcode number in spirv_unroll.h against spirv.h (all match). Added R2_isub_const_fold.
  3. Negative / out-of-bounds OpAccessChain constant index guard (gpu/vk/spirv_unroll.h): Enabling OpISub folding surfaced pass11.spv folding 0 - 1 = -1 into an OpAccessChain inside a dead-at-runtime branch (if (i != 0) arr[i - 1]), which spirv-val rejects even in untaken code. Added safe_access_chain_const() (tracking OpTypeArray, OpTypeVector, OpTypeMatrix, OpTypeStruct, OpTypeRuntimeArray bounds) so fold_constants / apply_aliases never substitute a negative or out-of-bounds OpConstant into an OpAccessChain index operand, plus regression test R3_oob_access_chain_index.

Rebase & Review #2103 Notes

  • Rebased onto forge/main (fd7dc40d): Pulls in #2013 (40bfceb0), clearing the earlier base (f1f2dc5b) CI failures (Website and all 37 old Guide screenshots entries; note main head fd7dc40d #1657 currently has 4 unrelated settings-graphics.png items in untouched fps_counter.cpp/vk_menu.cpp).
  • L18: scripts/check_pr_description.py hard-fails non-WIP PRs if any box in ### Ready for review or kept in ### When it applies is unchecked. Testing and Still to test explicitly record that the Linux build and full Linux CI suite are pending, and ### Ready to merge stays unchecked.
  • L11: kCompactHeadroom (1 GiB) only applies to AMD FSR 4 weight-table passes that fold cleanly (left == 0) to <= 60,000 words (peaking <60 MB, >16× headroom); larger shaders still require kBuildHeadroom (8 GiB).
  • L19 / L20: Adding new first-playable-frame telemetry or driver-version allowlists is out of scope; remaining platform/hardware coverage (Linux RADV, Windows RDNA 4, Steam Deck) remains listed under Still to test.

Re-verified on Rebased Head

  • tests/run_all.py fsr4 (Windows, 0 skipped): 3/3 passed (including R1, R2, R3 regressions).
  • All 13 real FSR 4.1.2 SPIR-V shaders: 13/13 pass spirv-val --target-env vulkan1.3 (det=1, and all 7 unrolled passes pass1/2/4/5/10/12/postpass retain identical folded word counts 27311–44769).
  • LONGSHOT_FSR=1 python -I scripts/dev.py vk (Windows llvm-mingw, on main @ fd7dc40d): compiled cleanly (0 errors, symbols checked).
  • scripts/check_third_party.py & scripts/check_pr_description.py: passed.
Addressed both real findings from Review #2085, rebased onto current `main` (`fd7dc40d`), replaced BeanBot's unbuilt `0ccb8e22` commit (which duplicated `spirv_unroll_legacy.h`, hardcoded a single GPU/driver/FSR string `AMD Radeon RX 6700 XT` + `26.10.1` + `4.1.2`, and unchecked required checklist boxes in the PR description), and verified Review #2103's remaining items: ### Code & Test Fixes (Review #2085) 1. **Stale dead-store index after bitcast unpacking (`gpu/vk/spirv_unroll.h` `forward_function_allocas`):** Moved `sm[loc.path] = rebuilt.size();` after the `vec_bitcast_src` unpacking loop (right before pushing the `OpStore`) so overwriting a location removes the superseded `OpStore` and never a scalar `OpBitcast` referenced by a forwarded load. Added synthetic regression `R1_bitcast_overwrite_dead_store` (`asuint(float2(a, b))` store -> load -> overwrite -> `spirv-val` + SPIR-V VM parity) in `tests/test_fsr4_tune.py`. 2. **Swapped `OpFAdd` / `OpISub` opcodes (`gpu/vk/spirv_unroll.h`):** Fixed `kISub = 130` (was `129`, `OpFAdd`) and updated `is_pure_op` (`case 129:` instead of duplicate `case 130:`). Audited every other opcode number in `spirv_unroll.h` against `spirv.h` (all match). Added `R2_isub_const_fold`. 3. **Negative / out-of-bounds `OpAccessChain` constant index guard (`gpu/vk/spirv_unroll.h`):** Enabling `OpISub` folding surfaced `pass11.spv` folding `0 - 1 = -1` into an `OpAccessChain` inside a dead-at-runtime branch (`if (i != 0) arr[i - 1]`), which `spirv-val` rejects even in untaken code. Added `safe_access_chain_const()` (tracking `OpTypeArray`, `OpTypeVector`, `OpTypeMatrix`, `OpTypeStruct`, `OpTypeRuntimeArray` bounds) so `fold_constants` / `apply_aliases` never substitute a negative or out-of-bounds `OpConstant` into an `OpAccessChain` index operand, plus regression test `R3_oob_access_chain_index`. ### Rebase & Review #2103 Notes - **Rebased onto `forge/main` (`fd7dc40d`):** Pulls in `#2013` (`40bfceb0`), clearing the earlier base (`f1f2dc5b`) CI failures (`Website` and all 37 old `Guide screenshots` entries; note `main` head `fd7dc40d` `#1657` currently has 4 unrelated `settings-graphics.png` items in untouched `fps_counter.cpp`/`vk_menu.cpp`). - **`L18`:** `scripts/check_pr_description.py` hard-fails non-WIP PRs if any box in `### Ready for review` or kept in `### When it applies` is unchecked. Testing and **Still to test** explicitly record that the Linux build and full Linux CI suite are pending, and `### Ready to merge` stays unchecked. - **`L11`:** `kCompactHeadroom` (`1 GiB`) only applies to AMD FSR 4 weight-table passes that fold cleanly (`left == 0`) to `<= 60,000` words (peaking `<60 MB`, >16× headroom); larger shaders still require `kBuildHeadroom` (`8 GiB`). - **`L19` / `L20`:** Adding new first-playable-frame telemetry or driver-version allowlists is out of scope; remaining platform/hardware coverage (Linux RADV, Windows RDNA 4, Steam Deck) remains listed under **Still to test**. ### Re-verified on Rebased Head - `tests/run_all.py fsr4` (Windows, 0 skipped): **3/3 passed** (including `R1`, `R2`, `R3` regressions). - All 13 real FSR 4.1.2 SPIR-V shaders: **13/13 pass `spirv-val --target-env vulkan1.3`** (`det=1`, and all 7 unrolled passes `pass1/2/4/5/10/12/postpass` retain identical folded word counts `27311–44769`). - `LONGSHOT_FSR=1 python -I scripts/dev.py vk` (Windows llvm-mingw, on `main @ fd7dc40d`): compiled cleanly (0 errors, symbols checked). - `scripts/check_third_party.py` & `scripts/check_pr_description.py`: passed.
Author
Member
@review
BeanBot requested changes 2026-11-21 07:32:10 +00:00
Dismissed
BeanBot left a comment

Recommendation: Request changes. The reported Windows measurements show a substantial GPU-time gain, but the corrected head has not been compared in game against the merge base, and the requested Linux and other hardware coverage remains outstanding. The head-only Guide screenshots check is also failing. (It stands on L22: The check Guide screenshots / Guide images and local UI source review (pull_request) fails on this head and passes on the base branch: Failing after 48s.)

The change folds and unrolls more FSR 4 shaders, aiming to reduce GPU time and cold pipeline-build costs. It adds a substantial SPIR-V transformation and expands the cold-build path to configurations that have not yet been tested.

@fix will do (3)

  1. L19 (its part an edit can do): Log first-playable-frame time separately from background compilation and cache hits, and capture peak memory.
  2. L20 (its part an edit can do) gpu/vk/vk_fsr4.cpp:735: Retain the existing fallback for combinations awaiting coverage, while using the new path for measured combinations.
  3. L22: The check Guide screenshots / Guide images and local UI source review (pull_request) fails on this head and passes on the base branch: Failing after 48s.

For the author (2) (a run, a measurement or a decision)

  • L19 (minor): Repeat the in-game comparison on the merge base and corrected head, including Auto and a heavy scene, source log lines, cold and warm time to first playable frame, and peak RAM and VRAM.
  • L20 (minor) gpu/vk/vk_fsr4.cpp:735: The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurations beyond the measured Windows card. Complete the requested RADV, RDNA 4 and Steam Deck runs, including cold pacing, warm cache hits and parity across odd dimensions and SDR/HDR or context changes.

Since the last review (on 0ccb8e229c)
Resolved: L25 (The description says every cold build requires 8 GiB, but the changed code allows 1 GiB on…)
Still open: L19 (Repeat the in-game comparison on the merge base and corrected head, including Auto and a h…); L20 (The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurat…); L22 (The check Guide screenshots / Guide images and local UI source review (pull_request) fai…)

Checks: Still running: CI / Website build and checks (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Yes on the reported Windows RX 6700 XT run: median FSR 4 dispatch time fell from 4.542 to 3.699 ms across three interleaved pairs. Those runs used earlier commits; an in-game comparison against the merge base on the corrected head remains missing.

Other systems: The expanded path also reaches Linux RADV, Windows RDNA 4 and FSR 4-capable Steam Deck configurations. Their cold pacing, cache reuse and visual parity remain unverified; Linux host build coverage is also pending.

Switches: No switch added or changed. The existing RX_VK_FSR4_TUNE=0 disables tuning.

Reviewed: 3a7aca49c9 against fd7dc40db0: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the supplied description and reviews, the final commit's unroller diff, and the headroom path. Skimmed the earlier lifecycle and unroller diffs. The full changed files and all dependent code were not read; the adjacent Tooling rules were unavailable, and docs/review-checklist.md was absent.; nothing run (a code review).

Checked and fine:

  • The description's two headroom thresholds match the current shader-size selection.
  • The final commit records the store position after emitting the bitcasts and corrects the OpISub opcode.

Testing: No code or tests were run. The author reports Windows game and game-free checks; Linux build and hardware runs remain pending. CI reports a head-only Guide screenshots failure and a running Website check.

Overlaps and merge order: Earlier review reports conflicts with #1886 and #1989 in gpu/vk/vk_fsr4.cpp; current overlap and merge order were not verified.


Automated code review by BeanBot (gpt-6.1-terra), asked for by madebyjordan. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The reported Windows measurements show a substantial GPU-time gain, but the corrected head has not been compared in game against the merge base, and the requested Linux and other hardware coverage remains outstanding. The head-only Guide screenshots check is also failing. (It stands on L22: The check `Guide screenshots / Guide images and local UI source review (pull_request)` fails on this head and passes on the base branch: Failing after 48s.) The change folds and unrolls more FSR 4 shaders, aiming to reduce GPU time and cold pipeline-build costs. It adds a substantial SPIR-V transformation and expands the cold-build path to configurations that have not yet been tested. **`@fix` will do (3)** 1. **L19** (its part an edit can do): Log first-playable-frame time separately from background compilation and cache hits, and capture peak memory. 2. **L20** (its part an edit can do) `gpu/vk/vk_fsr4.cpp:735`: Retain the existing fallback for combinations awaiting coverage, while using the new path for measured combinations. 3. **L22**: The check `Guide screenshots / Guide images and local UI source review (pull_request)` fails on this head and passes on the base branch: Failing after 48s. **For the author (2)** (a run, a measurement or a decision) - **L19** (minor): Repeat the in-game comparison on the merge base and corrected head, including Auto and a heavy scene, source log lines, cold and warm time to first playable frame, and peak RAM and VRAM. - **L20** (minor) `gpu/vk/vk_fsr4.cpp:735`: The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurations beyond the measured Windows card. Complete the requested RADV, RDNA 4 and Steam Deck runs, including cold pacing, warm cache hits and parity across odd dimensions and SDR/HDR or context changes. **Since the last review** (on 0ccb8e229cc6) Resolved: L25 (The description says every cold build requires 8 GiB, but the changed code allows 1 GiB on…) Still open: L19 (Repeat the in-game comparison on the merge base and corrected head, including Auto and a h…); L20 (The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurat…); L22 (The check `Guide screenshots / Guide images and local UI source review (pull_request)` fai…) **Checks:** Still running: `CI / Website build and checks (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes on the reported Windows RX 6700 XT run: median FSR 4 dispatch time fell from 4.542 to 3.699 ms across three interleaved pairs. Those runs used earlier commits; an in-game comparison against the merge base on the corrected head remains missing. **Other systems:** The expanded path also reaches Linux RADV, Windows RDNA 4 and FSR 4-capable Steam Deck configurations. Their cold pacing, cache reuse and visual parity remain unverified; Linux host build coverage is also pending. **Switches:** No switch added or changed. The existing RX_VK_FSR4_TUNE=0 disables tuning. **Reviewed:** 3a7aca49c977 against fd7dc40db0f6: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the supplied description and reviews, the final commit's unroller diff, and the headroom path. Skimmed the earlier lifecycle and unroller diffs. The full changed files and all dependent code were not read; the adjacent Tooling rules were unavailable, and docs/review-checklist.md was absent.; nothing run (a code review). **Checked and fine:** - The description's two headroom thresholds match the current shader-size selection. - The final commit records the store position after emitting the bitcasts and corrects the OpISub opcode. **Testing:** No code or tests were run. The author reports Windows game and game-free checks; Linux build and hardware runs remain pending. CI reports a head-only Guide screenshots failure and a running Website check. **Overlaps and merge order:** Earlier review reports conflicts with #1886 and #1989 in gpu/vk/vk_fsr4.cpp; current overlap and merge order were not verified. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by madebyjordan. Nothing was run; a maintainer decides.</sub>
Author
Member
@review
BeanBot left a comment

Recommendation: Request changes. The reported Windows RX 6700 XT results show a substantial FSR 4 GPU-time gain, but the corrected head and other eligible hardware still lack the requested measurements. The head-only Guide screenshots check is also failing, and the Website check is running. (It stands on L22: The check Guide screenshots / Guide images and local UI source review (pull_request) fails on this head and passes on the base branch: Failing after 48s.)

The change folds and unrolls more FSR 4 shaders, including the postpass, to reduce GPU time and cold pipeline compilation cost. It adds a substantial SPIR-V transformation and background-build complexity; coverage of its costs and behavior across eligible systems remains incomplete.

@fix will do (3)

  1. L19 (its part an edit can do): Log first-playable-frame time separately from background compilation and cache hits, and capture peak memory.
  2. L20 (its part an edit can do) gpu/vk/vk_fsr4.cpp:735: Retain the existing fallback for combinations awaiting coverage, while using the new path for measured combinations.
  3. L22: The check Guide screenshots / Guide images and local UI source review (pull_request) fails on this head and passes on the base branch: Failing after 48s.

For the author (2) (a run, a measurement or a decision)

  • L19 (minor): Repeat the in-game comparison on the merge base and corrected head, including Auto and a heavy scene, source log lines, cold and warm time to first playable frame, and peak RAM and VRAM.
  • L20 (minor) gpu/vk/vk_fsr4.cpp:735: The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurations beyond the measured Windows card. Complete the requested RADV, RDNA 4 and Steam Deck runs, including cold pacing, warm cache hits and parity across odd dimensions and SDR/HDR or context changes.

Since the last review (on 3a7aca49c9)
Still open: L19 (Repeat the in-game comparison on the merge base and corrected head, including Auto and a h…); L20 (The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurat…); L22 (The check Guide screenshots / Guide images and local UI source review (pull_request) fai…)

Checks: Still running: CI / Website build and checks (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Yes on the tested Windows RX 6700 XT: the reported three interleaved pairs show median FSR 4 dispatch time falling from 4.542 to 3.699 ms, and cold builds falling from 147.0 s for three passes to 3.43 s for seven. Those in-game comparisons used earlier commits; the merge-base versus corrected-head comparison remains missing.

Other systems: The compact threshold and expanded unroller also affect eligible RADV, RDNA 4 and Steam Deck configurations. Their cold pacing, cache behavior, odd-dimension and SDR/HDR or context-transition parity remain untested; the Linux host build and full suite are also pending.

Switches: No switch added, changed or removed. The existing RX_VK_FSR4_TUNE=0 disables tuning.

Reviewed: 3a7aca49c9 against fd7dc40db0: Read AGENTS.md, CONTRIBUTING.md and the pull request template; docs/review-checklist.md is absent. Checked the current head and the headroom and unrolling locations for the two ledger items, and read the supplied description, comments, review and CI status. The changed code files and diff were not read in full in this re-check; recorded runs and generated SPIR-V were not independently inspected.; nothing run (a code review).

Checked and fine:

  • The larger-than-60,000-word path retains the 8 GiB headroom threshold.
  • The reported Windows test includes three interleaved timing pairs and warm-cache checks.

Testing: No commands that build, test or run project code were executed. The supplied CI reports Guide screenshots failing on this head and Website still running.

Overlaps and merge order: Earlier review reports conflicts with Longshot #1886 and #1989 in gpu/vk/vk_fsr4.cpp; whichever merges second needs a rebase. Current overlap status was not verified.


Automated code review by BeanBot (gpt-6.1-terra), asked for by madebyjordan. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The reported Windows RX 6700 XT results show a substantial FSR 4 GPU-time gain, but the corrected head and other eligible hardware still lack the requested measurements. The head-only Guide screenshots check is also failing, and the Website check is running. (It stands on L22: The check `Guide screenshots / Guide images and local UI source review (pull_request)` fails on this head and passes on the base branch: Failing after 48s.) The change folds and unrolls more FSR 4 shaders, including the postpass, to reduce GPU time and cold pipeline compilation cost. It adds a substantial SPIR-V transformation and background-build complexity; coverage of its costs and behavior across eligible systems remains incomplete. **`@fix` will do (3)** 1. **L19** (its part an edit can do): Log first-playable-frame time separately from background compilation and cache hits, and capture peak memory. 2. **L20** (its part an edit can do) `gpu/vk/vk_fsr4.cpp:735`: Retain the existing fallback for combinations awaiting coverage, while using the new path for measured combinations. 3. **L22**: The check `Guide screenshots / Guide images and local UI source review (pull_request)` fails on this head and passes on the base branch: Failing after 48s. **For the author (2)** (a run, a measurement or a decision) - **L19** (minor): Repeat the in-game comparison on the merge base and corrected head, including Auto and a heavy scene, source log lines, cold and warm time to first playable frame, and peak RAM and VRAM. - **L20** (minor) `gpu/vk/vk_fsr4.cpp:735`: The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurations beyond the measured Windows card. Complete the requested RADV, RDNA 4 and Steam Deck runs, including cold pacing, warm cache hits and parity across odd dimensions and SDR/HDR or context changes. **Since the last review** (on 3a7aca49c977) Still open: L19 (Repeat the in-game comparison on the merge base and corrected head, including Auto and a h…); L20 (The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurat…); L22 (The check `Guide screenshots / Guide images and local UI source review (pull_request)` fai…) **Checks:** Still running: `CI / Website build and checks (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes on the tested Windows RX 6700 XT: the reported three interleaved pairs show median FSR 4 dispatch time falling from 4.542 to 3.699 ms, and cold builds falling from 147.0 s for three passes to 3.43 s for seven. Those in-game comparisons used earlier commits; the merge-base versus corrected-head comparison remains missing. **Other systems:** The compact threshold and expanded unroller also affect eligible RADV, RDNA 4 and Steam Deck configurations. Their cold pacing, cache behavior, odd-dimension and SDR/HDR or context-transition parity remain untested; the Linux host build and full suite are also pending. **Switches:** No switch added, changed or removed. The existing RX_VK_FSR4_TUNE=0 disables tuning. **Reviewed:** 3a7aca49c977 against fd7dc40db0f6: Read AGENTS.md, CONTRIBUTING.md and the pull request template; docs/review-checklist.md is absent. Checked the current head and the headroom and unrolling locations for the two ledger items, and read the supplied description, comments, review and CI status. The changed code files and diff were not read in full in this re-check; recorded runs and generated SPIR-V were not independently inspected.; nothing run (a code review). **Checked and fine:** - The larger-than-60,000-word path retains the 8 GiB headroom threshold. - The reported Windows test includes three interleaved timing pairs and warm-cache checks. **Testing:** No commands that build, test or run project code were executed. The supplied CI reports Guide screenshots failing on this head and Website still running. **Overlaps and merge order:** Earlier review reports conflicts with Longshot #1886 and #1989 in gpu/vk/vk_fsr4.cpp; whichever merges second needs a rebase. Current overlap status was not verified. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by madebyjordan. Nothing was run; a maintainer decides.</sub>
Author
Member

@Beanstalk Please test AMD FSR 4 (dlss=4) on AMD GPUs across Linux (RADV), Windows (RDNA 4 / RDNA 3 / RDNA 2), and any FSR 4-capable Steam Deck: run Hyrule Field and Castle Town Market (market-entrance) with both Auto and Performance presets (RX_VK_PASS_TIMING=1), checking cold pipeline build time/memory, warm cache reuse (cache/longshot_fsr4_pipelines.bin), steady-state frame times and fsr4 ffxDispatch GPU time, and visual parity vs main.

@Beanstalk Please test AMD FSR 4 (dlss=4) on AMD GPUs across Linux (RADV), Windows (RDNA 4 / RDNA 3 / RDNA 2), and any FSR 4-capable Steam Deck: run Hyrule Field and Castle Town Market (market-entrance) with both Auto and Performance presets (RX_VK_PASS_TIMING=1), checking cold pipeline build time/memory, warm cache reuse (cache/longshot_fsr4_pipelines.bin), steady-state frame times and fsr4 ffxDispatch GPU time, and visual parity vs main.
Member

Beanstalk test farm

Commit cfd2544 · approved by nobody yet · dashboard

A member of BigBeans can review this commit and comment @Beanstalk to test it.

<!-- beanstalk:sticky --> ### Beanstalk test farm Commit `cfd2544` · approved by nobody yet · [dashboard](https://beanstalk.magicbean.dev/prs/1999) A member of `BigBeans` can review this commit and comment `@Beanstalk` to test it.
Owner
@fix
BeanBot force-pushed perf/fsr4-further from 3a7aca49c9
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 10s
PR description / Description follows the template (pull_request_target) Successful in 12s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 13s
Third-party parts / As their notes say (pull_request) Successful in 14s
beanstalk/approval can't be tested as asked: see the farm's comment
CI / Website build and checks (pull_request) Has been cancelled
to cfd2544fb5
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
beanstalk/approval not approved yet
PR description / Description follows the template (pull_request_target) Successful in 6s
CI / Conventional Commit title (pull_request) Successful in 7s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 11s
CI / Workflow lint (actionlint) (pull_request) Successful in 11s
Third-party parts / As their notes say (pull_request) Successful in 12s
CI / Website build and checks (pull_request) Successful in 2m25s
2026-11-21 07:49:46 +00:00
Compare
BeanBot left a comment

Recommendation: Approve. The measured Windows configuration shows a substantial FSR 4 GPU-time improvement, but the requested comparison on the corrected head and coverage of other affected configurations remain outstanding. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.

What @fix changed
I changed this pull request: the new head is cfd2544fb5. I rebased it onto main (7c23d2be26).

Not done this time (still open: the next @fix takes it)

  • First-playable-frame timing and peak memory: The measurement tooling needs launch-to-playable timing and startup RAM/VRAM peak capture. The author must then run the cold and warm merge-base versus corrected-head comparison, including Auto and a heavy scene, and retain the source log lines.
  • gpu/vk/vk_fsr4.cpp:703 hardware coverage and fallback: The measured configuration needs a reliable eligibility check, and other configurations need the merge-base behavior preserved without reintroducing its unroller soundness defects. The author must also run the requested RADV, RDNA 4 and Steam Deck coverage.

Nothing was built or run: the checks run again on the new head.

Folds and unrolls more FSR 4 shader passes, including the postpass, and reduces cold pipeline compilation time on the tested Windows system. The expanded path and lower memory threshold also reach configurations that have not yet been tested.

@fix will do (2)

  1. L19 (its part an edit can do): Log first-playable-frame time separately from background compilation and cache hits, and capture peak memory.
  2. L20 (its part an edit can do) gpu/vk/vk_fsr4.cpp:735: Retain the existing fallback for combinations awaiting coverage, while using the new path for measured combinations.

Before merging, for the author (2) (a run, a measurement or a decision; it doesn't hold the recommendation)

  • L19 (minor): Repeat the in-game comparison on the merge base and corrected head, including Auto and a heavy scene, source log lines, cold and warm time to first playable frame, and peak RAM and VRAM.
  • L20 (minor) gpu/vk/vk_fsr4.cpp:735: The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurations beyond the measured Windows card. Complete the requested RADV, RDNA 4 and Steam Deck runs, including cold pacing, warm cache hits and parity across odd dimensions and SDR/HDR or context changes.

Since the last review (on 3a7aca49c9)
Still open: L19 (Repeat the in-game comparison on the merge base and corrected head, including Auto and a h…); L20 (The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurat…); L22 (The check Guide screenshots / Guide images and local UI source review (pull_request) fai…)

Checks: they run again on this head (Guide screenshots / Guide images and local UI source review (pull_request) failed on the last one); a failure shows on the pull request.

Also noticed (1; not asked for, not blocking)
  • The checkout is at rebased commit cfd2544f; 7c23d2be is its current base, consistent with the supplied range-diff.
More: does it help, other systems, switches, what was read

Does it help: Yes on the tested RX 6700 XT: the author's three interleaved in-game pairs report median FSR 4 dispatch time falling from 4.542 ms to 3.699 ms. Those measurements predate the corrected head; the requested corrected-head comparison remains open.

Other systems: Linux RADV, Windows RDNA 4 and FSR 4-capable Steam Deck configurations can use the expanded path; cold pacing, cache reuse and visual parity on those configurations remain unverified.

Switches: No switch added, changed or removed. Existing RX_VK_FSR4_TUNE defaults on for AMD GPUs and can disable tuning.

Reviewed: cfd2544fb5 against 7c23d2be26: Re-check focused on the ledger, recorded runs, the vk_fsr4.cpp diff and the headroom and eligibility code at HEAD. Other changed code, tests, generated fixture and repository rules were not read in full during this re-check.; nothing run (a code review).

Checked and fine:

  • The compact threshold remains limited to shaders of at most 60,000 words; larger eligible shaders retain the 8 GiB threshold.
  • The supplied range-diff reports no pull request changes since the ledger head.

Testing: No commands from the project or tests were run. The author reports Windows in-game, shader validation and behavioral test results; CI has not run on this head.

Overlaps and merge order: Earlier review reports conflicts with Longshot #1886 and #1989 in gpu/vk/vk_fsr4.cpp; current overlap was not independently verified.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The measured Windows configuration shows a substantial FSR 4 GPU-time improvement, but the requested comparison on the corrected head and coverage of other affected configurations remain outstanding. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge. **What `@fix` changed** I changed this pull request: the new head is cfd2544fb55f. I rebased it onto `main` (7c23d2be2613). **Not done this time (still open: the next `@fix` takes it)** - **First-playable-frame timing and peak memory**: The measurement tooling needs launch-to-playable timing and startup RAM/VRAM peak capture. The author must then run the cold and warm merge-base versus corrected-head comparison, including Auto and a heavy scene, and retain the source log lines. - **gpu/vk/vk_fsr4.cpp:703 hardware coverage and fallback**: The measured configuration needs a reliable eligibility check, and other configurations need the merge-base behavior preserved without reintroducing its unroller soundness defects. The author must also run the requested RADV, RDNA 4 and Steam Deck coverage. Nothing was built or run: the checks run again on the new head. Folds and unrolls more FSR 4 shader passes, including the postpass, and reduces cold pipeline compilation time on the tested Windows system. The expanded path and lower memory threshold also reach configurations that have not yet been tested. **`@fix` will do (2)** 1. **L19** (its part an edit can do): Log first-playable-frame time separately from background compilation and cache hits, and capture peak memory. 2. **L20** (its part an edit can do) `gpu/vk/vk_fsr4.cpp:735`: Retain the existing fallback for combinations awaiting coverage, while using the new path for measured combinations. **Before merging, for the author (2)** (a run, a measurement or a decision; it doesn't hold the recommendation) - **L19** (minor): Repeat the in-game comparison on the merge base and corrected head, including Auto and a heavy scene, source log lines, cold and warm time to first playable frame, and peak RAM and VRAM. - **L20** (minor) `gpu/vk/vk_fsr4.cpp:735`: The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurations beyond the measured Windows card. Complete the requested RADV, RDNA 4 and Steam Deck runs, including cold pacing, warm cache hits and parity across odd dimensions and SDR/HDR or context changes. **Since the last review** (on 3a7aca49c977) Still open: L19 (Repeat the in-game comparison on the merge base and corrected head, including Auto and a h…); L20 (The compact 1 GiB cold-build threshold and expanded unroller now reach eligible configurat…); L22 (The check `Guide screenshots / Guide images and local UI source review (pull_request)` fai…) **Checks:** they run again on this head (`Guide screenshots / Guide images and local UI source review (pull_request)` failed on the last one); a failure shows on the pull request. <details> <summary>Also noticed (1; not asked for, not blocking)</summary> - The checkout is at rebased commit cfd2544f; 7c23d2be is its current base, consistent with the supplied range-diff. </details> <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes on the tested RX 6700 XT: the author's three interleaved in-game pairs report median FSR 4 dispatch time falling from 4.542 ms to 3.699 ms. Those measurements predate the corrected head; the requested corrected-head comparison remains open. **Other systems:** Linux RADV, Windows RDNA 4 and FSR 4-capable Steam Deck configurations can use the expanded path; cold pacing, cache reuse and visual parity on those configurations remain unverified. **Switches:** No switch added, changed or removed. Existing RX_VK_FSR4_TUNE defaults on for AMD GPUs and can disable tuning. **Reviewed:** cfd2544fb55f against 7c23d2be2613: Re-check focused on the ledger, recorded runs, the vk_fsr4.cpp diff and the headroom and eligibility code at HEAD. Other changed code, tests, generated fixture and repository rules were not read in full during this re-check.; nothing run (a code review). **Checked and fine:** - The compact threshold remains limited to shaders of at most 60,000 words; larger eligible shaders retain the 8 GiB threshold. - The supplied range-diff reports no pull request changes since the ledger head. **Testing:** No commands from the project or tests were run. The author reports Windows in-game, shader validation and behavioral test results; CI has not run on this head. **Overlaps and merge order:** Earlier review reports conflicts with Longshot #1886 and #1989 in gpu/vk/vk_fsr4.cpp; current overlap was not independently verified. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
beanstalk/approval not approved yet
PR description / Description follows the template (pull_request_target) Successful in 6s
CI / Conventional Commit title (pull_request) Successful in 7s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 11s
CI / Workflow lint (actionlint) (pull_request) Successful in 11s
Third-party parts / As their notes say (pull_request) Successful in 12s
CI / Website build and checks (pull_request) Successful in 2m25s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
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 'perf/fsr4-further:madebyjordan-perf/fsr4-further'
git switch 'madebyjordan-perf/fsr4-further'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
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
MagicBeanDev/Longshot!1999
No description provided.