runtime: BAR-aware memory fallback and heap-size filtering in BindlessSet (RT-BINDLESS-MEMORY-FALLBACK-AND-BAR) #1879

Open
github-bot wants to merge 1 commit from github-bot/gh-1879 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 14:00 UTC · original
IlyassRS3:rt-bindless-memory-fallback-and-bar → main · +674 −25 · 3 files · 1 commits · open

Item: RT-BINDLESS-MEMORY-FALLBACK-AND-BAR
Claim: #1608

Summary

Fixes memory-type selection and OOM fallback in BindlessSet (runtime/src/vulkan_bindless.h) using vulkan_memory.h's memory_type_order() and resizable_bar() policy:

  1. Fixes non-ReBAR local == fallback OOM trap in BindlessSet::create():
    • Previously, memory_type(bits, DEVICE_LOCAL) and memory_type(bits, HOST_VISIBLE | HOST_COHERENT) each returned only the first matching memory type with no heap-size check and no retry loop.
    • When a small (<= 256 MiB) DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT BAR type appears at index 0 before main DEVICE_LOCAL VRAM and system RAM on a non-ReBAR GPU, local == fallback == 0, so if (fallback != local) evaluated false on BAR OOM — skipping both main VRAM and system RAM and degrading or failing bindless descriptor table flushes (up to 64 MiB as the table grows).
    • Now table (device_local == true) tries non-small-BAR DEVICE_LOCAL types first, then remaining DEVICE_LOCAL types, then falls back to HOST_VISIBLE | HOST_COHERENT types (tracking tried_mask to avoid duplicate attempts and incrementing table_host_fallbacks_ when a DEVICE_LOCAL type existed and host fallback succeeded).
  2. Keeps 64 MiB staging buffers off the 256 MiB BAR window on non-ReBAR GPUs + adds OOM retry:
    • staging (device_local == false) prefers system RAM over small BAR on non-ReBAR GPUs (while preserving ReBAR staging when resizable_bar() is true) and retries secondary HOST_VISIBLE | HOST_COHERENT types on OOM.
  3. Heap-size enforcement (VUID-vkAllocateMemory-pAllocateInfo-01713):
    • Filters out memory types whose heap is smaller than requirements.size when memoryHeapCount > 0 (preserving compatibility with synthetic zero-heap mocks where memoryHeapCount == 0).
  4. create_fallbacks() multi-type OOM retry & failed-handle cleanup:
    • Prefers non-small-BAR DEVICE_LOCAL types, retries all eligible fitting types on OOM, records failure via note_failure("fallback image", result), and clears failed image.image / image.memory / fallback_sampler_ handles so ~BindlessSet() never frees an invalid handle.

No overlap with open PRs #425 or #1092.

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU-only macOS arm64 host with Khronos Vulkan-Headers)
  • New unit test runtime/test/vk_bindless_memory_fallback_test.cpp (CTest vk_bindless_memory_fallback):
    • clang++ -std=c++20 -Wall -Wextra -Wno-missing-field-initializers -Werror -O1 -g -fsanitize=address,undefined: passed (0 leaks, 0 invalid frees, 0 undersized alloc attempts)
    • clang++ -std=c++20 -O1 -g -fsanitize=thread: passed
    • clang++ -std=c++20 -O2 (3 runs): passed
  • Existing bindless_sizing_test: passed; vk_bindless_grow_test.cpp and vk_bindless_test.cpp: syntax-checked cleanly
  • Mutation check against main: compiling vk_bindless_memory_fallback_test.cpp against main's runtime/src/vulkan_bindless.h fails immediately (FAIL line 346: !mock.table_types_bound.empty() && mock.table_types_bound.back() == 1)
  • python3 -I scripts/check_no_game_data.py on all changed files: passed
  • python3 -I tests/test_text_write_line_endings.py: passed (3 tests)
