vulkan_present: guard make_capture_buffer against a null memory-properties pointer (RT-PRESENT-CAPTURE-NULLGUARD) #1223

Closed
Miici0 wants to merge 2 commits from upstream-pr/1223 into main
Miici0 commented 2026-11-24 20:34:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Miici0 on 2026-11-24T20:34:14Z.


Claimed in the coordination issue as: RT-PRESENT-CAPTURE-NULLGUARD (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143716337)

Depends on: none

Fixes: none

What and why

make_capture_buffer() in runtime/src/vulkan_present.h called vkGetPhysicalDeviceMemoryProperties_(physical_, ...) without checking the function pointer for null first, unlike prepare_compose() right above it, which does guard it. Found while investigating the intermittent xbox_present crash reported in #14 (finding at https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143642803). This does not claim to fix that crash — the root cause there is still unconfirmed (it reproduces only through ctest, at roughly a 2% rate, and disappears under any validation layer or debugger, so it couldn't be caught live after over 100 attempts). This just closes a real null-pointer-call gap found along the way: if the extension function were ever unavailable, this call would crash immediately and unconditionally instead of failing the capture-buffer setup cleanly, as its sibling function already does.

Tested

ctest --test-dir runtime/build -C RelWithDebInfo -R "^xbox_present$": passes (2.99s). Full portable test suite otherwise unaffected (single-line, behavior-preserving guard; the function pointer is non-null in every environment observed, so this only changes behavior in the previously-unguarded null case).

GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.24, Windows 11 26300.9974, Vulkan SDK 1.4.363.1.

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports quoted here.
  • N/A: no new translator rule.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5479878732 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1223). Originally posted by [Miici0](https://github.com/Miici0) on 2026-11-24T20:34:14Z. --- Claimed in the coordination issue as: RT-PRESENT-CAPTURE-NULLGUARD (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143716337) Depends on: none Fixes: none ### What and why `make_capture_buffer()` in `runtime/src/vulkan_present.h` called `vkGetPhysicalDeviceMemoryProperties_(physical_, ...)` without checking the function pointer for null first, unlike `prepare_compose()` right above it, which does guard it. Found while investigating the intermittent `xbox_present` crash reported in #14 (finding at https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143642803). This does **not** claim to fix that crash — the root cause there is still unconfirmed (it reproduces only through `ctest`, at roughly a 2% rate, and disappears under any validation layer or debugger, so it couldn't be caught live after over 100 attempts). This just closes a real null-pointer-call gap found along the way: if the extension function were ever unavailable, this call would crash immediately and unconditionally instead of failing the capture-buffer setup cleanly, as its sibling function already does. ### Tested `ctest --test-dir runtime/build -C RelWithDebInfo -R "^xbox_present$"`: passes (2.99s). Full portable test suite otherwise unaffected (single-line, behavior-preserving guard; the function pointer is non-null in every environment observed, so this only changes behavior in the previously-unguarded null case). GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.24, Windows 11 26300.9974, Vulkan SDK 1.4.363.1. AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption, including in logs or reports quoted here. - [ ] N/A: no new translator rule.
Snooozs commented 2026-11-24 21:48:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Snooozs on 2026-11-24T21:48:52Z.


Read the diff at f849034a8 (not built or run by me). The guard sits after vkCreateBuffer, so on its path make_capture_buffer returns false with capture_buffer_ set and no memory bound. Nothing on that path releases it: the other failures in this function call release_capture() first.

That matters because finish_image tests capture_ && capture_buffer_ before copying into it. enable_capture clears capture_ when recreate fails, but a later recreation (a resize, say) with capture already on does not, and would leave an unbound buffer behind.

Moving the check to the top of the function, before vkCreateBuffer (and after release_capture()), avoids it. prepare_compose also checks before it creates anything.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7145423120 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1223#issuecomment-7145423120). Originally posted by [Snooozs](https://github.com/Snooozs) on 2026-11-24T21:48:52Z. --- Read the diff at `f849034a8` (not built or run by me). The guard sits after `vkCreateBuffer`, so on its path `make_capture_buffer` returns false with `capture_buffer_` set and no memory bound. Nothing on that path releases it: the other failures in this function call `release_capture()` first. That matters because `finish_image` tests `capture_ && capture_buffer_` before copying into it. `enable_capture` clears `capture_` when `recreate` fails, but a later recreation (a resize, say) with capture already on does not, and would leave an unbound buffer behind. Moving the check to the top of the function, before `vkCreateBuffer` (and after `release_capture()`), avoids it. `prepare_compose` also checks before it creates anything. AI-assisted (Claude Code, Claude Opus 5.5).
Miici0 commented 2026-11-27 17:05:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Miici0 on 2026-11-27T17:05:56Z.


Fixed as suggested: the memory-properties-pointer guard now runs right after release_capture(), before vkCreateBuffer, so a missing pointer never leaves capture_buffer_ set without bound memory (4d3159aba).

Tested on the RTX 4070 SUPER (driver 621.24, Windows 11 26300, Vulkan SDK 1.4.363.1): ctest -R "present|capture" — 6/6 pass (xbox_present_readback_size, vk_presenter_capture_colour, vk_predicate_capture, vk_presenter_sync, d3d12_present, xbox_present).

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7224024230 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1223#issuecomment-7224024230). Originally posted by [Miici0](https://github.com/Miici0) on 2026-11-27T17:05:56Z. --- Fixed as suggested: the memory-properties-pointer guard now runs right after `release_capture()`, before `vkCreateBuffer`, so a missing pointer never leaves `capture_buffer_` set without bound memory (`4d3159aba`). Tested on the RTX 4070 SUPER (driver 621.24, Windows 11 26300, Vulkan SDK 1.4.363.1): `ctest -R "present|capture"` — 6/6 pass (`xbox_present_readback_size`, `vk_presenter_capture_colour`, `vk_predicate_capture`, `vk_presenter_sync`, `d3d12_present`, `xbox_present`). AI-assisted (Claude Code).
zmasi commented 2026-11-28 23:58:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T23:58:09Z.


Windows 11 + RTX 3090 Verification Report (4d3159aba8 merged onto origin/main a9e247cd69)

  • Merge Status: Clean merge onto origin/main (a9e247cd69) and clean in a 5-PR runtime/ batch merge.
  • Environment: Windows 11 (10.0.26200, x64), MSVC 19.44.35228, NVIDIA GeForce RTX 3090, VK_LAYER_KHRONOS_validation 1.4.363.1 (LEONIDA_VK_VALIDATION=1, VK_VALIDATE_SYNC=1).

Diff Audit (1 file, +1/-0)

  • runtime/src/vulkan_present.h (VulkanPresenter::make_capture_buffer): checks if (!vkGetPhysicalDeviceMemoryProperties_) return false; immediately after release_capture() and before vk.vkCreateBuffer(...), matching prepare_compose() (vulkan_present.h:1168) and preventing both a null function-pointer call and an orphaned VkBuffer handle when vkGetPhysicalDeviceMemoryProperties is unavailable.

Red -> Green Verification on RTX 3090

  1. Red (origin/main a9e247cd69):
    • Built a Win32 swapchain SEH regression probe on RTX 3090 intercepting vkGetInstanceProcAddr("vkGetPhysicalDeviceMemoryProperties") -> nullptr (while counting vkCreateBuffer / vkDestroyBuffer calls) and invoking presenter.enable_capture():
      exc=0xC0000005 created_during=1 destroyed_during=0 leaked_during=1 — make_capture_buffer() allocated a VkBuffer and then crashed with STATUS_ACCESS_VIOLATION (0xC0000005) calling the null function pointer.
  2. Green (#1223 + origin/main):
    • Same Win32 swapchain SEH regression probe against #1223:
      exc=0x00000000 cap_ok=0 created_during=0 destroyed_during=0 leaked_during=0 (rc=0, zero exceptions and zero leaked VkBuffer handles).
    • vk_presenter_sync_test.exe (/O2 /MD /EHsc /W4 /permissive- /utf-8) on RTX 3090 with Khronos Validation 1.4.363.1:
      • Default suite: vk_presenter_sync_test: ok (1.56 s, rc=0, 0 VUID- errors).
      • --sparse-capture: sparse capture: frames 1/4, cap, last-fence drain, explicit readback, disk and splash-only handoffs verified (1.24 s, rc=0, 0 VUID- errors).

Verdict: PASS — ready to merge.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247782339 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1223#issuecomment-7247782339). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T23:58:09Z. --- ### Windows 11 + RTX 3090 Verification Report (`4d3159aba8` merged onto `origin/main` `a9e247cd69`) - **Merge Status**: Clean merge onto `origin/main` (`a9e247cd69`) and clean in a 5-PR `runtime/` batch merge. - **Environment**: Windows 11 (`10.0.26200`, x64), MSVC `19.44.35228`, NVIDIA GeForce RTX 3090, `VK_LAYER_KHRONOS_validation` `1.4.363.1` (`LEONIDA_VK_VALIDATION=1`, `VK_VALIDATE_SYNC=1`). #### Diff Audit (`1` file, `+1/-0`) - `runtime/src/vulkan_present.h` (`VulkanPresenter::make_capture_buffer`): checks `if (!vkGetPhysicalDeviceMemoryProperties_) return false;` immediately after `release_capture()` and *before* `vk.vkCreateBuffer(...)`, matching `prepare_compose()` (`vulkan_present.h:1168`) and preventing both a null function-pointer call and an orphaned `VkBuffer` handle when `vkGetPhysicalDeviceMemoryProperties` is unavailable. #### Red -> Green Verification on RTX 3090 1. **Red (`origin/main` `a9e247cd69`)**: - Built a Win32 swapchain SEH regression probe on RTX 3090 intercepting `vkGetInstanceProcAddr("vkGetPhysicalDeviceMemoryProperties") -> nullptr` (while counting `vkCreateBuffer` / `vkDestroyBuffer` calls) and invoking `presenter.enable_capture()`: `exc=0xC0000005 created_during=1 destroyed_during=0 leaked_during=1` — `make_capture_buffer()` allocated a `VkBuffer` and then crashed with `STATUS_ACCESS_VIOLATION` (`0xC0000005`) calling the null function pointer. 2. **Green (`#1223` + `origin/main`)**: - Same Win32 swapchain SEH regression probe against `#1223`: `exc=0x00000000 cap_ok=0 created_during=0 destroyed_during=0 leaked_during=0` (`rc=0`, zero exceptions and zero leaked `VkBuffer` handles). - `vk_presenter_sync_test.exe` (`/O2 /MD /EHsc /W4 /permissive- /utf-8`) on RTX 3090 with Khronos Validation `1.4.363.1`: - Default suite: `vk_presenter_sync_test: ok` (`1.56 s`, `rc=0`, **`0` `VUID-` errors**). - `--sparse-capture`: `sparse capture: frames 1/4, cap, last-fence drain, explicit readback, disk and splash-only handoffs verified` (`1.24 s`, `rc=0`, **`0` `VUID-` errors**). **Verdict**: **PASS** — ready to merge. AI-assisted.
enlight3d commented 2026-11-29 09:03:16 +00:00 (Migrated from github.com)

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


RUN #1223 | head 4d3159aba8, merged cleanly with main 54b2a81e95 (local merge, not pushed)

This pull request has no test of its own: the guarded path needs vkGetPhysicalDeviceMemoryProperties to be null, which no test in the tree arranges. So there is no red; I did not invent one. What I ran is the tests of the code it touches (runtime/src/vulkan_present.h).

Commands (from the repository root, in a worktree):

git fetch origin pull/1223/head:pr-1223
git checkout --detach origin/main && git merge --no-edit --no-ff pr-1223
cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build -j 8 --target gta6rt vk_presenter_sync_test vk_present_dump_test xbox_present_test d3d12_boot_movie_test d3d12_present_test
ctest -C RelWithDebInfo -R "^(vk_presenter_sync|vk_presenter_sparse_capture|vk_present_dump|vk_present_dump_default|vk_present_dump_invalid|d3d12_present|xbox_present|d3d12_boot_movie)$" --output-on-failure -j1
  • Build: gta6rt and the five test targets build, no error.
  • Green: vk_presenter_sync, vk_presenter_sparse_capture, vk_present_dump, vk_present_dump_default, vk_present_dump_invalid, d3d12_present pass. d3d12_boot_movie is skipped (reports skip).
  • xbox_present fails here (present failed (VkResult -11)), and it fails the same way on plain main 54b2a81e9, so it is pre-existing and not caused by this one-line guard. (The description mentions an intermittent xbox_present crash; what I see on this machine is a steady failure, not the same symptom.)
  • Red: not applicable (no test for the change).
  • Link: no new imports vs main (gta6rt.exe, 723 DLL!symbol entries, same list as the baseline built from main).

Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44, Vulkan SDK 1.4.363.1.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7253504872 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1223#issuecomment-7253504872). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T09:03:16Z. --- RUN #1223 | head 4d3159aba8c75054965414124fb43da55297d329, merged cleanly with main 54b2a81e95c470c953ddee6177fd6255cbaf041d (local merge, not pushed) This pull request has no test of its own: the guarded path needs `vkGetPhysicalDeviceMemoryProperties` to be null, which no test in the tree arranges. So there is no red; I did not invent one. What I ran is the tests of the code it touches (`runtime/src/vulkan_present.h`). Commands (from the repository root, in a worktree): ``` git fetch origin pull/1223/head:pr-1223 git checkout --detach origin/main && git merge --no-edit --no-ff pr-1223 cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON cmake --build runtime/build -j 8 --target gta6rt vk_presenter_sync_test vk_present_dump_test xbox_present_test d3d12_boot_movie_test d3d12_present_test ctest -C RelWithDebInfo -R "^(vk_presenter_sync|vk_presenter_sparse_capture|vk_present_dump|vk_present_dump_default|vk_present_dump_invalid|d3d12_present|xbox_present|d3d12_boot_movie)$" --output-on-failure -j1 ``` - Build: gta6rt and the five test targets build, no error. - Green: `vk_presenter_sync`, `vk_presenter_sparse_capture`, `vk_present_dump`, `vk_present_dump_default`, `vk_present_dump_invalid`, `d3d12_present` pass. `d3d12_boot_movie` is skipped (reports skip). - `xbox_present` fails here (`present failed (VkResult -11)`), and it fails the same way on plain main 54b2a81e9, so it is pre-existing and not caused by this one-line guard. (The description mentions an intermittent `xbox_present` crash; what I see on this machine is a steady failure, not the same symptom.) - Red: not applicable (no test for the change). - Link: no new imports vs main (gta6rt.exe, 723 DLL!symbol entries, same list as the baseline built from main). Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44, Vulkan SDK 1.4.363.1.
aslan2142 commented 2026-12-01 16:34:10 +00:00 (Migrated from github.com)

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


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:7317822957 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1223#issuecomment-7317822957). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:34:10Z. --- 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!1223
No description provided.