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

Open
opened 2026-11-26 21:19:19 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1879
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: rt-bindless-memory-fallback-and-bar


📝 Commits (1)

  • 5a6baea runtime: BAR-aware memory fallback and heap-size filtering in BindlessSet

📊 Changes

3 files changed (+674 additions, -25 deletions)

View changed files

📝 runtime/CMakeLists.txt (+12 -0)
📝 runtime/src/vulkan_bindless.h (+99 -25)
➕ runtime/test/vk_bindless_memory_fallback_test.cpp (+563 -0)

📄 Description

Item: RT-BINDLESS-MEMORY-FALLBACK-AND-BAR
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164522386

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1879 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `rt-bindless-memory-fallback-and-bar` --- ### 📝 Commits (1) - [`5a6baea`](https://github.com/ubiquitarianism/leonida/commit/5a6baea948d46eb4d51437f1f7e55ad03e216272) runtime: BAR-aware memory fallback and heap-size filtering in BindlessSet ### 📊 Changes **3 files changed** (+674 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+12 -0) 📝 `runtime/src/vulkan_bindless.h` (+99 -25) ➕ `runtime/test/vk_bindless_memory_fallback_test.cpp` (+563 -0) </details> ### 📄 Description Item: `RT-BINDLESS-MEMORY-FALLBACK-AND-BAR` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164522386 ### 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1891
No description provided.