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

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

@⁠IlyassRS3 on GitHub · 2026-11-25 15:39 UTC · original
IlyassRS3:fix/rt-present-compose-mem-and-guards → main · +389 −30 · 3 files · 1 commits · open

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.
**@⁠IlyassRS3** on GitHub · 2026-11-25 15:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1912) `IlyassRS3:fix/rt-present-compose-mem-and-guards` → `main` · +389 −30 · 3 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:10:56 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 15:39 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 15:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1912#pullrequestreview-6060683483) · **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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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