**@⁠IlyassRS3** on GitHub · 2026-11-25 14:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1879) `IlyassRS3:rt-bindless-memory-fallback-and-bar` → `main` · +674 −25 · 3 files · 1 commits · open Item: `RT-BINDLESS-MEMORY-FALLBACK-AND-BAR` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### Summary Fixes memory-type selection and OOM fallback in `BindlessSet` (`runtime/src/vulkan_bindless.h`) using `vulkan_memory.h`'s `memory_type_order()` and `resizable_bar()` policy: 1. **Fixes non-ReBAR `local == fallback` OOM trap in `BindlessSet::create()`**: - Previously, `memory_type(bits, DEVICE_LOCAL)` and `memory_type(bits, HOST_VISIBLE | HOST_COHERENT)` each returned only the first matching memory type with no heap-size check and no retry loop. - When a small (<= 256 MiB) `DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT` BAR type appears at index 0 before main `DEVICE_LOCAL` VRAM and system RAM on a non-ReBAR GPU, `local == fallback == 0`, so `if (fallback != local)` evaluated false on BAR OOM — skipping both main VRAM and system RAM and degrading or failing bindless descriptor table flushes (up to 64 MiB as the table grows). - Now `table` (`device_local == true`) tries non-small-BAR `DEVICE_LOCAL` types first, then remaining `DEVICE_LOCAL` types, then falls back to `HOST_VISIBLE | HOST_COHERENT` types (tracking `tried_mask` to avoid duplicate attempts and incrementing `table_host_fallbacks_` when a `DEVICE_LOCAL` type existed and host fallback succeeded). 2. **Keeps 64 MiB staging buffers off the 256 MiB BAR window on non-ReBAR GPUs + adds OOM retry**: - `staging` (`device_local == false`) prefers system RAM over small BAR on non-ReBAR GPUs (while preserving ReBAR staging when `resizable_bar()` is true) and retries secondary `HOST_VISIBLE | HOST_COHERENT` types on OOM. 3. **Heap-size enforcement (`VUID-vkAllocateMemory-pAllocateInfo-01713`)**: - Filters out memory types whose heap is smaller than `requirements.size` when `memoryHeapCount > 0` (preserving compatibility with synthetic zero-heap mocks where `memoryHeapCount == 0`). 4. **`create_fallbacks()` multi-type OOM retry & failed-handle cleanup**: - Prefers non-small-BAR `DEVICE_LOCAL` types, retries all eligible fitting types on OOM, records failure via `note_failure("fallback image", result)`, and clears failed `image.image` / `image.memory` / `fallback_sampler_` handles so `~BindlessSet()` never frees an invalid handle. No overlap with open PRs `#425` or `#1092`. ### Verification - **AI-assisted**: yes - **GPUs tested**: none (CPU-only macOS arm64 host with Khronos Vulkan-Headers) - New unit test `runtime/test/vk_bindless_memory_fallback_test.cpp` (CTest `vk_bindless_memory_fallback`): - `clang++ -std=c++20 -Wall -Wextra -Wno-missing-field-initializers -Werror -O1 -g -fsanitize=address,undefined`: passed (0 leaks, 0 invalid frees, 0 undersized alloc attempts) - `clang++ -std=c++20 -O1 -g -fsanitize=thread`: passed - `clang++ -std=c++20 -O2` (3 runs): passed - Existing `bindless_sizing_test`: passed; `vk_bindless_grow_test.cpp` and `vk_bindless_test.cpp`: syntax-checked cleanly - **Mutation check against `main`**: compiling `vk_bindless_memory_fallback_test.cpp` against `main`'s `runtime/src/vulkan_bindless.h` fails immediately (`FAIL line 346: !mock.table_types_bound.empty() && mock.table_types_bound.back() == 1`) - `python3 -I scripts/check_no_game_data.py` on all changed files: passed - `python3 -I tests/test_text_write_line_endings.py`: passed (3 tests)
Use memory_type_order() and resizable_bar() from vulkan_memory.h in
BindlessSet::create() and BindlessSet::create_fallbacks() so table,
staging, and fallback-image allocations:
- skip memory heaps smaller than requirements.size
  (VUID-vkAllocateMemory-pAllocateInfo-01713), with a fallback path when
  synthetic mock properties leave memoryHeapCount == 0;
- keep table, staging, and fallback allocations off a <=256 MiB BAR
  window on non-ReBAR GPUs while main VRAM or system RAM is available;
