Skip to content

Share bitmap upload submissions outside load batches - #1132

Merged
nitoygo merged 1 commit into
sven-n:mainfrom
jay23606:pr-go/1094-performance-opening-a-window-for-the-fir
Nov 15, 2026
Merged

nitoygo merged 1 commit into
sven-n:mainfrom
jay23606:pr-go/1094-performance-opening-a-window-for-the-fir

Conversation

@jay23606

Copy link
Copy Markdown
Contributor

Bug

Opening a window for the first time uploaded its textures one at a time inside the frame. Outside a load batch, every bitmap upload was its own GPU submission. Reusing a staging slot then waited on the previous submission's fence, so the game thread stalled and frames were dropped.

Change

Uploads outside a load batch now share the open submission until a staging slot is full or the frame's Flush takes it. Flush already runs before the frame submit, so a texture is on the GPU before the first frame that draws it.

Behaviour to be aware of: outside a batch, Upload can return success before its submission is in. A submit or fence failure is reported by Flush, not by the Upload call. This is documented in BitmapGpuResources.h.

Tests

  • Existing uploader tests that expect one submission per upload now call Flush() at the frame boundary.
  • New test: runtime uploads carry a submission across frames, and a 1024x1024 upload that fills a whole slot.
  • The regression test fails on commit 69889ac with CHECK( 0 == 1024 ) and passes on this change.
  • The new and existing outside-batch tests pass, and the full test_bitmap_gpu_resources.cpp file passes.

The test build uses tests/main.cpp as its doctest entry point, because build/standalone/main.cpp does not exist in the repository.

Not done: the browser and desktop frame-time measurements from the issue's acceptance criteria. They need a running build and were not run in this change.

Regression test: fails on commit 69889ac twice (/CHECK( 0 == 1024 )/), passes on fix twice (mkdir -p build/standalone && g++ -std=c++20 -I tests/third_party/doctest -I src/ThirdParty/SDL/include -I src/source -Wl,--unresolved-symbols=ignore-all -o build/standalone/bgr tests/main.cpp tests/render/test_bitmap_gpu_resources.cpp src/source/Render/Renderer/BitmapGpuResources.cpp && ./build/standalone/bgr -tc="uploads outside a batch*")

Refs #1094

nitoygo added a commit to nitoygo/MuMain that referenced this pull request Nov 15, 2026
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 merged commit 6e64b39 into sven-n:main Nov 15, 2026
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.

2 participants