runtime/vulkan: unified per-frame perf pack (bindless 0-alloc, view/descriptor/format tables) #113

Open
github-bot wants to merge 4 commits from github-bot/gh-113 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:20 UTC · original
ubiquitarianism:old-pr/9846 → main · +1850 −65 · 12 files · 4 commits · draft

Carried over from old PR 9846 by TG0000 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9846, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
TG0000: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Consolidated per-frame Vulkan runtime performance pack replacing closed PRs #8021, #8042, #8159, and #8180 (all previously independently verified across multiple GPUs including RX 9070 XT, RX 7800 XT, RX 6800, RTX 5070 Ti, RTX 5070, RTX 3070 Ti, RTX 2080, and Intel UHD 770).

What this combines

  1. GFX10 descriptor format table indexing (was #8021): compile-time indexed lookup instead of linear scan (~20x faster: 111 -> 5 ns).
  2. Hashed attachment-view cache indexed by image (was #8042): 2x–4.5x faster lookup and up to 460x faster image destroy (0.67 ms -> 3.4 us).
  3. Hashed border-color table & address-keyed replaced views (was #8159): removes O(N) scans under descriptor_mutex (5x–62.5x border colors, 3.3x–22.1x replaced views).
  4. Flat per-binding pending-write arrays & memchr free-index scan in vulkan_bindless.h (was #8180): 0 heap allocations per frame (was 2,811), 4x faster (206 -> 48 us/frame).

Testing

  • Built on Windows 11 (Ryzen 9 5900X, AMD Radeon RX 6800 gfx1030, clang++/Ninja/CMake 4.5.1, -DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF, RelWithDebInfo): 158/158 targets, 0 warnings.
  • All 7 touched Vulkan tests pass (gfx10_tiling, image_view_cache, descriptor_tables, bindless_sizing, bindless_queue, gfx10_descriptors, gfx10_format_bench_selftest); 73/74 full CTest pass (the only failure is vk_queue_query_sync, which fails identically on bare origin/main on RX 6800).
  • git diff --check and scripts/check_no_game_data.py clean. No game data used.

AI-assisted (Claude Opus 5.5).

**@⁠Andretuta** on GitHub · 2026-11-24 02:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/113) `ubiquitarianism:old-pr/9846` → `main` · +1850 −65 · 12 files · 4 commits · draft > Carried over from **old PR 9846** by `TG0000` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9846`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `TG0000`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Consolidated per-frame Vulkan runtime performance pack replacing closed PRs `#8021`, `#8042`, `#8159`, and `#8180` (all previously independently verified across multiple GPUs including RX 9070 XT, RX 7800 XT, RX 6800, RTX 5070 Ti, RTX 5070, RTX 3070 Ti, RTX 2080, and Intel UHD 770). ### What this combines 1. **GFX10 descriptor format table indexing** (was `#8021`): compile-time indexed lookup instead of linear scan (~20x faster: `111 -> 5 ns`). 2. **Hashed attachment-view cache indexed by image** (was `#8042`): `2x–4.5x` faster lookup and up to `460x` faster image destroy (`0.67 ms -> 3.4 us`). 3. **Hashed border-color table & address-keyed replaced views** (was `#8159`): removes O(N) scans under `descriptor_mutex` (`5x–62.5x` border colors, `3.3x–22.1x` replaced views). 4. **Flat per-binding pending-write arrays & `memchr` free-index scan in `vulkan_bindless.h`** (was `#8180`): `0` heap allocations per frame (was 2,811), `4x` faster (`206 -> 48 us/frame`). ### Testing - Built on Windows 11 (Ryzen 9 5900X, AMD Radeon RX 6800 gfx1030, clang++/Ninja/CMake 4.5.1, `-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF`, RelWithDebInfo): 158/158 targets, **0 warnings**. - All 7 touched Vulkan tests pass (`gfx10_tiling`, `image_view_cache`, `descriptor_tables`, `bindless_sizing`, `bindless_queue`, `gfx10_descriptors`, `gfx10_format_bench_selftest`); 73/74 full CTest pass (the only failure is `vk_queue_query_sync`, which fails identically on bare `origin/main` on RX 6800). - `git diff --check` and `scripts/check_no_game_data.py` clean. No game data used. AI-assisted (Claude Opus 5.5).
format_row, vulkan_format and vulkan_view_format walked the 94-row
format_table on every call; an SRV makes five of these lookups
(format_from_vulkan, vulkan_view_format, format_swizzle, vulkan_swizzle,
vulkan_format), and the T# -> set 0 binding does two of them under the
descriptor lock. The table is now indexed at compile time: by Vulkan
format for the core range (< 256, the VK_EXT_4444_formats rows above it
keep the scan) and by 9-bit GFX10 code (first row and row count). Each
lookup returns the first row in table order, as the scan did; a
static_assert keeps the rows of one code adjacent so the code's range is
exactly the rows the scan visited.

gfx10_format_bench times the lookups against the old scans (kept in the
bench as the reference) and its --self-test, run by ctest, checks both
agree on 502 formats x 1103 codes x cast/no cast. On a Ryzen host the
SRV lookup sequence goes from ~111 ns to ~5 ns (about 20x).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
VulkanContext::view runs for every colour and depth attachment of every
draw and clear the replay records. Its cache was a std::map keyed by a
6-tuple, and destroying an image walked every cached view of every image.
ImageViewCache (runtime/src/image_view_cache.h) makes the lookup one hash
probe and keeps each image's keys, so a destroy visits only its own views.
Same keys, same first-view-wins rule, same views released.

image_view_cache_test checks it against the old std::map on fixed and
random sequences and benchmarks both (1.7-3.6x faster lookups, 8-500x
faster destroys, no allocations on either path, ~155 vs 72 heap bytes per
cached view).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
register_border_color (CreateSampler and every static sampler with a custom
border colour) scanned the whole table, up to 4000 entries, under
descriptor_mutex. forget_image (every texture destruction) ran std::erase_if
over every replaced view of every live texture.

Both move into runtime/src/descriptor_tables.h, standard library only. Past
16 colours a hash index answers; past 384 replaced views they move into a
multimap by the texture's address. Below those sizes the old linear code
stays, since it is the faster there. Indices, releases and release order are
unchanged: colours are never removed or reordered, and std::multimap keeps
equal keys in insertion order.

runtime/test/descriptor_tables_test.cpp checks both against copies of the old
code on fixed cases and 400 random sequences, then times them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
BindlessSet::queue() kept its one-write-per-slot map in a std::unordered_map:
a heap node for every descriptor queued (up to five per add_image), all freed
again by flush(). The map is now one position array per binding, sized to the
binding's count in create_layout(); flush() zeroes only the entries it used.
flush()'s in-place VkWriteDescriptorSet array is a reused member.

allocate() looked for the first free index one byte at a time; memchr finds
the same first zero byte.

No behaviour change: bindless_queue_test drives BindlessSet through a fake
Vulkan device and digests every descriptor write and returned index; the
digest is the same built against the previous header. It also compares copies
of the old queue and allocate with the new ones on fixed and random inputs.

Per streamed frame (256 adds with storage views, 256 updates, two flushes):
206 -> 48 us and 2811 -> 0 heap allocations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:44:54 +00:00
This pull request has changes conflicting with the target branch.
  • runtime/CMakeLists.txt
  • runtime/src/vulkan_backend.h
  • runtime/src/vulkan_bindless.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/113/head:github-bot/gh-113'
git switch 'github-bot/gh-113'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-113'
git switch 'github-bot/gh-113'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-113'
git switch 'github-bot/gh-113'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-113'
git switch 'main'
git merge --squash 'github-bot/gh-113'
git switch 'main'
git merge --ff-only 'github-bot/gh-113'
git switch 'main'
git merge 'github-bot/gh-113'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.