perf(vk): cut zone-entry ASTC upload spikes on non-ASTC GPUs via async chunk submits #2860

Merged
HumanBean merged 1 commit from HumanBean/Longshot:perf/vk-async-astc-upload-main into main 2026-11-30 03:28:17 +00:00
Owner

Summary

On GPUs without native ASTC (AMD, NVIDIA, Intel desktop), large ASTC textures are decoded on the GPU in 16M-texel chunks (RX_VK_ASTC_CHUNK_MPX). Each chunk boundary blocked the presentation thread on vkWaitForFences just to reuse one upload command buffer, so entering a zone (Hyrule Field's 1365 x 1365 x 90 terrain arrays) froze the frame: 68 ms of astc_flush_ms in one frame of a nightly-937 Kakariko capture on an RX 9070 XT, with uploads_ms of 185 ms in the worst frame.

This is Jer9's #2330, merged into mod-api, ported to main unchanged (a clean cherry-pick, author kept): each recording keeps a pool of up to 64 upload command buffers, each finished chunk is submitted at once without a fence, and all chunks retire together when the frame slot is reused. No new switch; it does nothing on GPUs that sample ASTC natively or with RX_VK_ASTC_CPU=1.

Read first: replay_flush_upload() in gpu/vk/vk_replay.cpp, then upload_astc_gpu() in gpu/vk/vk_texture.cpp.

Testing

Tested: not run in the game on this PC; opened with --force at the person's request. Game-free on Linux: tests/test_async_astc_upload_chunks.py (fails on main, passes here), test_astc_upload_chunking, test_astc_pass_timing, test_vk_braces, test_utf8_paths, test_doc_anchors, test_switches_removed. Three C++ checks (draw_stream_visibility, fsr_image_retirement, fsr_uniform_ownership) were skipped here for want of the Vulkan headers, and the renderer was not compiled on this PC. On mod-api, Jer9 ran it on Windows 11, Radeon 860M (Adrenalin 26.10.1): 3-zone tour, 0 device losses.

Still to test:

  • Linux, RADV/NVIDIA, Windows NVIDIA: Market -> Hyrule Field -> Kokiri Forest, expecting astc_flush_ms under 2 ms and no VK_ERROR_DEVICE_LOST (@Beanstalk)

Measurements

Verdict: from #2330 on mod-api, on a Radeon 860M: worst astc_flush_ms 332 ms -> 1.6 ms, total 1580 -> 12 ms, vk: slow upload lines 25 -> 3, a 1365 x 1365 x 90 upload about 158-295 ms -> 18-29 ms. Not re-measured on main.

Setup: Windows 11, Ryzen AI 7 350 + Radeon 860M, 1600x1000, 67 % scale, 3-zone tour (numbers from #2330).

Before After
worst astc_flush_ms 332.07 1.64

Risks

A GPU or driver that mishandled many unfenced submits could lose the device; a revert is enough, nothing is saved or cached differently. Chunks past 64 per frame fall back to a bounded wait.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game: not run in the game (--force), see Testing.
  • mise run test passes: the targeted checks pass; three skipped for lack of Vulkan headers.
  • Measured against main: numbers are #2330's on mod-api.
  • No game files, build output or hand-edited generated files; third_party/ untouched.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • AI assistance recorded with Co-Authored-By: trailers.
## Summary On GPUs without native ASTC (AMD, NVIDIA, Intel desktop), large ASTC textures are decoded on the GPU in 16M-texel chunks (`RX_VK_ASTC_CHUNK_MPX`). Each chunk boundary blocked the presentation thread on `vkWaitForFences` just to reuse one upload command buffer, so entering a zone (Hyrule Field's 1365 x 1365 x 90 terrain arrays) froze the frame: 68 ms of `astc_flush_ms` in one frame of a nightly-937 Kakariko capture on an RX 9070 XT, with `uploads_ms` of 185 ms in the worst frame. This is Jer9's [#2330](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2330), merged into mod-api, ported to main unchanged (a clean cherry-pick, author kept): each recording keeps a pool of up to 64 upload command buffers, each finished chunk is submitted at once without a fence, and all chunks retire together when the frame slot is reused. No new switch; it does nothing on GPUs that sample ASTC natively or with `RX_VK_ASTC_CPU=1`. Read first: `replay_flush_upload()` in `gpu/vk/vk_replay.cpp`, then `upload_astc_gpu()` in `gpu/vk/vk_texture.cpp`. ## Testing **Tested:** not run in the game on this PC; opened with `--force` at the person's request. Game-free on Linux: `tests/test_async_astc_upload_chunks.py` (fails on main, passes here), `test_astc_upload_chunking`, `test_astc_pass_timing`, `test_vk_braces`, `test_utf8_paths`, `test_doc_anchors`, `test_switches_removed`. Three C++ checks (`draw_stream_visibility`, `fsr_image_retirement`, `fsr_uniform_ownership`) were skipped here for want of the Vulkan headers, and the renderer was not compiled on this PC. On mod-api, Jer9 ran it on Windows 11, Radeon 860M (Adrenalin 26.10.1): 3-zone tour, 0 device losses. **Still to test:** - Linux, RADV/NVIDIA, Windows NVIDIA: Market -> Hyrule Field -> Kokiri Forest, expecting `astc_flush_ms` under 2 ms and no `VK_ERROR_DEVICE_LOST` (@Beanstalk) ## Measurements **Verdict:** from #2330 on mod-api, on a Radeon 860M: worst `astc_flush_ms` 332 ms -> 1.6 ms, total 1580 -> 12 ms, `vk: slow upload` lines 25 -> 3, a 1365 x 1365 x 90 upload about 158-295 ms -> 18-29 ms. Not re-measured on main. Setup: Windows 11, Ryzen AI 7 350 + Radeon 860M, 1600x1000, 67 % scale, 3-zone tour (numbers from #2330). | | Before | After | |---|---|---| | worst `astc_flush_ms` | 332.07 | 1.64 | ## Risks A GPU or driver that mishandled many unfenced submits could lose the device; a revert is enough, nothing is saved or cached differently. Chunks past 64 per frame fall back to a bounded wait. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game: not run in the game (`--force`), see Testing. - [ ] `mise run test` passes: the targeted checks pass; three skipped for lack of Vulkan headers. - [ ] Measured against `main`: numbers are #2330's on mod-api. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] AI assistance recorded with `Co-Authored-By:` trailers.
perf(vk): cut zone-entry ASTC upload spikes on non-ASTC GPUs via async chunk submits
Some checks failed
CI / What the change needs (pull_request) Successful in 18s
CI / Third-party parts and guide screenshots (pull_request) Failing after 26s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 26s
PR description / Title and description (pull_request_target) Failing after 8s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 1m59s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 2m37s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m4s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m43s
CI / Website build and checks (pull_request) Failing after 34s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 19m5s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 40m21s
d49880dab5
Port of #2330 (merged into mod-api) to main. Each 16M-texel chunk of a GPU ASTC
upload is submitted asynchronously from a small pool of upload command buffers
instead of waiting on a fence at every chunk boundary; all chunks retire when
the frame slot is reused. No new switch.

Original work by Jer9: #2330

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
HumanBean changed title from WIP: perf(vk): cut zone-entry ASTC upload spikes on non-ASTC GPUs via async chunk submits to perf(vk): cut zone-entry ASTC upload spikes on non-ASTC GPUs via async chunk submits 2026-11-30 03:28:06 +00:00
HumanBean deleted branch perf/vk-async-astc-upload-main 2026-11-30 03:28:18 +00:00
First-time contributor

Measured on an RX 6650 XT (Navi 23, RDNA2, Windows 10, driver 26.10.1 / 0x800161), 1920x1080 native, no frame generation, 30 fps cap, 2.800-3.300 draws:

nightly Kakariko, first entry re-entry in play
895 (before) 582 / 789 / 556 ms 582 ms 42-110 ms
951 (with #2860 and #2789) 296 / 216 ms 416 / 235 ms 40-63 ms

So this cut the zone-entry stall roughly in half on this card, but it did not go away: it also happens on re-entry, not only the first visit after a build. When it triggers, the texture budget is exactly at its cap (2442 MB of 2443 MB) and VRAM is at 85-88% (5.8-6.1 of 6.8-7.2 GB allowed), with the reaper destroying 150-205 images (217-417 MB) per 10 s while the new view's textures decode.

RX_VK_TEX_MAX_DIM=1024 is set in the profile (it brought the in-play worst frame from 182-260 ms to 40-110 ms), so the textures that remain are already the reduced ones.

Full write-up, settings and log excerpts: #2905

Measured on an RX 6650 XT (Navi 23, RDNA2, Windows 10, driver 26.10.1 / 0x800161), 1920x1080 native, no frame generation, 30 fps cap, 2.800-3.300 draws: | nightly | Kakariko, first entry | re-entry | in play | |---|---|---|---| | 895 (before) | 582 / 789 / 556 ms | 582 ms | 42-110 ms | | 951 (with #2860 and #2789) | 296 / 216 ms | 416 / 235 ms | 40-63 ms | So this cut the zone-entry stall roughly in half on this card, but it did not go away: it also happens on **re-entry**, not only the first visit after a build. When it triggers, the texture budget is exactly at its cap (2442 MB of 2443 MB) and VRAM is at 85-88% (5.8-6.1 of 6.8-7.2 GB allowed), with the reaper destroying 150-205 images (217-417 MB) per 10 s while the new view's textures decode. `RX_VK_TEX_MAX_DIM=1024` is set in the profile (it brought the in-play worst frame from 182-260 ms to 40-110 ms), so the textures that remain are already the reduced ones. Full write-up, settings and log excerpts: #2905
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 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!2860
No description provided.