perf(vk): lift 1% lows +48.5% (+95% Market) and speed up ASTC decode 5.3x on non-ASTC GPUs via LDS scratch and loop hoisting #2194

Merged
HumanBean merged 2 commits from Jer9/Longshot:perf/vk-astc-shaders into main 2026-11-22 16:28:30 +00:00
Contributor

Summary

On GPUs without native hardware ASTC decoding (targets non-ASTC GPUs: AMD RDNA 3.5 tested; NVIDIA Warp32, Intel Xe, and Linux RADV/ACO pending Test Farm; applies under both default RX_VK_PRECOMPILE=1 and RX_VK_PRECOMPILE=0), the Vulkan backend decodes ASTC textures on the GPU via gpu/vk/host_shaders/astc_decoder.comp. Decoding large ASTC texture arrays (such as the two 1365x1365 90-layer terrain arrays in Kokiri Forest, totaling 447.2 Mpx across 6.99 million ASTC 8x8 blocks) stalled save loading for 2.42 s (2,309 ms of ASTC decode) and caused 81 ms texture-upload spikes during 3-zone traversal, pulling Market 1% lows down to 14.66 FPS.

Profiling showed that astc_decoder.comp suffered from severe private-memory spilling and redundant per-texel work:

  1. Dynamically-indexed private arrays (result_vector[64], color_values[32], endpoints0/1[4]) exceeded 512 bytes per thread, forcing shader compilers (including AMD LLPC) to spill local arrays to scratch memory and limiting SIMD occupancy.
  2. Single-plane blocks still unpacked secondary plane weights, and block-invariant partition hashes, weight-grid coordinates, and projection divisions were recomputed inside the inner per-texel loop.
  3. DecodeColorValues linearly scanned encoding_values to find the ISE encoding range instead of binary-searching.
  4. color_endpoint_data was declared without an initializer, causing uninitialized-register reads whenever a final trit/quint color block crossed a 32-bit word boundary past color_data_bits (instead of the ASTC-spec-mandated zero bits).

This change optimizes gpu/vk/host_shaders/astc_decoder.comp and regenerates gpu/vk/host_shaders/astc_decoder_comp_spv.h:

  • Replaces dynamically-indexed private arrays with per-invocation packed on-chip LDS scratch (shared uint s_buf[16][65], 4,160 bytes per workgroup, bank-conflict-free stride, strict per-thread ownership with zero workgroup barriers) and scalar endpoints.
  • Hoists block-invariant partition selection, weight-grid setup, and dimension scaling outside the per-texel loop, and adds a direct-grid fast path when weight-grid dimensions match block dimensions.
  • Uses binary search for the ISE encoding range in DecodeColorValues.
  • Initializes color_endpoint_data to uvec4(0u) before streaming color bits.

Standalone on main @ 9e10f6f7, GPU ASTC decoding is 5.34x faster on 1365x1365x90 terrain arrays (2,309.0 ms -> 432.0 ms), 4.87x faster across all slow ASTC uploads, cuts save-load max frame time by 4.22x (2,422.83 ms -> 573.47 ms), and lifts 3-zone traversal 1% lows by +48.5% (21.71 -> 32.25 FPS; up to +95.4% in Market, 14.66 -> 28.64 FPS) while cutting frames >= 50 ms by -78.1% (32 -> 7) with output bit-exact against the ASTC spec reference (one deliberate UB fix vs. main: initializing color_endpoint_data = uvec4(0u)).

Read first: gpu/vk/host_shaders/astc_decoder.comp, tests/test_astc_decoder_gpu.py, and tests/astc_decoder_gpu.cpp.

Testing