- retry across all eligible memory types on OOM, fixing the non-ReBAR
  BAR-first bug where local == fallback == BAR skipped both main VRAM
  and system RAM and degraded/failed bindless table flushes;
- clear failed image/memory/sampler out-handles before teardown.

Item: RT-BINDLESS-MEMORY-FALLBACK-AND-BAR
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:09:39 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 14:01 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 14:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1879#pullrequestreview-6059001190) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠Timon360SB on GitHub · 2026-11-25 15:07 UTC · original

Independent verification — Turing and Blackwell

  • Base: 77baf906275d7b695664adbf0b33f3c2b306a1dc
  • Head: 5a6baea948d46eb4d51437f1f7e55ad03e216272

Environment

GPU Windows 11 build ReBAR
RTX 5070 26200 Enabled
RTX 2060 SUPER 28000 Unavailable

NVIDIA 621.14, Vulkan SDK 1.4.363.0, MSVC 19.44.35230, Ninja RelWithDebInfo.

Three repetitions per GPU, revision and validation mode. Core, GPU-assisted and synchronization validation requested in validated runs.

Results

Test Base Head
bindless_sizing 12/12 12/12
vk_bindless_grow 12/12 12/12
vk_bindless_ps_tex 12/12 12/12
vk_bindless_ps_imgatomic 12/12 12/12
d3d12_bindless_churn 12/12 12/12
vk_bindless_memory_fallback N/A 2/2
Total 60/60 62/62

122 executions: 122 passed, 0 failed, 0 skipped.

Findings

  • The new mock-Vulkan memory fallback test passes under Windows/MSVC on both systems.
  • Bindless growth: 400 frames, 3,200 keys added, table growth from 64 to 512 slots, zero allocations or descriptor pools in the second half.
  • Texture readback: 24 draws per execution, zero bad pixels.
  • D3D12 bindless churn: 96 frames, all sampled texels matched.
  • No Vulkan validation errors found in the captured logs.

No regressions observed on either GPU, including the no-ReBAR Turing configuration. Allocation failure handling was covered by the new mock test; physical BAR exhaustion was not forced.

Synthetic tests only. No game files used.
AI-assisted: yes.

**@⁠Timon360SB** on GitHub · 2026-11-25 15:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1879#issuecomment-7166332752) ## Independent verification — Turing and Blackwell - **Base:** `77baf906275d7b695664adbf0b33f3c2b306a1dc` - **Head:** `5a6baea948d46eb4d51437f1f7e55ad03e216272` ### Environment | GPU | Windows 11 build | ReBAR | |---|---|---| | RTX 5070 | 26200 | Enabled | | RTX 2060 SUPER | 28000 | Unavailable | NVIDIA 621.14, Vulkan SDK 1.4.363.0, MSVC 19.44.35230, Ninja RelWithDebInfo. Three repetitions per GPU, revision and validation mode. Core, GPU-assisted and synchronization validation requested in validated runs. ### Results | Test | Base | Head | |---|---:|---:| | `bindless_sizing` | 12/12 | 12/12 | | `vk_bindless_grow` | 12/12 | 12/12 | | `vk_bindless_ps_tex` | 12/12 | 12/12 | | `vk_bindless_ps_imgatomic` | 12/12 | 12/12 | | `d3d12_bindless_churn` | 12/12 | 12/12 | | `vk_bindless_memory_fallback` | N/A | 2/2 | | **Total** | **60/60** | **62/62** | 122 executions: 122 passed, 0 failed, 0 skipped. ### Findings - The new mock-Vulkan memory fallback test passes under Windows/MSVC on both systems. - Bindless growth: 400 frames, 3,200 keys added, table growth from 64 to 512 slots, zero allocations or descriptor pools in the second half. - Texture readback: 24 draws per execution, zero bad pixels. - D3D12 bindless churn: 96 frames, all sampled texels matched. - No Vulkan validation errors found in the captured logs. No regressions observed on either GPU, including the no-ReBAR Turing configuration. Allocation failure handling was covered by the new mock test; physical BAR exhaustion was not forced. Synthetic tests only. No game files used. AI-assisted: yes.
This pull request has changes conflicting with the target branch.
  • 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/1879/head:github-bot/gh-1879'
git switch 'github-bot/gh-1879'

Merge

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