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

Closed
IlyassRS3 wants to merge 1 commit from upstream-pr/1912 into main
IlyassRS3 commented 2026-11-25 15:39:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T15:39:51Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5494477490 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1912). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T15:39:51Z. --- 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.
copilot-pull-request-reviewer[bot] commented 2026-11-25 15:39:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T15:39:59Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6060683483 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1912#pullrequestreview-6060683483). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T15:39:59Z. **Review:** COMMENTED --- 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.
zmasi commented 2026-11-28 12:17:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:17:37Z.


#1912 | head 90022ae32b (merged cleanly with main d48a957bb9) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(vk_present_compose|vk_presenter_capture_colour|d3d12_present)$" --output-on-failure (LEONIDA_VK_VALIDATION=1, LEONIDA_PRESENT_PLANE1=0) | red on main: vk_present_compose fails (exit 8 at !composer.ready() when vkGetImageMemoryRequirements is omitted) | green on PR+main: 3/3 CTests pass (vk_present_compose, vk_presenter_capture_colour, and d3d12_present across 70 presented frames + swapchain resize) on RTX 3090 with 0 Khronos validation errors; check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239126721 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1912#issuecomment-7239126721). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T12:17:37Z. --- #1912 | head 90022ae32b045cc8bb741d6f747a136c7af3d3e6 (merged cleanly with main d48a957bb9988afce424552a3c0c8d01ef12320f) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(vk_present_compose|vk_presenter_capture_colour|d3d12_present)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`, `LEONIDA_PRESENT_PLANE1=0`) | red on main: `vk_present_compose` fails (exit 8 at `!composer.ready()` when `vkGetImageMemoryRequirements` is omitted) | green on PR+main: 3/3 CTests pass (`vk_present_compose`, `vk_presenter_capture_colour`, and `d3d12_present` across 70 presented frames + swapchain resize) on RTX 3090 with `0` Khronos validation errors; `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
enlight3d commented 2026-11-29 09:04:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T09:04:11Z.


RUN of #1912 (red/green, GPU box, merged build)

Heads: PR head 90022ae32b04, main 54b2a81e95c4. Tested as main + PR head (git merge --no-ff, local only): merged cleanly, no conflicts.

Commands (VS 2022 x64 environment, from the worktree root):
cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build -j 8 --target vk_present_compose_test vk_presenter_sync_test vk_present_dump_test gta6rt
ctest -R "^vk_present_compose$" --output-on-failure -j1
Also run, because they include vulkan_present.h which includes the touched header: ctest -R "^(vk_presenter_sync|vk_presenter_sparse_capture|vk_present_dump|vk_present_dump_default|vk_present_dump_invalid)$" -j1

  • Red, behavioural (the PR's vulkan_present_compose.h reverted to main's, the new test and its CMake registration kept; the test still compiles, so this is not a build failure): vk_present_compose fails at runtime/test/vk_present_compose_test.cpp:230: !composer.ready(), i.e. ready() returns true although a Vulkan proc is missing, which is what the PR fixes. (The test is a CPU mock; it does not use the GPU.)
  • Green, merged: vk_present_compose Passed. The five related tests (vk_presenter_sync, vk_presenter_sparse_capture, vk_present_dump, _default, _invalid) Passed too, none skipped.
  • Link: no new imports vs main (dumpbin /imports of gta6rt.exe, DLL!symbol, sorted: 700 entries on main and on main + PR, identical).

Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo, -DLEONIDA_REQUIRE_VULKAN=ON, Vulkan SDK 1.4.363.1.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7253515215 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1912#issuecomment-7253515215). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T09:04:11Z. --- RUN of #1912 (red/green, GPU box, merged build) Heads: PR head `90022ae32b04`, main `54b2a81e95c4`. Tested as main + PR head (`git merge --no-ff`, local only): merged cleanly, no conflicts. Commands (VS 2022 x64 environment, from the worktree root): `cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON` `cmake --build runtime/build -j 8 --target vk_present_compose_test vk_presenter_sync_test vk_present_dump_test gta6rt` `ctest -R "^vk_present_compose$" --output-on-failure -j1` Also run, because they include `vulkan_present.h` which includes the touched header: `ctest -R "^(vk_presenter_sync|vk_presenter_sparse_capture|vk_present_dump|vk_present_dump_default|vk_present_dump_invalid)$" -j1` - Red, behavioural (the PR's `vulkan_present_compose.h` reverted to main's, the new test and its CMake registration kept; the test still compiles, so this is not a build failure): `vk_present_compose` fails at `runtime/test/vk_present_compose_test.cpp:230: !composer.ready()`, i.e. `ready()` returns true although a Vulkan proc is missing, which is what the PR fixes. (The test is a CPU mock; it does not use the GPU.) - Green, merged: `vk_present_compose` Passed. The five related tests (`vk_presenter_sync`, `vk_presenter_sparse_capture`, `vk_present_dump`, `_default`, `_invalid`) Passed too, none skipped. - Link: no new imports vs main (`dumpbin /imports` of `gta6rt.exe`, DLL!symbol, sorted: 700 entries on main and on main + PR, identical). Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo, `-DLEONIDA_REQUIRE_VULKAN=ON`, Vulkan SDK 1.4.363.1.
fiestorra commented 2026-11-30 11:54:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T11:54:14Z.


