Skip to content

perf(render): texture uploads never wait for the GPU - #1133

Merged
nitoygo merged 2 commits into
sven-n:mainfrom
nitoygo:perf/uploads-never-wait
Nov 15, 2026
Merged

nitoygo merged 2 commits into
sven-n:mainfrom
nitoygo:perf/uploads-never-wait

Conversation

@nitoygo

@nitoygo nitoygo commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

Texture uploads could stop the frame and wait for the GPU. The uploader had three staging slots. When all three were still being copied, it waited for the oldest one to finish. Outside a load, each texture was also its own GPU submission, so the first time a window opened, the client paid one submission per icon.

On desktop this shows up as small hitches: 1–3 ms of slot waiting per load, and a heavier first window open. In a browser it is a hard blocker. A browser frame can't wait at all; any wait inside a frame throws. That makes this the uploader part of #1094 and of the last item of #1061.

What changed

This builds on #1132 by @jay23606, whose commit is included unchanged as the first commit here. It lets uploads outside a load share the open submission until the frame's flush. Merging this PR with a merge commit (not squash or rebase, which rewrite the commit) also lands #1132 and marks it merged. The second commit adds the rest:

  • Uploads never wait in normal use. If a slot is still being copied, the uploader takes the next finished one or adds a new one, up to 16 slots (64 MiB). It only waits past that ceiling or when memory runs out. After 60 frames without growth, idle slots beyond the first three are released.
  • Load batches removed. Since every upload now shares the open slot until the next flush (Share bitmap upload submissions outside load batches #1132), the load batch's begin/end calls on the uploader are removed, and a load ends with a flush.
  • Startup spreads itself out. StagedLoad::Pump now takes a hold-back check. While more than 32 MiB of staging is still being copied, startup leaves its next step for the next frame.
  • SDL Vulkan cleanup is still triggered. SDL's Vulkan backend frees finished submissions only on a fence wait or a frame submit, not on a fence query. So a fence the query already reports as done is still waited on; that wait returns immediately. Without it, texture creation got slower during loads (+45 ms over a startup).
  • New frames query on the control socket. It reports the longest frame and the number of slow frames (> 50 ms) since the last reset. I used it for the measurements below. It is documented in docs/control-socket.md.

Results (Vulkan, 1280×720, RelWithDebInfo)

main this PR
Slot waits per load 1–3 ms 0 ms
Inventory, first open (longest frame) 65–68 ms 60–64 ms
In-world frame time ($bench scene.full) same same

No FPS change in the world. The gain is fewer load hitches, and an uploader that can run inside a browser frame. I also tested it in a browser (WebGPU) build: the client reaches Lorencia, and the first inventory open is clean.

Tests

  • test_bitmap_gpu_resources (19 cases), using a fake GPU: growth up to the ceiling, waiting only at the ceiling or without memory, trimming, flushes across frames, and lost slots. Two regression cases came from review. One checks that a trim never leaves the ring pointing at a lost slot. The other checks that a trim never removes the last usable slot when lost slots fill the minimum; before the fix that case hung.
  • test_bitmap_gpu_upload_integration passes on a real D3D12 device (MU_RUN_GPU_UPLOAD_TESTS=1), including bounded staging growth under a flood.
  • Share bitmap upload submissions outside load batches #1132's per-frame test (runtime uploads carry a submission across frames…) is kept and passes unchanged.
  • New cases in test_staged_load (hold-back) and test_control_protocol (frames).

Closes #1094. Refs #1061, #865.

🤖 Generated with Claude Code

jay23606 and others added 2 commits November 15, 2026 15:06
Builds on the previous commit (sven-n#1132), which lets uploads outside a load batch share the open submission until the
frame's flush. The uploader still kept three staging slots and waited for the oldest one's fence when the ring
wrapped, and a browser frame can't wait at all.

- A slot the GPU is still copying is skipped: the uploader takes the next finished slot or adds one, up to 16
  (64 MiB); only past that, or out of memory, does it wait. Idle slots past the first three are released after 60
  frames without growth.
- With every upload sharing the open slot until the next flush, the load batch's begin/end on the uploader is gone;
  a load ends with a flush.
- StagedLoad::Pump takes a hold-back check between steps; startup leaves its next step to the next frame while more
  than 32 MiB of staging is still being copied.
- A finished fence is still waited on (it returns at once): SDL's Vulkan backend cleans up finished submissions only
  on a fence wait or a frame submit, and without it texture creation slowed during loads.
- The control socket's `frames` query reports the longest frame and slow frames since the last reset.
@nitoygo
nitoygo force-pushed the perf/uploads-never-wait branch from fb7db71 to 21d5b08 Compare November 15, 2026 20:47
@nitoygo nitoygo changed the title perf(render): texture uploads never wait for the GPU, and share submissions outside loads perf(render): texture uploads never wait for the GPU (builds on #1132) Nov 15, 2026
@nitoygo nitoygo changed the title perf(render): texture uploads never wait for the GPU (builds on #1132) perf(render): texture uploads never wait for the GPU Nov 15, 2026
@nitoygo
nitoygo merged commit 549e87e into sven-n:main Nov 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance] Opening a window for the first time uploads its textures one by one inside the frame

2 participants