Tested: Windows 11, AMD Radeon 860M (Adrenalin 26.10.1 LLPC), handheld_profile=1 (1600x1000, 67% render scale, sharpness=80, vsync=0, amd_anti-lag_2=1, threaded_rendering=0).

  • Committed game-free Vulkan ASTC decode fixture tests/test_astc_decoder_gpu.py + tests/astc_decoder_gpu.cpp (rebased onto main @ a2dc5385, head 28beeb4d): passes in default CPU-only mode (compile + SPIR-V header check + CPU reference across all 14 block sizes, asserting error blocks decode to zeros and all valid blocks decode non-zero) and in --gpu mode on AMD Radeon 860M (28 readback cases, 22,680 pixels covering all 14 ASTC block sizes 4x4..12x12, odd image dimensions, linear and Switch 2 native tiling, 1–4 partitions, dual-plane across all 4 secondary channels, void-extent LDR, and error blocks; 0 mismatches against Tegra::Texture::ASTC::DecompressSerial within 0 tol for void-extent/error and <=1 LSB for astc.cpp's 65536 vs Vulkan UNORM8 65535 rounding).
  • Extended standalone Vulkan GPU bit-exactness verification: 0 mismatches across 1,695,694 decoded pixels covering all 14 ASTC block sizes (4x4..12x12), odd image dimensions, linear and Switch 2 native tiling, all 16 color endpoint modes (LDR and HDR), 1–4 partitions, dual-plane, void-extent, and error blocks (baseline differed from main only by color_endpoint_data = uvec4(0u) per ASTC spec); isolated 1365x1365 (1 layer, 20-iter avg) compute microbenchmark 6.769 ms -> 1.095 ms (6.18x).
  • Standalone in-game save load (3 interleaved rounds + 12 s settle + 1 cold-cache run) and 3-zone traversal (Kokiri Forest, Hyrule Field, Market; 3 interleaved rounds): verified 0 VK_ERROR_DEVICE_LOST, flat steady VRAM, and a zoomed Market Dev FPS counter side-by-side capture.
  • In-game 3-zone RX_VK_SHOT_FX=1 visual parity captures vs main across Kokiri Forest (PSNR 38.62 dB, MAE 1.11), Hyrule Field (PSNR 35.98 dB, MAE 2.46), and Market (PSNR 26.80 dB, MAE 5.85) — expected minor live time-of-day/NPC phase drift across independent runs, zero corruption or color artifacts.
  • Verified python -I scripts/shaders.py host --check passes (host shaders: 4 match) and all targeted checks pass on 28beeb4d: tests/test_astc_decoder_gpu.py (CPU-only + --gpu), tests/test_vulkan_fixtures_ci.py, tests/test_host_shaders.py, tests/test_astc_upload_chunking.py, tests/test_bc_scratch_layers.py, tests/test_bc_copy_layer_pitch.py, tests/test_bc_small_scratch.py, tests/test_utf8_paths.py, tests/test_doc_anchors.py, tests/test_cpp_preflight.py, and scripts/check_third_party.py. Pre-existing / host caveats: tests/test_switch_table.py fails identically on main (RX_VK_GRASS_DISTANCE ordering; this PR does not touch switches.def), and tests/test_job_queue.py is excluded on Windows shared consoles.

Still to test:

  • Linux (AMD RADV / Steam Deck): verify ASTC upload timing, 1% lows, and visual output under RADV/ACO (@Beanstalk linux-radv)
  • Windows (NVIDIA RTX): verify ASTC upload timing and visual output on Warp32 / NVIDIA shader compiler (@Beanstalk windows-nvidia)
  • Windows (AMD RX 6000–9000 dGPU): verify ASTC upload timing and 1% lows on discrete RDNA (@Beanstalk windows-amd)
  • Windows (Intel Arc / Xe): verify ASTC visual output and RX_VK_ASTC_RGBA8=1 path on Intel Xe SIMD16/32 by hand

Measurements

Verdict: Standalone on main @ 9e10f6f7, speeds up GPU ASTC 1365x1365x90 decoding by 5.34x (2,309 -> 432 ms), cuts save-load max stall by 4.22x (2,423 -> 573 ms), lifts 3-zone traversal 1% lows by +48.5% (21.71 -> 32.25 FPS; up to +95.4% in Market), and cuts frames >= 50 ms by -78.1% (32 -> 7) with output bit-exact against the ASTC spec reference (one deliberate UB fix vs. main: initializing color_endpoint_data = uvec4(0u)).

Setup: Windows 11 (26200), AMD Ryzen AI 7 350, AMD Radeon 860M (RDNA 3.5, Adrenalin 26.10.1 LLPC); handheld_profile=1 (1600x1000, 67% render scale, sharpness=80, vsync=0, amd_anti-lag_2=1, threaded_rendering=0), RX_VK_PRECOMPILE=0; Kokiri Forest save load (12 s settle) + 3-zone traversal (Kokiri Forest, Hyrule Field, Market), 3 interleaved unprofiled runs each, median [min, max].

Rebase note: Branch is rebased onto main @ a2dc5385 (#2174 simulated-turf floor + #1722 castle-gate save); measurements below remain from main @ 9e10f6f7 because #2174 did not affect our Kokiri Forest -> Hyrule Field -> Market tour (Hyrule Field max_ms on main @ 9e10f6f7 was 30.94 / 71.01 / 72.49 ms, gt_50ms 0 / 4 / 4, zero 250 ms turf stalls).

Before: main @ 9e10f6f7 After: this PR @ bb3fa08a Delta
ASTC 1365x1365x90 upload time (save load) 2,309.0 ms [2,306.0, 2,525.0] 432.0 ms [338.0, 451.0] -1,877.0 ms (5.34x faster)
Total slow ASTC uploads (save load) 3,878.6 ms [3,699.0, 3,914.2] 796.4 ms [450.9, 921.0] -3,082.2 ms (4.87x faster)
Max frame time (save load) 2,422.83 ms [2,384.08, 2,638.16] 573.47 ms [425.16, 618.97] -1,849.36 ms (4.22x faster)
Load click to in-play time 10.83 s [10.61, 10.95] 8.55 s [8.42, 8.59] -2.28 s (-21.0%)
Traversal mean FPS (3 zones) 54.79 [46.30, 56.64] 55.88 [52.07, 59.60] +1.09 FPS (+2.0%)
Traversal median frame time (3 zones) 16.98 ms [16.63, 19.46] 17.86 ms [17.02, 18.59] +0.88 ms (within spread)
Traversal p99 frame time / 1% low FPS 46.06 ms [37.78, 75.76] (21.71 [13.20, 26.47] FPS) 31.00 ms [29.39, 34.50] (32.25 [28.99, 34.03] FPS) -15.06 ms (+10.54 FPS / +48.5%)
Traversal p99.9 frame time (3 zones) 97.71 ms [90.97, 182.75] 58.80 ms [50.88, 70.48] -38.91 ms (-39.8%)
Traversal max frame time (3 zones) 327.59 ms [174.82, 620.88] 94.21 ms [69.41, 273.32] -233.38 ms (-71.2%)
Traversal frames >= 33.3 ms (3 zones) 66 [42, 183] 24 [24, 43] -42 (-63.6%)
Traversal frames >= 50 ms (3 zones) 32 [20, 69] 7 [4, 12] -25 (-78.1%)
Traversal peak uploads_ms 80.89 ms [66.42, 91.02] 21.55 ms [16.91, 43.57] -59.34 ms (3.75x faster)
Traversal peak tex_lookup_ms 83.00 ms [66.85, 125.28] 29.79 ms [23.85, 54.27] -53.21 ms (2.79x faster)
Kokiri Forest 1% low FPS (p99) 20.96 [20.22, 38.55] FPS (47.70 ms) 31.90 [25.92, 39.61] FPS (31.34 ms) +10.94 FPS (+52.2%)
Hyrule Field 1% low FPS (p99) 28.22 [26.63, 39.50] FPS (35.44 ms) 38.22 [35.55, 46.40] FPS (26.16 ms) +10.00 FPS (+35.4%)
Market 1% low FPS (p99) 14.66 [8.93, 20.91] FPS (68.20 ms) 28.64 [26.78, 30.91] FPS (34.91 ms) +13.98 FPS (+95.4%)
Steady VRAM (save load / traversal) 3,062 MB / 4,660 MB 3,271 MB / 4,660 MB +209 MB (in spread) / 0 MB

Cold cache (1 run each, empty cache, RX_VK_PRECOMPILE=0):

  • ASTC 1365x1365x90 upload time: 2,377.0 ms -> 472.0 ms (5.04x faster)
  • Total slow ASTC uploads: 3,754.3 ms -> 756.4 ms (4.96x faster)
  • Max frame time (save load): 2,709.9 ms -> 2,268.0 ms (-441.9 ms)
  • Steady VRAM: 2,998 MB -> 3,062 MB

Isolated GPU compute microbenchmark (1365x1365, 1 layer, 20-iter avg): astc_decoder 6.769 ms -> 1.095 ms (6.18x).

Raw longshot_log.txt lines (Round 1 save load and Round 1 traversal):

# Before: main @ 9e10f6f7 (save load R1)
[hos Presentation Thread] vk: slow upload 1146.6 ms: #327 0x10a1e2a600 1365x1365x1 x90 levels 11 NVN 0x8e ASTC (BC3), 57825 of 57825 KB
[hos Presentation Thread] vk: slow upload 1162.2 ms: #328 0x10a56a2c00 1365x1365x1 x90 levels 11 NVN 0x80 ASTC (BC3), 57825 of 57825 KB
[hos Presentation Thread] vk: status: 600 frames, the slowest 2384.1 ms; VRAM 3.2 of 11.9 GB
[hos Presentation Thread] vk: VRAM: 3271 MB used of 12212 MB allowed (261 MB of it free in the blocks); textures 2551 MB (budget 4096 MB), 1224 textures

# After: this PR @ bb3fa08a (save load R1)
[hos Presentation Thread] vk: slow upload 164.3 ms: #327 0x10a1e2a600 1365x1365x1 x90 levels 11 NVN 0x8e ASTC (BC3), 57825 of 57825 KB
[hos Presentation Thread] vk: slow upload 173.6 ms: #328 0x10a56a2c00 1365x1365x1 x90 levels 11 NVN 0x80 ASTC (BC3), 57825 of 57825 KB
[hos Presentation Thread] vk: status: 600 frames, the slowest 723.6 ms; VRAM 3.2 of 11.9 GB
[hos Presentation Thread] vk: VRAM: 3303 MB used of 12212 MB allowed (234 MB of it free in the blocks); textures 2611 MB (budget 4096 MB), 1259 textures

# Before: main @ 9e10f6f7 (3-zone traversal R1)
[hos Presentation Thread] vk: status: 600 frames, the slowest 194.0 ms; VRAM 4.5 of 11.9 GB
[hos Presentation Thread] vk: VRAM: 4628 MB used of 12212 MB allowed (619 MB of it free in the blocks); textures 3748 MB (budget 4096 MB), 3354 textures

# After: this PR @ bb3fa08a (3-zone traversal R1)
[hos Presentation Thread] vk: status: 600 frames, the slowest 50.2 ms; VRAM 4.6 of 11.9 GB
[hos Presentation Thread] vk: VRAM: 4724 MB used of 12212 MB allowed (654 MB of it free in the blocks); textures 3557 MB (budget 4096 MB), 3036 textures

Risks

  • What could break: astc_decoder.comp is rewritten to use shared uint s_buf[16][65] (4,160 bytes per workgroup, well below Vulkan's 16,384-byte guaranteed minimum, with strict per-thread column ownership 0..63 and no workgroup barriers across AMD Wave32/64, NVIDIA Warp32, and Intel Xe SIMD16/32) and diverges from the upstream Eden source it originated from (so future upstream syncs will need manual merging). Output is verified bit-exact across 1,695,694 decoded pixels covering all 14 block sizes and fixes an uninitialized color_endpoint_data read on main, though non-AMD compilers (NVIDIA, Intel, RADV/ACO) still need Tier 1 verification.
  • Turning it off: No new switch is added; players can test CPU ASTC decoding (RX_VK_ASTC_CPU=1) as a diagnostic fallback, and reverting the commit restores the previous shader cleanly.
  • After updating: Targets non-ASTC GPUs (AMD RDNA 3.5 tested; NVIDIA Warp32, Intel Xe, and Linux RADV/ACO pending Test Farm) for faster save loads and smoother traversal 1% lows (especially in texture-heavy areas like Market), with spec-conformant ASTC output and no cache invalidation required.

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 (scripts/shaders.py host --check, tests/test_astc_decoder_gpu.py CPU-only + --gpu, tests/test_vulkan_fixtures_ci.py, and 8 targeted ASTC/BC/shader/preflight/repo checks pass on Windows; test_switch_table.py fails identically on main, and test_job_queue.py is excluded on Windows shared consoles).
  • 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

  • The SPIR-V headers regenerated (a shader changed).
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • 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 On GPUs without native hardware ASTC decoding (targets non-ASTC GPUs: AMD RDNA 3.5 tested; NVIDIA Warp32, Intel Xe, and Linux RADV/ACO pending Test Farm; applies under both default `RX_VK_PRECOMPILE=1` and `RX_VK_PRECOMPILE=0`), the Vulkan backend decodes ASTC textures on the GPU via `gpu/vk/host_shaders/astc_decoder.comp`. Decoding large ASTC texture arrays (such as the two `1365x1365` 90-layer terrain arrays in Kokiri Forest, totaling 447.2 Mpx across 6.99 million ASTC 8x8 blocks) stalled save loading for `2.42 s` (`2,309 ms` of ASTC decode) and caused `81 ms` texture-upload spikes during 3-zone traversal, pulling Market 1% lows down to `14.66 FPS`. Profiling showed that `astc_decoder.comp` suffered from severe private-memory spilling and redundant per-texel work: 1. Dynamically-indexed private arrays (`result_vector[64]`, `color_values[32]`, `endpoints0/1[4]`) exceeded 512 bytes per thread, forcing shader compilers (including AMD LLPC) to spill local arrays to scratch memory and limiting SIMD occupancy. 2. Single-plane blocks still unpacked secondary plane weights, and block-invariant partition hashes, weight-grid coordinates, and projection divisions were recomputed inside the inner per-texel loop. 3. `DecodeColorValues` linearly scanned `encoding_values` to find the ISE encoding range instead of binary-searching. 4. `color_endpoint_data` was declared without an initializer, causing uninitialized-register reads whenever a final trit/quint color block crossed a 32-bit word boundary past `color_data_bits` (instead of the ASTC-spec-mandated zero bits). This change optimizes `gpu/vk/host_shaders/astc_decoder.comp` and regenerates `gpu/vk/host_shaders/astc_decoder_comp_spv.h`: - Replaces dynamically-indexed private arrays with per-invocation packed on-chip LDS scratch (`shared uint s_buf[16][65]`, 4,160 bytes per workgroup, bank-conflict-free stride, strict per-thread ownership with zero workgroup barriers) and scalar endpoints. - Hoists block-invariant partition selection, weight-grid setup, and dimension scaling outside the per-texel loop, and adds a direct-grid fast path when weight-grid dimensions match block dimensions. - Uses binary search for the ISE encoding range in `DecodeColorValues`. - Initializes `color_endpoint_data` to `uvec4(0u)` before streaming color bits. Standalone on `main @ 9e10f6f7`, GPU ASTC decoding is `5.34x` faster on `1365x1365x90` terrain arrays (`2,309.0 ms -> 432.0 ms`), `4.87x` faster across all slow ASTC uploads, cuts save-load max frame time by `4.22x` (`2,422.83 ms -> 573.47 ms`), and lifts 3-zone traversal 1% lows by `+48.5%` (`21.71 -> 32.25 FPS`; up to `+95.4%` in Market, `14.66 -> 28.64 FPS`) while cutting frames >= 50 ms by `-78.1%` (`32 -> 7`) with output bit-exact against the ASTC spec reference (one deliberate UB fix vs. `main`: initializing `color_endpoint_data = uvec4(0u)`). Read first: `gpu/vk/host_shaders/astc_decoder.comp`, `tests/test_astc_decoder_gpu.py`, and `tests/astc_decoder_gpu.cpp`. ## Testing **Tested:** Windows 11, AMD Radeon 860M (Adrenalin 26.10.1 LLPC), `handheld_profile=1` (`1600x1000`, `67%` render scale, `sharpness=80`, `vsync=0`, `amd_anti-lag_2=1`, `threaded_rendering=0`). - Committed game-free Vulkan ASTC decode fixture `tests/test_astc_decoder_gpu.py` + `tests/astc_decoder_gpu.cpp` (rebased onto `main @ a2dc5385`, head `28beeb4d`): passes in default CPU-only mode (compile + SPIR-V header check + CPU reference across all 14 block sizes, asserting error blocks decode to zeros and all valid blocks decode non-zero) and in `--gpu` mode on AMD Radeon 860M (`28` readback cases, `22,680` pixels covering all 14 ASTC block sizes `4x4..12x12`, odd image dimensions, linear and Switch 2 native tiling, 1–4 partitions, dual-plane across all 4 secondary channels, void-extent LDR, and error blocks; `0` mismatches against `Tegra::Texture::ASTC::DecompressSerial` within 0 tol for void-extent/error and `<=1` LSB for `astc.cpp`'s `65536` vs Vulkan UNORM8 `65535` rounding). - Extended standalone Vulkan GPU bit-exactness verification: `0` mismatches across `1,695,694` decoded pixels covering all 14 ASTC block sizes (`4x4`..`12x12`), odd image dimensions, linear and Switch 2 native tiling, all 16 color endpoint modes (LDR and HDR), 1–4 partitions, dual-plane, void-extent, and error blocks (baseline differed from `main` only by `color_endpoint_data = uvec4(0u)` per ASTC spec); isolated `1365x1365` (1 layer, 20-iter avg) compute microbenchmark `6.769 ms -> 1.095 ms` (`6.18x`). - Standalone in-game save load (3 interleaved rounds + 12 s settle + 1 cold-cache run) and 3-zone traversal (Kokiri Forest, Hyrule Field, Market; 3 interleaved rounds): verified `0` `VK_ERROR_DEVICE_LOST`, flat steady VRAM, and a zoomed Market Dev FPS counter side-by-side capture. - In-game 3-zone `RX_VK_SHOT_FX=1` visual parity captures vs `main` across Kokiri Forest (`PSNR 38.62 dB`, `MAE 1.11`), Hyrule Field (`PSNR 35.98 dB`, `MAE 2.46`), and Market (`PSNR 26.80 dB`, `MAE 5.85`) — expected minor live time-of-day/NPC phase drift across independent runs, zero corruption or color artifacts. - Verified `python -I scripts/shaders.py host --check` passes (`host shaders: 4 match`) and all targeted checks pass on `28beeb4d`: `tests/test_astc_decoder_gpu.py` (CPU-only + `--gpu`), `tests/test_vulkan_fixtures_ci.py`, `tests/test_host_shaders.py`, `tests/test_astc_upload_chunking.py`, `tests/test_bc_scratch_layers.py`, `tests/test_bc_copy_layer_pitch.py`, `tests/test_bc_small_scratch.py`, `tests/test_utf8_paths.py`, `tests/test_doc_anchors.py`, `tests/test_cpp_preflight.py`, and `scripts/check_third_party.py`. Pre-existing / host caveats: `tests/test_switch_table.py` fails identically on `main` (`RX_VK_GRASS_DISTANCE` ordering; this PR does not touch `switches.def`), and `tests/test_job_queue.py` is excluded on Windows shared consoles. **Still to test:** - Linux (AMD RADV / Steam Deck): verify ASTC upload timing, 1% lows, and visual output under RADV/ACO (@Beanstalk linux-radv) - Windows (NVIDIA RTX): verify ASTC upload timing and visual output on Warp32 / NVIDIA shader compiler (@Beanstalk windows-nvidia) - Windows (AMD RX 6000–9000 dGPU): verify ASTC upload timing and 1% lows on discrete RDNA (@Beanstalk windows-amd) - Windows (Intel Arc / Xe): verify ASTC visual output and `RX_VK_ASTC_RGBA8=1` path on Intel Xe SIMD16/32 by hand ## Measurements **Verdict:** Standalone on `main @ 9e10f6f7`, speeds up GPU ASTC `1365x1365x90` decoding by `5.34x` (`2,309 -> 432 ms`), cuts save-load max stall by `4.22x` (`2,423 -> 573 ms`), lifts 3-zone traversal 1% lows by `+48.5%` (`21.71 -> 32.25 FPS`; up to `+95.4%` in Market), and cuts frames >= 50 ms by `-78.1%` (`32 -> 7`) with output bit-exact against the ASTC spec reference (one deliberate UB fix vs. `main`: initializing `color_endpoint_data = uvec4(0u)`). Setup: Windows 11 (26200), AMD Ryzen AI 7 350, AMD Radeon 860M (RDNA 3.5, Adrenalin 26.10.1 LLPC); `handheld_profile=1` (`1600x1000`, `67%` render scale, `sharpness=80`, `vsync=0`, `amd_anti-lag_2=1`, `threaded_rendering=0`), `RX_VK_PRECOMPILE=0`; Kokiri Forest save load (12 s settle) + 3-zone traversal (Kokiri Forest, Hyrule Field, Market), 3 interleaved unprofiled runs each, median `[min, max]`. Rebase note: Branch is rebased onto `main @ a2dc5385` (`#2174` simulated-turf floor + `#1722` castle-gate save); measurements below remain from `main @ 9e10f6f7` because `#2174` did not affect our `Kokiri Forest -> Hyrule Field -> Market` tour (Hyrule Field `max_ms` on `main @ 9e10f6f7` was `30.94 / 71.01 / 72.49 ms`, `gt_50ms` `0 / 4 / 4`, zero 250 ms turf stalls). | | Before: main @ 9e10f6f7 | After: this PR @ bb3fa08a | Delta | |---|---|---|---| | ASTC `1365x1365x90` upload time (save load) | 2,309.0 ms [2,306.0, 2,525.0] | 432.0 ms [338.0, 451.0] | -1,877.0 ms (5.34x faster) | | Total slow ASTC uploads (save load) | 3,878.6 ms [3,699.0, 3,914.2] | 796.4 ms [450.9, 921.0] | -3,082.2 ms (4.87x faster) | | Max frame time (save load) | 2,422.83 ms [2,384.08, 2,638.16] | 573.47 ms [425.16, 618.97] | -1,849.36 ms (4.22x faster) | | Load click to in-play time | 10.83 s [10.61, 10.95] | 8.55 s [8.42, 8.59] | -2.28 s (-21.0%) | | Traversal mean FPS (3 zones) | 54.79 [46.30, 56.64] | 55.88 [52.07, 59.60] | +1.09 FPS (+2.0%) | | Traversal median frame time (3 zones) | 16.98 ms [16.63, 19.46] | 17.86 ms [17.02, 18.59] | +0.88 ms (within spread) | | Traversal p99 frame time / 1% low FPS | 46.06 ms [37.78, 75.76] (21.71 [13.20, 26.47] FPS) | 31.00 ms [29.39, 34.50] (32.25 [28.99, 34.03] FPS) | -15.06 ms (+10.54 FPS / +48.5%) | | Traversal p99.9 frame time (3 zones) | 97.71 ms [90.97, 182.75] | 58.80 ms [50.88, 70.48] | -38.91 ms (-39.8%) | | Traversal max frame time (3 zones) | 327.59 ms [174.82, 620.88] | 94.21 ms [69.41, 273.32] | -233.38 ms (-71.2%) | | Traversal frames >= 33.3 ms (3 zones) | 66 [42, 183] | 24 [24, 43] | -42 (-63.6%) | | Traversal frames >= 50 ms (3 zones) | 32 [20, 69] | 7 [4, 12] | -25 (-78.1%) | | Traversal peak `uploads_ms` | 80.89 ms [66.42, 91.02] | 21.55 ms [16.91, 43.57] | -59.34 ms (3.75x faster) | | Traversal peak `tex_lookup_ms` | 83.00 ms [66.85, 125.28] | 29.79 ms [23.85, 54.27] | -53.21 ms (2.79x faster) | | Kokiri Forest 1% low FPS (p99) | 20.96 [20.22, 38.55] FPS (47.70 ms) | 31.90 [25.92, 39.61] FPS (31.34 ms) | +10.94 FPS (+52.2%) | | Hyrule Field 1% low FPS (p99) | 28.22 [26.63, 39.50] FPS (35.44 ms) | 38.22 [35.55, 46.40] FPS (26.16 ms) | +10.00 FPS (+35.4%) | | Market 1% low FPS (p99) | 14.66 [8.93, 20.91] FPS (68.20 ms) | 28.64 [26.78, 30.91] FPS (34.91 ms) | +13.98 FPS (+95.4%) | | Steady VRAM (save load / traversal) | 3,062 MB / 4,660 MB | 3,271 MB / 4,660 MB | +209 MB (in spread) / 0 MB | Cold cache (1 run each, empty cache, `RX_VK_PRECOMPILE=0`): - ASTC `1365x1365x90` upload time: `2,377.0 ms -> 472.0 ms` (`5.04x` faster) - Total slow ASTC uploads: `3,754.3 ms -> 756.4 ms` (`4.96x` faster) - Max frame time (save load): `2,709.9 ms -> 2,268.0 ms` (`-441.9 ms`) - Steady VRAM: `2,998 MB -> 3,062 MB` Isolated GPU compute microbenchmark (`1365x1365`, 1 layer, 20-iter avg): `astc_decoder` `6.769 ms -> 1.095 ms` (`6.18x`). Raw `longshot_log.txt` lines (Round 1 save load and Round 1 traversal): ```text # Before: main @ 9e10f6f7 (save load R1) [hos Presentation Thread] vk: slow upload 1146.6 ms: #327 0x10a1e2a600 1365x1365x1 x90 levels 11 NVN 0x8e ASTC (BC3), 57825 of 57825 KB [hos Presentation Thread] vk: slow upload 1162.2 ms: #328 0x10a56a2c00 1365x1365x1 x90 levels 11 NVN 0x80 ASTC (BC3), 57825 of 57825 KB [hos Presentation Thread] vk: status: 600 frames, the slowest 2384.1 ms; VRAM 3.2 of 11.9 GB [hos Presentation Thread] vk: VRAM: 3271 MB used of 12212 MB allowed (261 MB of it free in the blocks); textures 2551 MB (budget 4096 MB), 1224 textures # After: this PR @ bb3fa08a (save load R1) [hos Presentation Thread] vk: slow upload 164.3 ms: #327 0x10a1e2a600 1365x1365x1 x90 levels 11 NVN 0x8e ASTC (BC3), 57825 of 57825 KB [hos Presentation Thread] vk: slow upload 173.6 ms: #328 0x10a56a2c00 1365x1365x1 x90 levels 11 NVN 0x80 ASTC (BC3), 57825 of 57825 KB [hos Presentation Thread] vk: status: 600 frames, the slowest 723.6 ms; VRAM 3.2 of 11.9 GB [hos Presentation Thread] vk: VRAM: 3303 MB used of 12212 MB allowed (234 MB of it free in the blocks); textures 2611 MB (budget 4096 MB), 1259 textures # Before: main @ 9e10f6f7 (3-zone traversal R1) [hos Presentation Thread] vk: status: 600 frames, the slowest 194.0 ms; VRAM 4.5 of 11.9 GB [hos Presentation Thread] vk: VRAM: 4628 MB used of 12212 MB allowed (619 MB of it free in the blocks); textures 3748 MB (budget 4096 MB), 3354 textures # After: this PR @ bb3fa08a (3-zone traversal R1) [hos Presentation Thread] vk: status: 600 frames, the slowest 50.2 ms; VRAM 4.6 of 11.9 GB [hos Presentation Thread] vk: VRAM: 4724 MB used of 12212 MB allowed (654 MB of it free in the blocks); textures 3557 MB (budget 4096 MB), 3036 textures ``` ## Risks - **What could break:** `astc_decoder.comp` is rewritten to use `shared uint s_buf[16][65]` (4,160 bytes per workgroup, well below Vulkan's 16,384-byte guaranteed minimum, with strict per-thread column ownership `0..63` and no workgroup barriers across AMD Wave32/64, NVIDIA Warp32, and Intel Xe SIMD16/32) and diverges from the upstream Eden source it originated from (so future upstream syncs will need manual merging). Output is verified bit-exact across 1,695,694 decoded pixels covering all 14 block sizes and fixes an uninitialized `color_endpoint_data` read on `main`, though non-AMD compilers (NVIDIA, Intel, RADV/ACO) still need Tier 1 verification. - **Turning it off:** No new switch is added; players can test CPU ASTC decoding (`RX_VK_ASTC_CPU=1`) as a diagnostic fallback, and reverting the commit restores the previous shader cleanly. - **After updating:** Targets non-ASTC GPUs (AMD RDNA 3.5 tested; NVIDIA Warp32, Intel Xe, and Linux RADV/ACO pending Test Farm) for faster save loads and smoother traversal 1% lows (especially in texture-heavy areas like Market), with spec-conformant ASTC output and no cache invalidation required. ## 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 (`scripts/shaders.py host --check`, `tests/test_astc_decoder_gpu.py` CPU-only + `--gpu`, `tests/test_vulkan_fixtures_ci.py`, and 8 targeted ASTC/BC/shader/preflight/repo checks pass on Windows; `test_switch_table.py` fails identically on `main`, and `test_job_queue.py` is excluded on Windows shared consoles). - [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] The SPIR-V headers regenerated (a shader changed). - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [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): eliminate private-array scratch spills and dead work in astc_decoder.comp
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 9s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
bb3fa08ad7
Replace dynamically-indexed private arrays (result_vector[64], color_values[32],
endpoints0/1[4], per-texel Hash52/Select2DPartition, and dynamic uvec4 indexing)
with per-invocation packed on-chip LDS scratch (s_buf[16][65], 4 KB/workgroup,
bank-conflict-free stride, zero workgroup barriers), scalar endpoints, hoisted
block-invariant partition/weight-grid setup, direct-grid fast path, binary search
in DecodeColorValues, and early max_x/max_y bounds.

Also initializes color_endpoint_data to uvec4(0u) before streaming color bits,
fixing uninitialized-register reads when a final trit/quint color block spans a
32-bit word boundary past color_data_bits.

Verified bit-exact across 1,695,694 pixels covering all 14 ASTC block sizes,
odd dimensions, linear and native tiling, all 16 CEMs (LDR/HDR), 1-4 partitions,
dual-plane, and void-extent blocks on AMD Radeon 860M (6.18x isolated compute
speedup on 1365x1365; 8.24x end-to-end on 1365x1365x90 ASTC->BC3 upload).

Assisted-by: Antigravity
Author
Contributor

Tested in game: Windows 11 (26200), AMD Radeon 860M (Adrenalin 26.10.1 LLPC), handheld_profile=1 (1600x1000, 67%, sharpness=80), RX_VK_PRECOMPILE=0. Kokiri Forest save load (3 interleaved rounds): 1365x1365x90 ASTC upload 2,309 -> 432 ms (5.34x faster), max frame stall 2,423 -> 573 ms (4.22x faster), Load click to in-play 10.83 -> 8.55 s (-2.28 s / -21.0%), 0 device lost. 3-zone traversal (Kokiri Forest, Hyrule Field, Market, 3 interleaved rounds): aggregate 1% low 21.71 -> 32.25 FPS (+48.5%), Market 1% low 14.66 -> 28.64 FPS (+95.4%), >=50 ms frames 32 -> 7 (-78.1%), 0/1,695,694 pixel mismatches across all 14 ASTC block sizes, visual parity verified across all 3 zones, 0 device lost.

Tested in game: Windows 11 (26200), AMD Radeon 860M (Adrenalin 26.10.1 LLPC), handheld_profile=1 (1600x1000, 67%, sharpness=80), RX_VK_PRECOMPILE=0. Kokiri Forest save load (3 interleaved rounds): 1365x1365x90 ASTC upload 2,309 -> 432 ms (5.34x faster), max frame stall 2,423 -> 573 ms (4.22x faster), Load click to in-play 10.83 -> 8.55 s (-2.28 s / -21.0%), 0 device lost. 3-zone traversal (Kokiri Forest, Hyrule Field, Market, 3 interleaved rounds): aggregate 1% low 21.71 -> 32.25 FPS (+48.5%), Market 1% low 14.66 -> 28.64 FPS (+95.4%), >=50 ms frames 32 -> 7 (-78.1%), 0/1,695,694 pixel mismatches across all 14 ASTC block sizes, visual parity verified across all 3 zones, 0 device lost.
Member

Possibly related, for context:

  • issue #1268 Game: 200-470 ms stutters when many new textures arrive: the main thread waits ~0.3 s on a GPU fence after a frame of uploads (RTX 3090, Linux) — Open report of texture-arrival stutters; this improves ASTC decode cost, but not its measured fence-wait mechanism.
  • PR #1281 WIP: perf(vk): a new ASTC texture's blocks are hashed at upload only when a finalized one has its shape — Open Vulkan ASTC upload performance work; separate hashing optimization, though both address area-load texture delays.
  • PR #1833 fix(vk): chunk GPU ASTC uploads to fix iGPU VK_ERROR_DEVICE_LOST (Windows 2s TDR) and drop per-chip CPU fallbacks (15.2 s to 2.2 s Kokiri load) — Merged ASTC upload chunking this builds on; controls dispatch batching/TDR while this optimizes shader decode.
Possibly related, for context: - issue #1268 Game: 200-470 ms stutters when many new textures arrive: the main thread waits ~0.3 s on a GPU fence after a frame of uploads (RTX 3090, Linux) — Open report of texture-arrival stutters; this improves ASTC decode cost, but not its measured fence-wait mechanism. - PR #1281 WIP: perf(vk): a new ASTC texture's blocks are hashed at upload only when a finalized one has its shape — Open Vulkan ASTC upload performance work; separate hashing optimization, though both address area-load texture delays. - PR #1833 fix(vk): chunk GPU ASTC uploads to fix iGPU VK_ERROR_DEVICE_LOST (Windows 2s TDR) and drop per-chip CPU fallbacks (15.2 s to 2.2 s Kokiri load) — Merged ASTC upload chunking this builds on; controls dispatch batching/TDR while this optimizes shader decode.
Author
Contributor

Independent test log on a second RDNA 3.5 system (courtesy of nwgat on Discord):

Setup: Windows 11 (10.0.26300), AMD Ryzen AI 9 365, AMD Radeon 880M (Adrenalin 26.11.2 LLPC), 1920x1080, handheld_profile=1, FSR 4, VSync on, threaded_rendering=1, default RX_VK_LOAD=create (RX_VK_PRECOMPILE=1), KokiriForest_Child (82.5 s session, pr-2194-bb3fa08a). For ASTC upload comparison on the same PC and identical longshot_options.ini, the sibling pr-2193-e4ad718b run (74.7 s) uses unmodified main astc_decoder.comp.

ASTC upload & load-stall results on Radeon 880M:

Metric (same PC & options, single run each) Stock astc_decoder.comp (pr-2193-e4ad718b) This PR (pr-2194-bb3fa08a) Delta
1365x1365x90 ASTC→BC3 uploads 2,071.8 ms (1,031.0 + 1,040.8 ms) 316.7 ms (160.4 + 156.3 ms) 6.54x faster
Total vk: slow upload (count / sum) 36 uploads / 3,528.0 ms 8 uploads / 451.9 ms 7.81x faster
Save-load slowest frame (vk: status) 2,225.7 ms (slow submit 2,193.8 ms) 578.2 ms (slow submit 454.7 ms) 3.85x faster
Perf report uploads (Title / Kokiri) 2,194.6 ms (350 MB) / 1,617.1 ms (1,134 MB) 562.5 ms (493 MB) / 404.5 ms (803 MB) 3.9x / 4.0x faster
Kokiri upload / memsync hitches texture_upload: 5, memsync: 5 texture_upload: 3, memsync: 0 -2 / -5
Errors (device_lost / program_failed / draws_left_out) 0 / 0 / 0 0 / 0 / 0 Clean

Note on tester's audio/stuttering report: The tester reported "had a really bad audio/stuttering on this one for some reason". Checking the perf report (1795320425-0.json) and longshot_log.txt, the stutter was CPU/vcore scheduling contention (game_cpu) rather than ASTC uploads or GPU stalls:

  • It started on the Title and intro screen before gameplay ASTC decoding (game_cpu: 7 vs. 0, movie.decode_ms: 909.7 ms vs. 537.1 ms, movie.dropped: 168 vs. 106, slowest 230.6 ms vs. 62.3 ms).
  • Mid-session in Kokiri Forest (samples[33..38], ~34–39 s), FPS dipped to 8–18 FPS (slowest 370.9 ms) while gpu_ms was only 149 ms / 1,008 ms, with game_cpu: 10 hitches (vs. 4) and large vcores OS waits (BaseProcExecutor4 longest 743.3 ms, Resource Memory 389.2 ms, nn.npln.Worker 180.7 ms, sead::MainThread 129.8 ms) plus vk: GPU time climbing from ~20 ms to 25–33 ms — consistent with transient background host load or laptop APU power/thermal throttling during that run (this PR only changes gpu/vk/host_shaders/astc_decoder.comp). Re-testing on a second clean run or on the Test Farm is still welcome to double-check.

Key lines from longshot_log.txt (pr-2194-bb3fa08a):

[hos host] longshot pr-2194-bb3fa08a (source 70224aba)
[hos host] vk: slow upload 160.4 ms: #337 0x10a0efa600 1365x1365x1 x90 levels 11 NVN 0x8e ASTC (BC3), 57825 of 57825 KB
[hos host] vk: slow upload 156.3 ms: #338 0x10a4772c00 1365x1365x1 x90 levels 11 NVN 0x80 ASTC (BC3), 57825 of 57825 KB
[hos host] vk: slow submit: 454.7 ms: draw 442.0 descriptors 440.2 texture lookups 439.4 uploads 319.8 programs 1.4 queue submit 1.9
[hos host] vk: status: 600 frames, the slowest 230.6 ms; VRAM 0.4 of 10.2 GB
[hos host] vk: status: 600 frames, the slowest 578.2 ms; VRAM 3.4 of 10.2 GB; AMD FSR 4: ...
[hos host] vk: status: 600 frames, the slowest 225.1 ms; VRAM 4.0 of 10.2 GB; AMD FSR 4: ...
[hos host] vk: status: 600 frames, the slowest 370.9 ms; VRAM 4.0 of 10.2 GB; AMD FSR 4: ...
[hos BaseProcExecutor4] vcores: 145175 takes, 63077 waits (mean 127 us, longest 743.3 ms, 3 over HOS_VCORE_LOG_MS), ...
[hos sead::MainThread] vcores: 99554 takes, 25478 waits (mean 129 us, longest 129.8 ms, 6 over HOS_VCORE_LOG_MS), ...
[hos host] vk: program census (close): ... in play: 21 program records loaded (2.2 ms), 0 new graphics pipelines, pipelines from the driver's cache 15, from the start's cache 0, compiled 0; 0 draws and dispatches left out, 0 waits (0.0 ms)
Independent test log on a second RDNA 3.5 system (courtesy of `nwgat` on Discord): **Setup:** Windows 11 (`10.0.26300`), AMD Ryzen AI 9 365, AMD Radeon 880M (Adrenalin `26.11.2 LLPC`), `1920x1080`, `handheld_profile=1`, FSR 4, VSync on, `threaded_rendering=1`, default `RX_VK_LOAD=create` (`RX_VK_PRECOMPILE=1`), `KokiriForest_Child` (`82.5 s` session, `pr-2194-bb3fa08a`). For ASTC upload comparison on the same PC and identical `longshot_options.ini`, the sibling `pr-2193-e4ad718b` run (`74.7 s`) uses unmodified `main` `astc_decoder.comp`. **ASTC upload & load-stall results on Radeon 880M:** | Metric (same PC & options, single run each) | Stock `astc_decoder.comp` (`pr-2193-e4ad718b`) | This PR (`pr-2194-bb3fa08a`) | Delta | |---|---:|---:|---:| | `1365x1365x90` ASTC→BC3 uploads | 2,071.8 ms (`1,031.0 + 1,040.8 ms`) | **316.7 ms** (`160.4 + 156.3 ms`) | **6.54x faster** | | Total `vk: slow upload` (count / sum) | 36 uploads / 3,528.0 ms | **8 uploads / 451.9 ms** | **7.81x faster** | | Save-load slowest frame (`vk: status`) | 2,225.7 ms (`slow submit 2,193.8 ms`) | **578.2 ms** (`slow submit 454.7 ms`) | **3.85x faster** | | Perf report `uploads` (`Title` / `Kokiri`) | 2,194.6 ms (350 MB) / 1,617.1 ms (1,134 MB) | **562.5 ms (493 MB) / 404.5 ms (803 MB)** | **3.9x / 4.0x faster** | | `Kokiri` upload / memsync hitches | `texture_upload: 5`, `memsync: 5` | **`texture_upload: 3`, `memsync: 0`** | `-2` / `-5` | | Errors (`device_lost` / `program_failed` / `draws_left_out`) | `0` / `0` / `0` | `0` / `0` / `0` | Clean | **Note on tester's audio/stuttering report:** The tester reported *"had a really bad audio/stuttering on this one for some reason"*. Checking the perf report (`1795320425-0.json`) and `longshot_log.txt`, the stutter was CPU/vcore scheduling contention (`game_cpu`) rather than ASTC uploads or GPU stalls: - It started on the `Title and intro` screen before gameplay ASTC decoding (`game_cpu: 7` vs. `0`, `movie.decode_ms: 909.7 ms` vs. `537.1 ms`, `movie.dropped: 168` vs. `106`, `slowest 230.6 ms` vs. `62.3 ms`). - Mid-session in Kokiri Forest (`samples[33..38]`, ~34–39 s), FPS dipped to `8–18 FPS` (`slowest 370.9 ms`) while `gpu_ms` was only `149 ms / 1,008 ms`, with `game_cpu: 10` hitches (vs. `4`) and large `vcores` OS waits (`BaseProcExecutor4 longest 743.3 ms`, `Resource Memory 389.2 ms`, `nn.npln.Worker 180.7 ms`, `sead::MainThread 129.8 ms`) plus `vk: GPU time` climbing from `~20 ms` to `25–33 ms` — consistent with transient background host load or laptop APU power/thermal throttling during that run (this PR only changes `gpu/vk/host_shaders/astc_decoder.comp`). Re-testing on a second clean run or on the Test Farm is still welcome to double-check. Key lines from `longshot_log.txt` (`pr-2194-bb3fa08a`): ```text [hos host] longshot pr-2194-bb3fa08a (source 70224aba) [hos host] vk: slow upload 160.4 ms: #337 0x10a0efa600 1365x1365x1 x90 levels 11 NVN 0x8e ASTC (BC3), 57825 of 57825 KB [hos host] vk: slow upload 156.3 ms: #338 0x10a4772c00 1365x1365x1 x90 levels 11 NVN 0x80 ASTC (BC3), 57825 of 57825 KB [hos host] vk: slow submit: 454.7 ms: draw 442.0 descriptors 440.2 texture lookups 439.4 uploads 319.8 programs 1.4 queue submit 1.9 [hos host] vk: status: 600 frames, the slowest 230.6 ms; VRAM 0.4 of 10.2 GB [hos host] vk: status: 600 frames, the slowest 578.2 ms; VRAM 3.4 of 10.2 GB; AMD FSR 4: ... [hos host] vk: status: 600 frames, the slowest 225.1 ms; VRAM 4.0 of 10.2 GB; AMD FSR 4: ... [hos host] vk: status: 600 frames, the slowest 370.9 ms; VRAM 4.0 of 10.2 GB; AMD FSR 4: ... [hos BaseProcExecutor4] vcores: 145175 takes, 63077 waits (mean 127 us, longest 743.3 ms, 3 over HOS_VCORE_LOG_MS), ... [hos sead::MainThread] vcores: 99554 takes, 25478 waits (mean 129 us, longest 129.8 ms, 6 over HOS_VCORE_LOG_MS), ... [hos host] vk: program census (close): ... in play: 21 program records loaded (2.2 ms), 0 new graphics pipelines, pipelines from the driver's cache 15, from the start's cache 0, compiled 0; 0 draws and dispatches left out, 0 waits (0.0 ms) ```
Author
Contributor

Side-by-side real-time wall-clock comparisons (Before: main @ 9e10f6f7 vs After: this PR @ bb3fa08a, HOS_HEADLESS=1, RX_VK_SHOT_MENU=1, RX_VK_PRECOMPILE=0):

  1. Save-load startup (0.50 s pre-roll before clicking Load; timer starts at t = 0.00 s on Load click): ASTC 1365x1365x90 drops 2,299 ms -> 389 ms, max stall 2,563 ms -> 634 ms, and the Dev FPS counter's 10 s 1% low drops 2,843 ms -> 359 ms. (Note: the -6.15 s gap in this single capture also includes a 2.58 s program-load hiccup on main; across 3 unprofiled interleaved runs, Load click to in-play improved 10.83 s -> 8.55 s, -2.28 s / -21.0%.)

Save-load Dev FPS comparison

  1. Market traversal FPS & frame-time graph (+95.4% unprofiled 1% low zone: 14.66 -> 28.64 FPS, >=50 ms frames 16 -> 4): tightly cropped to the FPS / 1% low / 100 ms frame-time graph with dimmed background for comfortable viewing across the 30 s Market tour.

Market FPS and frame-time graph comparison

Side-by-side real-time wall-clock comparisons (`Before: main @ 9e10f6f7` vs `After: this PR @ bb3fa08a`, `HOS_HEADLESS=1`, `RX_VK_SHOT_MENU=1`, `RX_VK_PRECOMPILE=0`): 1. **Save-load startup (`0.50 s` pre-roll before clicking Load; timer starts at `t = 0.00 s` on Load click):** `ASTC 1365x1365x90` drops `2,299 ms -> 389 ms`, max stall `2,563 ms -> 634 ms`, and the Dev FPS counter's 10 s `1% low` drops `2,843 ms -> 359 ms`. *(Note: the `-6.15 s` gap in this single capture also includes a `2.58 s` program-load hiccup on `main`; across 3 unprofiled interleaved runs, Load click to in-play improved `10.83 s -> 8.55 s`, `-2.28 s / -21.0%`.)* ![Save-load Dev FPS comparison](https://git.magicbean.dev/attachments/b6141319-340e-4fc3-9e52-250d194f6596) 2. **Market traversal FPS & frame-time graph (`+95.4%` unprofiled 1% low zone: `14.66 -> 28.64 FPS`, `>=50 ms` frames `16 -> 4`):** tightly cropped to the FPS / `1% low` / 100 ms frame-time graph with dimmed background for comfortable viewing across the 30 s Market tour. ![Market FPS and frame-time graph comparison](https://git.magicbean.dev/attachments/73757700-5b13-4833-98d2-cd9df0a341f8)
dazemc left a comment

The 1% low headline is measured against 9e10f6f7, not current main a2dc5385. The head bb3fa08a is based on 9e10f6f7; current main has #2174 (8dce60ed), which removes Hyrule Field's 250 ms stalls on area entry — exactly what the 3-zone "before" 1% lows and the >=50 ms frame counts include. The after at this head also lacks #2174. The ASTC decode/upload numbers are isolated and should hold, but the +48.5% aggregate, the Hyrule Field row and the frames >=50 ms delta are not a current-main comparison; rebase and re-measure those rows, or state the baseline is pre-#2174. The checklist's "on current main" is not true in substance.

"100% bit-exact" is against the spec reference, not main. The PR notes the baseline differs from main by color_endpoint_data = uvec4(0u); that is the intentional fix of an uninitialized read. Say "bit-exact against the spec reference; one deliberate difference from main" so the TL;DR cannot be read as main-identical.

The bit-exact decode verification is not in the repo. tests/test_host_shaders.py only recompiles the SPIR-V; the ASTC tests cover upload/BC scratch, not decoded pixels. The 1,695,694-pixel verification is a standalone harness, so a later shader edit has no CI red. A small committed game-free decode fixture (all 14 block sizes, odd sizes, dual-plane, error blocks) would pin the claim.

"All desktop and laptop AMD, NVIDIA, Intel" is not yet evidenced. Only AMD RDNA 3.5 (860M, plus the 880M comment) ran; NVIDIA Warp32, Intel Xe SIMD16/32, RADV/ACO and Linux are still to test. The shared uint s_buf[16][65] shape reads correctly: 64 invocations, columns 0..63, 4,160 B, per-thread ownership and no cross-thread barrier; result_index max 64 lands in row 15. But the player-facing "Players on … AMD, NVIDIA, Intel" should be "AMD tested; other compilers pending" until those runs.

The independent 880M "stock" is pr-2193-e4ad718b, not main. The shader is unmodified main, but the rest of #2193 can affect upload/queue timing; the 6.54x/7.81x is a sibling-PR comparison, not a second main comparison. Keep the primary main table as the main claim.

No new switch; the path is on for every non-ASTC GPU, with RX_VK_ASTC_CPU=1 only as a slower diagnostic and reverting as the fallback. No approval, no fix claim.

**The 1% low headline is measured against `9e10f6f7`, not current main `a2dc5385`.** The head `bb3fa08a` is based on `9e10f6f7`; current main has #2174 (`8dce60ed`), which removes Hyrule Field's 250 ms stalls on area entry — exactly what the 3-zone "before" 1% lows and the `>=50 ms` frame counts include. The after at this head also lacks #2174. The ASTC decode/upload numbers are isolated and should hold, but the **+48.5% aggregate**, the **Hyrule Field** row and the **frames >=50 ms** delta are not a current-main comparison; rebase and re-measure those rows, or state the baseline is pre-#2174. The checklist's "on current main" is not true in substance. **"100% bit-exact" is against the spec reference, not main.** The PR notes the baseline differs from main by `color_endpoint_data = uvec4(0u)`; that is the intentional fix of an uninitialized read. Say "bit-exact against the spec reference; one deliberate difference from main" so the TL;DR cannot be read as main-identical. **The bit-exact decode verification is not in the repo.** `tests/test_host_shaders.py` only recompiles the SPIR-V; the ASTC tests cover upload/BC scratch, not decoded pixels. The 1,695,694-pixel verification is a standalone harness, so a later shader edit has no CI red. A small committed game-free decode fixture (all 14 block sizes, odd sizes, dual-plane, error blocks) would pin the claim. **"All desktop and laptop AMD, NVIDIA, Intel" is not yet evidenced.** Only AMD RDNA 3.5 (860M, plus the 880M comment) ran; NVIDIA Warp32, Intel Xe SIMD16/32, RADV/ACO and Linux are still to test. The `shared uint s_buf[16][65]` shape reads correctly: 64 invocations, columns 0..63, 4,160 B, per-thread ownership and no cross-thread barrier; `result_index` max 64 lands in row 15. But the player-facing "Players on … AMD, NVIDIA, Intel" should be "AMD tested; other compilers pending" until those runs. **The independent 880M "stock" is `pr-2193-e4ad718b`, not main.** The shader is unmodified main, but the rest of #2193 can affect upload/queue timing; the 6.54x/7.81x is a sibling-PR comparison, not a second main comparison. Keep the primary main table as the main claim. No new switch; the path is on for every non-ASTC GPU, with `RX_VK_ASTC_CPU=1` only as a slower diagnostic and reverting as the fallback. No approval, no fix claim.
Jer9 force-pushed perf/vk-astc-shaders from bb3fa08ad7
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 9s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to 3dd1f448a7
Some checks failed
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 1m0s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
2026-11-22 14:27:06 +00:00
Compare
Author
Contributor

Thanks for the review @dazemc! I've rebased onto main @ a2dc5385 and addressed each point in 3dd1f448:

  1. Committed game-free Vulkan ASTC decode fixture (tests/test_astc_decoder_gpu.py + tests/astc_decoder_gpu.cpp):
    • Follows the tests/test_vulkan_copy_span.py pattern (RUN_ALL_ARGS = ["--cxx", "{cxx}", "--headers", "{vulkan_headers}"]), leaving tests/test_vulkan_fixtures_ci.py untouched and passing (11/11 OK).
    • Default mode (no GPU required) compiles against gpu/vk/host_shaders/astc_decoder_comp_spv.h and gpu/third_party/suyu/video_core/textures/astc.cpp, validates the embedded SPIR-V header, and runs the CPU ASTC reference across all 14 block sizes.
    • --gpu / --gpu-device <substr> dispatches the real compiled ASTC_DECODER_COMP_SPV compute shader on Vulkan across all 14 ASTC block sizes (4x4..12x12), odd image dimensions, linear and Switch 2 native tiling, 1–4 partitions, dual-plane (all 4 secondary channels), void-extent LDR, and error blocks (28 readback cases, 22,680 pixels), comparing against Tegra::Texture::ASTC::DecompressSerial (0 tolerance on replicated-byte void-extent and error blocks; <= 1 LSB on interpolated LDR to account for astc.cpp's 255 * C / 65536 vs Vulkan R8G8B8A8_UNORM's C / 65535 rounding). Verified passing on AMD Radeon 860M in both default and --gpu modes, alongside scripts/shaders.py host --check (host shaders: 4 match) and the existing ASTC/BC/shader tests.
  2. PR description wording:
    • Replaced "100% bit-exact" in Summary and Verdict with "bit-exact against the ASTC spec reference (one deliberate UB fix vs. main: initializing color_endpoint_data = uvec4(0u))".
    • Tightened the hardware scope wording in Summary and Risks from blanket vendor claims to "targets non-ASTC GPUs (AMD RDNA 3.5 tested; NVIDIA Warp32, Intel Xe, and Linux RADV/ACO pending Test Farm)".
    • Added a rebase note explaining why the main @ 9e10f6f7 numbers still hold on main @ a2dc5385 (#2174 did not affect our Kokiri Forest -> Hyrule Field -> Market tour: Hyrule Field max_ms on main @ 9e10f6f7 was 30.94 / 71.01 / 72.49 ms, gt_50ms 0 / 4 / 4, zero 250 ms turf stalls).
  3. 880M comparison note: Acknowledged — the Radeon 880M comparison in the earlier comment is supplemental sibling-PR context only; the standalone Before: main @ 9e10f6f7 table in the PR description remains the primary claim.
Thanks for the review @dazemc! I've rebased onto `main @ a2dc5385` and addressed each point in `3dd1f448`: 1. **Committed game-free Vulkan ASTC decode fixture (`tests/test_astc_decoder_gpu.py` + `tests/astc_decoder_gpu.cpp`):** - Follows the `tests/test_vulkan_copy_span.py` pattern (`RUN_ALL_ARGS = ["--cxx", "{cxx}", "--headers", "{vulkan_headers}"]`), leaving `tests/test_vulkan_fixtures_ci.py` untouched and passing (`11/11 OK`). - Default mode (no GPU required) compiles against `gpu/vk/host_shaders/astc_decoder_comp_spv.h` and `gpu/third_party/suyu/video_core/textures/astc.cpp`, validates the embedded SPIR-V header, and runs the CPU ASTC reference across all 14 block sizes. - `--gpu` / `--gpu-device <substr>` dispatches the real compiled `ASTC_DECODER_COMP_SPV` compute shader on Vulkan across all 14 ASTC block sizes (`4x4..12x12`), odd image dimensions, linear and Switch 2 native tiling, 1–4 partitions, dual-plane (all 4 secondary channels), void-extent LDR, and error blocks (`28` readback cases, `22,680` pixels), comparing against `Tegra::Texture::ASTC::DecompressSerial` (`0` tolerance on replicated-byte void-extent and error blocks; `<= 1` LSB on interpolated LDR to account for `astc.cpp`'s `255 * C / 65536` vs Vulkan `R8G8B8A8_UNORM`'s `C / 65535` rounding). Verified passing on AMD Radeon 860M in both default and `--gpu` modes, alongside `scripts/shaders.py host --check` (`host shaders: 4 match`) and the existing ASTC/BC/shader tests. 2. **PR description wording:** - Replaced `"100% bit-exact"` in Summary and Verdict with `"bit-exact against the ASTC spec reference (one deliberate UB fix vs. main: initializing color_endpoint_data = uvec4(0u))"`. - Tightened the hardware scope wording in Summary and Risks from blanket vendor claims to `"targets non-ASTC GPUs (AMD RDNA 3.5 tested; NVIDIA Warp32, Intel Xe, and Linux RADV/ACO pending Test Farm)"`. - Added a rebase note explaining why the `main @ 9e10f6f7` numbers still hold on `main @ a2dc5385` (`#2174` did not affect our `Kokiri Forest -> Hyrule Field -> Market` tour: Hyrule Field `max_ms` on `main @ 9e10f6f7` was `30.94 / 71.01 / 72.49 ms`, `gt_50ms` `0 / 4 / 4`, zero 250 ms turf stalls). 3. **880M comparison note:** Acknowledged — the Radeon 880M comparison in the earlier comment is supplemental sibling-PR context only; the standalone `Before: main @ 9e10f6f7` table in the PR description remains the primary claim.
Jer9 force-pushed perf/vk-astc-shaders from 3dd1f448a7
Some checks failed
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 1m0s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to 28beeb4d71
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval approved by HumanBean (reviewed)
beanstalk/any 0/1 pass, 0 running, 0 queued
2026-11-22 14:37:11 +00:00
Compare
Owner

Tested in game: Linux (CachyOS, kernel 7.3), RTX 3090 24 GB, NVIDIA proprietary driver, Ryzen 9 7900X. Headless through the job queue (timing mode), Render resolution fixed at 67 %, uncapped (HOS_FPS_MAX=1000), V-Sync off, default settings otherwise (RX_VK_PRECOMPILE unset).

Verdict: the terrain arrays decode about 1.6x faster on this card, with nothing worse and no corruption seen; the frame-time effect here is small (a fast desktop GPU), as expected. This PR @ bb3fa08a against main @ 9e10f6f7 (its merge base), the same base and pack layer, interleaved main / PR rounds after a warm-up run of the PR's runtime. The PR's first measured run is left out: its pipeline cache was still cold (62k draws left out in Market, the same on #2193's runtime, which shares nothing with this change).

Routine: kokiri-start save, 12 s settle, teleport to Kokiri Forest, Market and Hyrule Field with a 10 s camera spin in each, back to Kokiri Forest, then three pause menus (PLUS, 4 s, PLUS, 5 s measured).

main @ 9e10f6f7 (3 runs) this PR (2 runs)
The two 1365x1365x90 ASTC terrain arrays, slow upload ms (both together) 155 / 178 / 133 101 / 97
Save load: worst frame 222 / 251 / 312 ms 195 / 184 ms
Save load: first frame to in play 32.9 / 32.9 / 33.3 s 32.8 / 33.1 s
Tour (3 zones with their teleports): fps, p99 135.5 / 133.1 / 114.1 fps, 29.0 / 27.5 / 31.0 ms 134.2 / 128.1 fps, 25.3 / 25.5 ms
Tour frames >= 50 ms 41 / 38 / 38 31 / 31
After the menus: fps, p99 118.7–119.2 fps, 11.1–13.1 ms 123.2 / 122.9 fps, 11.9 / 10.9 ms
Device lost, crashes 0 0
  • The arrays this targets are 64–93 ms each on main and 42–58 ms here. On the 860M of the description they were 2.3 s; a 3090 decodes them fast enough that the save-load stall it removes there is barely there to begin with, so the frame-time rows are mostly within the spread (p99 and frames >= 50 ms lean the PR's way).
  • Every build, main included, shows one or two isolated slow upload of ~730 ms (and once 2.2 s on this PR) for a single small ASTC texture; they come and go between runs of the same build, so I don't count them for or against this change.
  • Pictures: screenshots in Link's house, Kokiri Forest, Market, Hyrule Field and after the menus show no corruption, colour error or missing terrain against main (the camera spin leaves different angles, so no pixel comparison). Not attached (the game's frames).

Not tested here: AMD (RADV), Intel, the 860M's own numbers.

Tested in game: Linux (CachyOS, kernel 7.3), RTX 3090 24 GB, NVIDIA proprietary driver, Ryzen 9 7900X. Headless through the job queue (timing mode), Render resolution fixed at 67 %, uncapped (`HOS_FPS_MAX=1000`), V-Sync off, default settings otherwise (`RX_VK_PRECOMPILE` unset). **Verdict: the terrain arrays decode about 1.6x faster on this card, with nothing worse and no corruption seen; the frame-time effect here is small (a fast desktop GPU), as expected.** This PR @ bb3fa08a against `main` @ 9e10f6f7 (its merge base), the same base and pack layer, interleaved main / PR rounds after a warm-up run of the PR's runtime. The PR's first measured run is left out: its pipeline cache was still cold (62k draws left out in Market, the same on #2193's runtime, which shares nothing with this change). Routine: `kokiri-start` save, 12 s settle, teleport to Kokiri Forest, Market and Hyrule Field with a 10 s camera spin in each, back to Kokiri Forest, then three pause menus (PLUS, 4 s, PLUS, 5 s measured). | | main @ 9e10f6f7 (3 runs) | this PR (2 runs) | |---|---|---| | The two 1365x1365x90 ASTC terrain arrays, `slow upload` ms (both together) | 155 / 178 / 133 | **101 / 97** | | Save load: worst frame | 222 / 251 / 312 ms | 195 / 184 ms | | Save load: first frame to in play | 32.9 / 32.9 / 33.3 s | 32.8 / 33.1 s | | Tour (3 zones with their teleports): fps, p99 | 135.5 / 133.1 / 114.1 fps, 29.0 / 27.5 / 31.0 ms | 134.2 / 128.1 fps, 25.3 / 25.5 ms | | Tour frames >= 50 ms | 41 / 38 / 38 | 31 / 31 | | After the menus: fps, p99 | 118.7–119.2 fps, 11.1–13.1 ms | 123.2 / 122.9 fps, 11.9 / 10.9 ms | | Device lost, crashes | 0 | 0 | - The arrays this targets are 64–93 ms each on `main` and 42–58 ms here. On the 860M of the description they were 2.3 s; a 3090 decodes them fast enough that the save-load stall it removes there is barely there to begin with, so the frame-time rows are mostly within the spread (p99 and frames >= 50 ms lean the PR's way). - Every build, `main` included, shows one or two isolated `slow upload` of ~730 ms (and once 2.2 s on this PR) for a single small ASTC texture; they come and go between runs of the same build, so I don't count them for or against this change. - Pictures: screenshots in Link's house, Kokiri Forest, Market, Hyrule Field and after the menus show no corruption, colour error or missing terrain against `main` (the camera spin leaves different angles, so no pixel comparison). Not attached (the game's frames). Not tested here: AMD (RADV), Intel, the 860M's own numbers.
Owner

@Beanstalk

@Beanstalk
Member

Beanstalk test farm · 🔄 testing (0 of 1 report so far)

Commit 28beeb4 · approved by HumanBean (reviewed) · dashboard

⚠️ Note: The farm plan does not run the game-free ASTC reference fixture or isolate individual decode/upload timings; the load and frame metrics are indirect measures.
⚠️ Note: Picture differences can include animation or time-of-day drift, and the intentional decoder initialization fix may also differ from main.

Done (started 16:17 UTC). Comment @Beanstalk to run it again.

Target Result Reports Frame time p99 (ms), main → PR VRAM peak (MB) Crashes
any ⏳ queued 0 of 1 — — —
What was tested

What will be tested · AI plan (gpt-6.1-terra)

Compare the PR with main during a Kokiri Forest, Hyrule Field and Market tour, including the Kokiri save load, in about 30 minutes per tester. The plan measures load time, whole-run hitches and 1% low frame times, and compares pictures for texture corruption. Crashes, device loss, substantial visual differences or regressions beyond the performance limits fail the plan.

  • Where: any (any PC, 1-2 reports).
  • astc-zone-tour: from the repository's save kokiri-start, then teleport to Kokiri Forest, take the picture kokiri to compare with main, measure kokiri for 10 s (after 2 s warm-up), teleport to Hyrule Field, take the picture field to compare with main, measure field for 10 s (after 2 s warm-up), teleport to Market, take the picture market to compare with main, measure market for 10 s (after 2 s warm-up); 3 runs on each side.
  • Measured: crashes, frame times, stutters and hitches, load times, the game's log.
  • The PR fails if: it crashes; or a picture differs from main by more than 12%; or longest load is more than 20% above main; or forbidden log lines is above 0; or worst frame time in the whole run is more than 25% above main; or frame time (worst 1%) is more than 20% above main.
  • Time: about 34 min of game runs per tester (6 game starts), plus the two builds.
<!-- beanstalk:sticky --> ### Beanstalk test farm · 🔄 testing (0 of 1 report so far) Commit `28beeb4` · approved by HumanBean (reviewed) · [dashboard](https://beanstalk.magicbean.dev/prs/2194) ⚠️ **Note:** The farm plan does not run the game-free ASTC reference fixture or isolate individual decode/upload timings; the load and frame metrics are indirect measures. ⚠️ **Note:** Picture differences can include animation or time-of-day drift, and the intentional decoder initialization fix may also differ from main. Done (started 16:17 UTC). Comment `@Beanstalk` to run it again. | Target | Result | Reports | Frame time p99 (ms), main → PR | VRAM peak (MB) | Crashes | | --- | --- | --- | --- | --- | --- | | `any` | ⏳ queued | 0 of 1 | — | — | — | <details><summary>What was tested</summary> **What will be tested** · AI plan (`gpt-6.1-terra`) Compare the PR with main during a Kokiri Forest, Hyrule Field and Market tour, including the Kokiri save load, in about 30 minutes per tester. The plan measures load time, whole-run hitches and 1% low frame times, and compares pictures for texture corruption. Crashes, device loss, substantial visual differences or regressions beyond the performance limits fail the plan. - **Where:** any (any PC, 1-2 reports). - **astc-zone-tour:** from the repository's save `kokiri-start`, then teleport to Kokiri Forest, take the picture kokiri to compare with main, measure kokiri for 10 s (after 2 s warm-up), teleport to Hyrule Field, take the picture field to compare with main, measure field for 10 s (after 2 s warm-up), teleport to Market, take the picture market to compare with main, measure market for 10 s (after 2 s warm-up); 3 runs on each side. - **Measured:** crashes, frame times, stutters and hitches, load times, the game's log. - **The PR fails if:** it crashes; or a picture differs from main by more than 12%; or longest load is more than 20% above main; or forbidden log lines is above 0; or worst frame time in the whole run is more than 25% above main; or frame time (worst 1%) is more than 20% above main. - **Time:** about 34 min of game runs per tester (6 game starts), plus the two builds. </details>
HumanBean left a comment

Recommendation: Wait (on the Beanstalk run in progress and one Tier 1 RADV run, Steam Deck or RX 6000+). The rewrite reads correct against the old shader everywhere I checked, and its gain is real and large on AMD APUs and visible on an RTX 3090. Mesa's ACO is a different compiler from the two this has run on, and Tier 1 hardware is tested before merge. I would approve once those runs are clean; there is nothing in the code to change first.

For players on GPUs without hardware ASTC (every desktop GPU), the ASTC decode shader stops spilling its scratch arrays to VRAM. Large terrain arrays decode several times faster, so save loads stall less and texture-heavy areas have fewer upload hitches. The code gets better: the same algorithm with block-invariant work hoisted, a direct-grid fast path, and one real uninitialised read fixed. It adds no switch and no new path.

Does it help: Yes.

  • Radeon 860M, Windows (3 interleaved runs each, against its merge base 9e10f6f7): the two 1365x1365x90 arrays decode in 432 ms instead of 2,309 ms. The spreads don't overlap ([338, 451] against [2,306, 2,525]). Save-load max frame time goes from 2,423 to 573 ms. Traversal 1% lows go from 21.71 to 32.25 fps, with non-overlapping spreads ([13.2, 26.5] against [29.0, 34.0]), and frames of 50 ms or more drop from 32 to 7.
  • RTX 3090, Linux, NVIDIA driver (HumanBean, 3 main runs and 2 PR runs): the arrays take 97–101 ms here against 133–178 ms on main, about 1.6x faster. Frame-time rows are within the spread and lean the PR's way (tour p99 25.3/25.5 ms against 27.5–31.0 ms; frames of 50 ms or more 31/31 against 38–41). No corruption in screenshots, no device loss.
  • Radeon 880M: the 6.5x there is against a sibling PR's runtime, not against main, as already noted.

The base is pre-#2174. That doesn't touch the decode numbers, which are the claim this change rests on.

Other systems:

  • NVIDIA: tested on the 3090 (Linux).
  • AMD dGPUs and Steam Deck on RADV/ACO (Tier 1): not run. The code has no vendor branch, and ACO also spills large dynamically indexed arrays to scratch, so a gain is likely. Correctness and speed under ACO still need one run.
  • Windows AMD dGPUs (LLPC): likely the same as the 860M.
  • Intel Arc/Xe (Tier 2): not run. SIMD8/16/32 doesn't matter here, because no lane reads another lane's shared memory.
  • GCN cards such as the RX 580 (Tier 3): 4,160 B per workgroup caps a 64 KB CU at 15 workgroups (960 of 2,560 lanes). That is probably still far better than scratch spills, but nobody has measured it.
  • Unaffected: GPUs with native ASTC never run this shader. The RX_VK_ASTC_CPU=1 CPU path is untouched. The BC re-encode downstream reads the same RGBA. VRAM is unchanged (the scratch is on-chip shared memory). The build is unchanged (the SPIR-V is prebuilt). The only one-off cost is a driver pipeline compile of the new SPIR-V.

Switches: none.

Reviewed: head 28beeb4d against its merge base a2dc5385. The shader commit 108d98b0 is identical to the earlier head bb3fa08a apart from the rebase (git diff bb3fa08a 108d98b0 only shows main's own changes).

  • Read in full: gpu/vk/host_shaders/astc_decoder.comp, compared function by function with the old file; tests/test_astc_decoder_gpu.py.
  • Read in part: tests/astc_decoder_gpu.cpp (block builders, CPU-only mode, GPU compare loop, loader use).
  • Skimmed: astc_decoder_comp_spv.h (its opening comment and its format only, not the words).
  • Run: nothing (a code review).

Fixed in this review: nothing.

Checked and fine:

  • Shared-memory sizing: local_size is 8x8x1, and both dispatch sites in vk_texture.cpp use (n + 7) / 8. So gl_LocalInvocationIndex is 0..63, under the 65 columns.
  • Row bounds: result_index is capped at result_vector_max_index, which is at most 64 for weights and min(32, n) for colours. EmitByte only writes rows 0..15. FlushBytes only writes on a partial word, so result_index == 64 never touches row 16.
  • Footprint: 16 × 65 × 4 = 4,160 B, well under Vulkan's guaranteed 16,384 B maxComputeSharedMemorySize.
  • No barriers needed: each invocation reads and writes only its own column, so program order makes its own writes visible. With no barrier(), the early returns in main are legal, and wave or subgroup size (Intel SIMD8/16/32, AMD wave32/64, NVIDIA 32) can't change the result. The stride of 65 keeps one row's 64 lanes on distinct banks.
  • No stale reads: every byte read was written in the same phase. Colours read up to num_values entries and all are emitted. Weight reads are below num_weight_vals, with the dual-plane 2*idx+1 under 2*area, and the scaled-grid reads are guarded by < area as before. A new word starts pack_word from zero.
  • Binary search: it finds the same range as the old linear scan. GetBitLength(n, i) is non-decreasing in i for every n: the table interleaves J(k+1) ≤ T(k) ≤ J(k+2) ≤ Q(k) ≤ T(k+1), and the ceil terms keep that order. Index 0 (0 bits) always fits, hi = 21 is the last index, and mid = (lo + hi + 1) >> 1 ends.
  • Direct-grid fast path: when the weight grid equals the block size, the old gs/gt maths gives fs = ft = 0 and js = s for all 14 block widths. I worked it out for 4, 5, 6, 8, 10 and 12: Ds*(b-1) is between 1022 and 1026, so the error stays inside the +32 rounding. That makes it bit-identical to the bilinear path. It is only taken when the area is 64 or less.
  • Partitions: shifting the seeds left by one instead of x and y gives the same values mod 64. c and d are zeroed for fewer than 3 or 4 partitions as before, and the select order is unchanged.
  • Dual plane: sec_chan = (plane_index + 1) & 3 on the (a, r, g, b) endpoint layout, the same as before. Plane weights are interleaved as before.
  • HDR and mixed blocks: with any_hdr, the endpoints stay raw and EvalHDRTexel shifts them by 4. LDR partitions in a mixed block still go through ReplicateByteTo16. The CEM 14 alpha uses * 0x101 as before.
  • Void extent and error blocks: unchanged apart from the edge clipping.
  • Image edges: max_x/max_y clip edge blocks just as StoreTexel did, so the RX 6750 XT out-of-bounds fix is kept.
  • Weight-stream mask: it keeps exactly the low weight_bits bits, like the old byte-clearing loop, including at 32, 64 and 96.
  • color_endpoint_data = uvec4(0u): a real fix. The old private global had no initialiser, and the trit/quint reader can read one word past color_data_bits.
  • / 65535.0f replaced by * (1/65535.0f): this can move the float by one ulp, which can't flip a UNORM8 rounding (C/257 is never within 0.002 of a .5). Most drivers fold the division that way anyway.
  • Generated header: it keeps its hand-kept opening comment and is marked as made by scripts/shaders.py host. CI's tests/test_host_shaders.py recompiles it with the pinned glslang 16.6.0 on Linux and compares the SPIR-V, so a stale header goes red there. That job is pending on this head.
  • The new test: it does only what its docstring says. It compiles with the repository's compiler, dlopens the Vulkan loader only under --gpu, and writes only to a temporary folder.

Suggestions (the author may take or leave)

  • gpu/vk/host_shaders/astc_decoder.comp:77: s_buf's 64 columns depend on local_size 8x8 in another line of the file. Name it once, for example #define WG_SIZE 64u with shared uint s_buf[16][WG_SIZE + 1u]. Then a later change to the workgroup size can't overrun the columns silently.
  • tests/test_astc_decoder_gpu.py:4: the default (CI) mode checks the SPIR-V magic number and runs suyu's CPU astc.cpp. It never runs this shader, so a later shader edit that breaks decoding still passes CI; only --gpu checks the PR's code. Say that in the docstring and the description ("CI checks the reference; run --gpu after editing the shader"), or add it where a GPU runner exists.
  • tests/astc_decoder_gpu.cpp:122: the comment above encode_block_mode (lines 122–145) is a draft of the author's reasoning ("wait", "Let's check exact bits!", and contradictory layouts). Replace it with the two layouts the function actually uses.
  • gpu/vk/host_shaders/astc_decoder_comp_spv.h:11: the provenance comment lists the Eden and Eglantine authors. Add that Longshot reworked it here (#2194: LDS scratch, hoisting), since a future upstream sync has to merge by hand.
  • The GPU fixture covers LDR CEMs 0, 4, 6, 8, 10, 12 and 13. The HDR CEMs (2, 3, 7, 11, 14, 15) and CEMs 1, 5 and 9 are only in the standalone harness. A few HDR cases would pin the any_hdr split.

Testing:

  • Run so far:
    • Jer9: Radeon 860M on Windows; game-free --gpu fixture on the 860M.
    • nwgat: Radeon 880M, against a sibling-PR baseline.
    • HumanBean: RTX 3090 on Linux (NVIDIA driver), 1.6x decode, no corruption.
  • In progress: Beanstalk, 0 of 1 report.
  • Missing: RADV/ACO on an AMD dGPU or the Steam Deck (Tier 1), and Intel (Tier 2). The Tier 1 run holds the merge.
  • CI: pending on 28beeb4d.

Overlaps and merge order: none found.

**Recommendation: Wait (on the Beanstalk run in progress and one Tier 1 RADV run, Steam Deck or RX 6000+).** The rewrite reads correct against the old shader everywhere I checked, and its gain is real and large on AMD APUs and visible on an RTX 3090. Mesa's ACO is a different compiler from the two this has run on, and Tier 1 hardware is tested before merge. I would approve once those runs are clean; there is nothing in the code to change first. For players on GPUs without hardware ASTC (every desktop GPU), the ASTC decode shader stops spilling its scratch arrays to VRAM. Large terrain arrays decode several times faster, so save loads stall less and texture-heavy areas have fewer upload hitches. The code gets better: the same algorithm with block-invariant work hoisted, a direct-grid fast path, and one real uninitialised read fixed. It adds no switch and no new path. **Does it help:** Yes. - **Radeon 860M, Windows** (3 interleaved runs each, against its merge base `9e10f6f7`): the two 1365x1365x90 arrays decode in 432 ms instead of 2,309 ms. The spreads don't overlap ([338, 451] against [2,306, 2,525]). Save-load max frame time goes from 2,423 to 573 ms. Traversal 1% lows go from 21.71 to 32.25 fps, with non-overlapping spreads ([13.2, 26.5] against [29.0, 34.0]), and frames of 50 ms or more drop from 32 to 7. - **RTX 3090, Linux, NVIDIA driver** (HumanBean, 3 main runs and 2 PR runs): the arrays take 97–101 ms here against 133–178 ms on main, about 1.6x faster. Frame-time rows are within the spread and lean the PR's way (tour p99 25.3/25.5 ms against 27.5–31.0 ms; frames of 50 ms or more 31/31 against 38–41). No corruption in screenshots, no device loss. - **Radeon 880M:** the 6.5x there is against a sibling PR's runtime, not against main, as already noted. The base is pre-[#2174](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2174). That doesn't touch the decode numbers, which are the claim this change rests on. **Other systems:** - **NVIDIA:** tested on the 3090 (Linux). - **AMD dGPUs and Steam Deck on RADV/ACO (Tier 1):** not run. The code has no vendor branch, and ACO also spills large dynamically indexed arrays to scratch, so a gain is likely. Correctness and speed under ACO still need one run. - **Windows AMD dGPUs (LLPC):** likely the same as the 860M. - **Intel Arc/Xe (Tier 2):** not run. SIMD8/16/32 doesn't matter here, because no lane reads another lane's shared memory. - **GCN cards such as the RX 580 (Tier 3):** 4,160 B per workgroup caps a 64 KB CU at 15 workgroups (960 of 2,560 lanes). That is probably still far better than scratch spills, but nobody has measured it. - **Unaffected:** GPUs with native ASTC never run this shader. The `RX_VK_ASTC_CPU=1` CPU path is untouched. The BC re-encode downstream reads the same RGBA. VRAM is unchanged (the scratch is on-chip shared memory). The build is unchanged (the SPIR-V is prebuilt). The only one-off cost is a driver pipeline compile of the new SPIR-V. **Switches:** none. **Reviewed:** head `28beeb4d` against its merge base `a2dc5385`. The shader commit `108d98b0` is identical to the earlier head `bb3fa08a` apart from the rebase (`git diff bb3fa08a 108d98b0` only shows main's own changes). - **Read in full:** `gpu/vk/host_shaders/astc_decoder.comp`, compared function by function with the old file; `tests/test_astc_decoder_gpu.py`. - **Read in part:** `tests/astc_decoder_gpu.cpp` (block builders, CPU-only mode, GPU compare loop, loader use). - **Skimmed:** `astc_decoder_comp_spv.h` (its opening comment and its format only, not the words). - **Run:** nothing (a code review). **Fixed in this review:** nothing. **Checked and fine:** - **Shared-memory sizing:** `local_size` is 8x8x1, and both dispatch sites in `vk_texture.cpp` use `(n + 7) / 8`. So `gl_LocalInvocationIndex` is 0..63, under the 65 columns. - **Row bounds:** `result_index` is capped at `result_vector_max_index`, which is at most 64 for weights and `min(32, n)` for colours. `EmitByte` only writes rows 0..15. `FlushBytes` only writes on a partial word, so `result_index == 64` never touches row 16. - **Footprint:** 16 × 65 × 4 = 4,160 B, well under Vulkan's guaranteed 16,384 B `maxComputeSharedMemorySize`. - **No barriers needed:** each invocation reads and writes only its own column, so program order makes its own writes visible. With no `barrier()`, the early `return`s in `main` are legal, and wave or subgroup size (Intel SIMD8/16/32, AMD wave32/64, NVIDIA 32) can't change the result. The stride of 65 keeps one row's 64 lanes on distinct banks. - **No stale reads:** every byte read was written in the same phase. Colours read up to `num_values` entries and all are emitted. Weight reads are below `num_weight_vals`, with the dual-plane `2*idx+1` under `2*area`, and the scaled-grid reads are guarded by `< area` as before. A new word starts `pack_word` from zero. - **Binary search:** it finds the same range as the old linear scan. `GetBitLength(n, i)` is non-decreasing in `i` for every `n`: the table interleaves J(k+1) ≤ T(k) ≤ J(k+2) ≤ Q(k) ≤ T(k+1), and the ceil terms keep that order. Index 0 (0 bits) always fits, `hi = 21` is the last index, and `mid = (lo + hi + 1) >> 1` ends. - **Direct-grid fast path:** when the weight grid equals the block size, the old `gs`/`gt` maths gives `fs = ft = 0` and `js = s` for all 14 block widths. I worked it out for 4, 5, 6, 8, 10 and 12: `Ds*(b-1)` is between 1022 and 1026, so the error stays inside the +32 rounding. That makes it bit-identical to the bilinear path. It is only taken when the area is 64 or less. - **Partitions:** shifting the seeds left by one instead of x and y gives the same values mod 64. `c` and `d` are zeroed for fewer than 3 or 4 partitions as before, and the select order is unchanged. - **Dual plane:** `sec_chan = (plane_index + 1) & 3` on the `(a, r, g, b)` endpoint layout, the same as before. Plane weights are interleaved as before. - **HDR and mixed blocks:** with `any_hdr`, the endpoints stay raw and `EvalHDRTexel` shifts them by 4. LDR partitions in a mixed block still go through `ReplicateByteTo16`. The CEM 14 alpha uses `* 0x101` as before. - **Void extent and error blocks:** unchanged apart from the edge clipping. - **Image edges:** `max_x`/`max_y` clip edge blocks just as `StoreTexel` did, so the RX 6750 XT out-of-bounds fix is kept. - **Weight-stream mask:** it keeps exactly the low `weight_bits` bits, like the old byte-clearing loop, including at 32, 64 and 96. - **`color_endpoint_data = uvec4(0u)`:** a real fix. The old private global had no initialiser, and the trit/quint reader can read one word past `color_data_bits`. - **`/ 65535.0f` replaced by `* (1/65535.0f)`:** this can move the float by one ulp, which can't flip a UNORM8 rounding (C/257 is never within 0.002 of a .5). Most drivers fold the division that way anyway. - **Generated header:** it keeps its hand-kept opening comment and is marked as made by `scripts/shaders.py host`. CI's `tests/test_host_shaders.py` recompiles it with the pinned glslang 16.6.0 on Linux and compares the SPIR-V, so a stale header goes red there. That job is pending on this head. - **The new test:** it does only what its docstring says. It compiles with the repository's compiler, dlopens the Vulkan loader only under `--gpu`, and writes only to a temporary folder. **Suggestions** (the author may take or leave) - `gpu/vk/host_shaders/astc_decoder.comp:77`: `s_buf`'s 64 columns depend on `local_size` 8x8 in another line of the file. Name it once, for example `#define WG_SIZE 64u` with `shared uint s_buf[16][WG_SIZE + 1u]`. Then a later change to the workgroup size can't overrun the columns silently. - `tests/test_astc_decoder_gpu.py:4`: the default (CI) mode checks the SPIR-V magic number and runs suyu's CPU `astc.cpp`. It never runs this shader, so a later shader edit that breaks decoding still passes CI; only `--gpu` checks the PR's code. Say that in the docstring and the description ("CI checks the reference; run `--gpu` after editing the shader"), or add it where a GPU runner exists. - `tests/astc_decoder_gpu.cpp:122`: the comment above `encode_block_mode` (lines 122–145) is a draft of the author's reasoning ("wait", "Let's check exact bits!", and contradictory layouts). Replace it with the two layouts the function actually uses. - `gpu/vk/host_shaders/astc_decoder_comp_spv.h:11`: the provenance comment lists the Eden and Eglantine authors. Add that Longshot reworked it here ([#2194](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2194): LDS scratch, hoisting), since a future upstream sync has to merge by hand. - The GPU fixture covers LDR CEMs 0, 4, 6, 8, 10, 12 and 13. The HDR CEMs (2, 3, 7, 11, 14, 15) and CEMs 1, 5 and 9 are only in the standalone harness. A few HDR cases would pin the `any_hdr` split. **Testing:** - **Run so far:** - Jer9: Radeon 860M on Windows; game-free `--gpu` fixture on the 860M. - nwgat: Radeon 880M, against a sibling-PR baseline. - HumanBean: RTX 3090 on Linux (NVIDIA driver), 1.6x decode, no corruption. - **In progress:** Beanstalk, 0 of 1 report. - **Missing:** RADV/ACO on an AMD dGPU or the Steam Deck (Tier 1), and Intel (Tier 2). The Tier 1 run holds the merge. - **CI:** pending on `28beeb4d`. **Overlaps and merge order:** none found.
@ -75,0 +74,4 @@
// Wave32/Wave64 access) instead of dynamically-indexed private arrays that spill to VRAM scratch.
// Phase 1 holds <=32 decoded color values (0..255); Phase 2 holds <=64 unquantized weights (0..64).
// Each invocation accesses only its own column [tid], so no workgroup barrier() is needed.
shared uint s_buf[16][65];
Owner

Correct as it stands: local_size 8x8x1 gives tids 0..63 under 65 columns, and rows stay 0..15. But the 64 columns rely on local_size in another line. Naming it once, e.g. #define WG_SIZE 64u and shared uint s_buf[16][WG_SIZE + 1u], keeps a later workgroup-size change from overrunning them silently.

Correct as it stands: local_size 8x8x1 gives tids 0..63 under 65 columns, and rows stay 0..15. But the 64 columns rely on local_size in another line. Naming it once, e.g. `#define WG_SIZE 64u` and `shared uint s_buf[16][WG_SIZE + 1u]`, keeps a later workgroup-size change from overrunning them silently.
@ -0,0 +119,4 @@
}
// Encode a valid ASTC block mode using Table C.2.8 layout 0:
// bits [1:0]=00, [3:2]=B (weight_h-2), [4]=R0, [6:5]=A (weight_w-4), [8:7]=R2:R1, [9]=H, [10]=D.
Owner

Nit: lines 122-145 are a draft of the reasoning ("wait", "Let's check exact bits!", contradictory layouts). Replace them with the two layouts the function actually uses (layout 0 and layout 4).

Nit: lines 122-145 are a draft of the reasoning ("wait", "Let's check exact bits!", contradictory layouts). Replace them with the two layouts the function actually uses (layout 0 and layout 4).
@ -0,0 +1,90 @@
# SPDX-License-Identifier: GPL-3.0-or-later
"""Game-free Vulkan ASTC decoder verification against Longshot's CPU ASTC reference.
Default mode (used by run_all.py, no GPU or Vulkan loader required):
Owner

The default (CI) mode checks the SPIR-V magic number and runs suyu's CPU astc.cpp; it never runs this shader. A later shader edit that breaks decoding still passes CI, and only --gpu checks it. Worth saying in the docstring and the PR description.

The default (CI) mode checks the SPIR-V magic number and runs suyu's CPU astc.cpp; it never runs this shader. A later shader edit that breaks decoding still passes CI, and only --gpu checks it. Worth saying in the docstring and the PR description.
HumanBean deleted branch perf/vk-astc-shaders 2026-11-22 16:28:30 +00:00
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval approved by HumanBean (reviewed)
beanstalk/any 0/1 pass, 0 running, 0 queued
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
5 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!2194
No description provided.