Independent verification on this machine (Windows 11, RTX 4090, MSVC 19.44.35226), with a negative control that bites.

1. It applies and builds. merge-tree clean onto main d367675c7; one source file plus its test.

2. With the branch: ctest -R '^vk_present_compose' -> 100% tests passed, 0 failed out of 1.

3. The control - revert only the source, keep the test:

git checkout origin/main -- <the changed source>
cmake --build … --target vk_present_compose_test
ctest -R '^vk_present_compose' --output-on-failure
0% tests passed, 1 tests failed out of 1
FAIL …/runtime/test/vk_present_compose_test.cpp:230: !com…

The failure is an assertion at line 230, on a !com… condition (a COM call expected to fail), so the part of the change the test owns is the failure path it asserts there.

What I did not test: the rest of the present-compose path, and whether the refusal the test encodes matches what the console's composer does. The control establishes that the test notices the change, not that the change is right.

Why I am commenting: I verify open pull requests that replay onto current main, build the binaries their tests name, run them, then revert only the source change. 34 controls so far: 27 bite.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7277679901 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1912#issuecomment-7277679901). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-30T11:54:14Z. --- Independent verification on this machine (Windows 11, RTX 4090, MSVC 19.44.35226), with a negative control that bites. **1. It applies and builds.** `merge-tree` clean onto `main` `d367675c7`; one source file plus its test. **2. With the branch:** `ctest -R '^vk_present_compose'` -> **100% tests passed, 0 failed out of 1**. **3. The control - revert only the source, keep the test:** ``` git checkout origin/main -- <the changed source> cmake --build … --target vk_present_compose_test ctest -R '^vk_present_compose' --output-on-failure 0% tests passed, 1 tests failed out of 1 FAIL …/runtime/test/vk_present_compose_test.cpp:230: !com… ``` **The failure is an assertion at line 230**, on a `!com…` condition (a COM call expected to fail), so the part of the change the test owns is the **failure path** it asserts there. **What I did not test:** the rest of the present-compose path, and whether the refusal the test encodes matches what the console's composer does. **The control establishes that the test notices the change, not that the change is right.** **Why I am commenting:** I verify open pull requests that replay onto current `main`, build the binaries their tests name, run them, then revert **only** the source change. **34 controls so far: 27 bite.** Written with an AI assistant.
aslan2142 commented 2026-12-01 16:38:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:38:59Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317961800 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1912#issuecomment-7317961800). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:38:59Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1912
No description provided.