Skip to content

perf: Reuse ETC2 staging buffers - #242

Open
Saul5662 wants to merge 1 commit into
komaruworld:mainfrom
Saul5662:etc2-staging-pool
Open

Saul5662 wants to merge 1 commit into
komaruworld:mainfrom
Saul5662:etc2-staging-pool

Conversation

@Saul5662

@Saul5662 Saul5662 commented Nov 20, 2026 •

Copy link
Copy Markdown

Issue

Every emulated ETC2 upload (vkCmdCopyBufferToImage{,2}) created a host-visible staging buffer, and ReleaseCommandBuffer freed it again. On NVIDIA each create/allocate/map/free cycle costs 0.45 ms at 16 KiB and 1.4 ms at 4 MiB of kernel time on the uploading thread. On a cold-cache join this stalled Main for several seconds while textures loaded.

Results

RTX 3060, NVIDIA 620.73.04, empty asset cache, perf over the first 20 s of the join:

before after
driver + kernel share of Main 53% 21%
worst 240-frame windows during load 63 and 54 fps 80 and 82 fps

Patch (src/graphics/vulkan_etc2_emulation.cc)

  • Released staging buffers go into a per-device pool, still mapped, and are reused by later uploads. A buffer is recycled at the point where it used to be destroyed.
  • Sizes round up to a power of two (64 KiB minimum). The pool is capped at 256 MiB per device, with the largest buffers evicted first.
  • Device teardown frees both pooled and in-flight buffers.
  • Tests cover reuse, size-class hits and misses, the cap, and teardown. The full suite passes.

DISCLAIMER: This PR was AI assisted and manually reviewed.

This branch has not been deployed

No deployments
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.

1 participant