[PR #1912] runtime: BAR-aware memory fallback, proc completeness, and zero-extent guards in PresentComposer (RT-PRESENT-COMPOSE-MEM-AND-GUARDS) #1923

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

📋 Pull Request Information

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

Base: main ← Head: fix/rt-present-compose-mem-and-guards


📝 Commits (1)

  • 90022ae runtime: BAR-aware memory fallback, proc completeness, and zero-extent guards in PresentComposer (RT-PRESENT-COMPOSE-MEM-AND-GUARDS)

📊 Changes

3 files changed (+389 additions, -30 deletions)

View changed files

📝 runtime/CMakeLists.txt (+7 -0)
📝 runtime/src/vulkan_present_compose.h (+87 -30)
➕ runtime/test/vk_present_compose_test.cpp (+295 -0)

📄 Description

Item ID: RT-PRESENT-COMPOSE-MEM-AND-GUARDS (claimed in #1608).

Summary

Hardens leonida::PresentComposer (runtime/src/vulkan_present_compose.h), which owns the PresentX compute composition pass and its RGBA16F output image (up to 64 MiB at 4K):

  1. BAR-aware memory fallback and heap-size filtering (ensure_target):
    • Replaces the first-DEVICE_LOCAL loop with memory_type_order() (preserving memoryHeapCount == 0 mock compatibility) plus !resizable_bar() pure-VRAM preference so the compose target stays off the 256 MiB BAR window on non-ReBAR GPUs, filters out undersized heaps (VUID-vkAllocateMemory-pAllocateInfo-01713), and retries all eligible memory types on VK_ERROR_OUT_OF_DEVICE_MEMORY.
  2. Complete Vulkan proc validation and partial-init cleanup (ready, ~PresentComposer):
    • Checks every Vulkan device proc PresentComposer calls (including vkGetImageMemoryRequirements, vkBindImageMemory, vkCmdPipelineBarrier, and all destroy/free procs) so partial or mock devices cannot hit a null function pointer dereference.
    • Destroys partial pipeline/layout/pool objects immediately when ready() fails partway through and guards release_target() / release_pipeline() against null destroy procs.
  3. Zero-extent and creation-error handle safety (ensure_target):
    • Rejects 0x0 extents (e.g. minimized windows) before calling release_target() or vkCreateImage (VUID-VkImageCreateInfo-extent-00944/00945), and clears output handles on failed vkCreateImage / vkCreateImageView / vkAllocateMemory.

Verification

  • AI-assisted: yes.
  • GPUs tested: none (macOS host, CPU-only portable Vulkan-Headers mock harness; no game files used).
  • New CTest target vk_present_compose (runtime/test/vk_present_compose_test.cpp, Clang 20, C++20, -Wall -Wextra -Werror):
    • ASan + UBSan: PASS
    • TSan: PASS
    • -O2 × 3: PASS
  • Downstream header syntax check (vulkan_present.h): PASS.
  • Mutation test against main's vulkan_present_compose.h: fails on main (ready() returned true with missing vkGetImageMemoryRequirements), passes on this branch.
  • Hygiene: python3 -I scripts/check_no_game_data.py on all 3 touched files and python3 -I tests/test_text_write_line_endings.py passed.

🔄 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/1912 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-present-compose-mem-and-guards` --- ### 📝 Commits (1) - [`90022ae`](https://github.com/ubiquitarianism/leonida/commit/90022ae32b045cc8bb741d6f747a136c7af3d3e6) runtime: BAR-aware memory fallback, proc completeness, and zero-extent guards in PresentComposer (RT-PRESENT-COMPOSE-MEM-AND-GUARDS) ### 📊 Changes **3 files changed** (+389 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+7 -0) 📝 `runtime/src/vulkan_present_compose.h` (+87 -30) ➕ `runtime/test/vk_present_compose_test.cpp` (+295 -0) </details> ### 📄 Description Item ID: `RT-PRESENT-COMPOSE-MEM-AND-GUARDS` (claimed in #1608). ### Summary Hardens `leonida::PresentComposer` (`runtime/src/vulkan_present_compose.h`), which owns the PresentX compute composition pass and its RGBA16F output image (up to 64 MiB at 4K): 1. **BAR-aware memory fallback and heap-size filtering (`ensure_target`)**: - Replaces the first-`DEVICE_LOCAL` loop with `memory_type_order()` (preserving `memoryHeapCount == 0` mock compatibility) plus `!resizable_bar()` pure-VRAM preference so the compose target stays off the 256 MiB BAR window on non-ReBAR GPUs, filters out undersized heaps (`VUID-vkAllocateMemory-pAllocateInfo-01713`), and retries all eligible memory types on `VK_ERROR_OUT_OF_DEVICE_MEMORY`. 2. **Complete Vulkan proc validation and partial-init cleanup (`ready`, `~PresentComposer`)**: - Checks every Vulkan device proc `PresentComposer` calls (including `vkGetImageMemoryRequirements`, `vkBindImageMemory`, `vkCmdPipelineBarrier`, and all destroy/free procs) so partial or mock devices cannot hit a null function pointer dereference. - Destroys partial pipeline/layout/pool objects immediately when `ready()` fails partway through and guards `release_target()` / `release_pipeline()` against null destroy procs. 3. **Zero-extent and creation-error handle safety (`ensure_target`)**: - Rejects `0x0` extents (e.g. minimized windows) before calling `release_target()` or `vkCreateImage` (`VUID-VkImageCreateInfo-extent-00944/00945`), and clears output handles on failed `vkCreateImage` / `vkCreateImageView` / `vkAllocateMemory`. ### Verification - **AI-assisted**: yes. - **GPUs tested**: none (macOS host, CPU-only portable Vulkan-Headers mock harness; no game files used). - New CTest target `vk_present_compose` (`runtime/test/vk_present_compose_test.cpp`, Clang 20, C++20, `-Wall -Wextra -Werror`): - ASan + UBSan: PASS - TSan: PASS - `-O2` × 3: PASS - Downstream header syntax check (`vulkan_present.h`): PASS. - Mutation test against `main`'s `vulkan_present_compose.h`: fails on `main` (`ready()` returned `true` with missing `vkGetImageMemoryRequirements`), passes on this branch. - Hygiene: `python3 -I scripts/check_no_game_data.py` on all 3 touched files and `python3 -I tests/test_text_write_line_endings.py` passed. --- <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#1923
No description provided.