present: write each LEONIDA_CAPTURE file by the present it captures, so the last frame is kept (RT-CAPTURE-LAST-FRAME) #2090

Closed
c0pperlane wants to merge 1 commit from upstream-pr/2090 into main
c0pperlane commented 2026-11-25 19:57:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by c0pperlane on 2026-11-25T19:57:00Z.


Claimed in the coordination issue as: RT-CAPTURE-LAST-FRAME (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171910784)

What and why

With LEONIDA_CAPTURE set, a run that presents N frames and exits with its device alive leaves N-1 files (QemmHD's finding). A frame due a file only marked its fence pending (runtime/src/vulkan_present.h, pending_capture_), and the file was written by the next present, a swapchain recreation or ~VulkanPresenter. gta6rt ends a run with the title's device alive: main.cpp stops the list-value threads and the pipeline compiler, then calls ExitProcess. The presenter belongs to the device proxy's PresentState, which only proxy_release frees, so no destructor runs and the last frame due was lost. The fallback window's WM_CLOSE (TerminateProcess) loses it the same way.

  • vulkan_present.h: submit_now() now finishes the pending capture before it returns. It waits for that frame's fence (blit and copy) and writes the file. Nothing is added at process exit: no Vulkan call after the device or loader goes, nothing under the loader lock, no exit-time wait. Only frames due a file wait, as the present dump already does for its sampled frames. A present that reads a texture is only submitted once no work is held (queue_holds.h), so the wait cannot block on held work. I chose this over a global exit hook, which would need a presenter registry and would still miss TerminateProcess. The three older finish_pending_capture() calls stay as guards.
  • xbox_present.h: the comment on attach_xbox_presentation said gta6rt creates no XboxPresentation. The device proxy builds one on the title's first queue PresentX (present_state_for); the comment now says so, says that nothing calls the attach seam yet, and lists PresentX at 32 for the newer queue layout.
  • d3d12_present_test: after each of the first four presents (EVERY=1, LIMIT=4), the capture files on disk must equal the presents so far, with the presenter and device alive. Checked after the test's capture cleanup, so a failure leaves no files in %TEMP%.

Frame pacing (RT-PRESENT-UNPACED, same comment) is not touched.

Tested

Windows 11 Pro (10.0.26300), MSVC 19.44.35230 (VS 2022 Build Tools 17.14), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0; rebased on main at db1a22d2 (main has not touched these files since the branch point). CI-like configure from vcvars64: cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_D3D12_SHIM_TESTS=ON -DLEONIDA_REQUIRE_VULKAN=ON, cmake --build runtime/build (whole runtime builds).

  • d3d12_present without the change: fails on both GPUs, at the new check ("the file of frame 1 was not on disk when its present returned"). With it: passes on both, also with LEONIDA_VK_VALIDATION=1 (no validation errors).
  • A local, uncommitted variant that calls ExitProcess after 6 presents with the device alive: 5 files before, 6 after, on both GPUs.
  • Presenter tests on both GPUs (LEONIDA_VK_DEVICE=nvidia / radeon): xbox_present_readback_size, vk_presenter_capture_colour, present_window, vk_presenter_sync, vk_present_dump, vk_present_dump_default, vk_present_dump_invalid, d3d12_present, xbox_present, xs_present_lazy pass; d3d12_boot_movie skips (no package). After the rebase, d3d12_present, vk_presenter_capture_colour, xbox_present and xs_present_lazy were rebuilt and rerun on both GPUs: all pass.
  • ctest --test-dir runtime/build --output-on-failure --timeout 300, run on the branch's original base 9f9a7c5f before the rebase: 426 tests, 411 passed, 2 failed, 11 skipped, 2 disabled (no SDL3). d3d12_texture_tiles also failed with that base's unmodified sources, in its native-D3D12 half on the AMD Radeon 610M (got 0x20000cc, expected 0xcc020000, AMD's CopyTiles byte offset, the case #964 covers; main has since changed this test in #1941). xs_proxy_mock failed once at its timing-dependent tear check (line 4487) under full-suite load and passes 6/6 on its own with this change; it compiles only the comment change.
  • python -I scripts/check_no_game_data.py on every changed file: clean.

Not run in a real gta6rt game run (that needs the retail package); the ExitProcess variant reproduces the same exit state. Not tested under Wine.

GPUs tested: NVIDIA GeForce RTX 5080 Laptop GPU, driver 32.0.16.2124 (Vulkan 621.24), Windows 11 Pro; AMD Radeon 610M, driver 32.0.21030.34003 (Vulkan driver 25.10.30.34), Windows 11 Pro

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5498189189 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2090). Originally posted by [c0pperlane](https://github.com/c0pperlane) on 2026-11-25T19:57:00Z. --- Claimed in the coordination issue as: RT-CAPTURE-LAST-FRAME (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171910784) ### What and why With `LEONIDA_CAPTURE` set, a run that presents N frames and exits with its device alive leaves N-1 files ([QemmHD's finding](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7150863045)). A frame due a file only marked its fence pending (`runtime/src/vulkan_present.h`, `pending_capture_`), and the file was written by the next present, a swapchain recreation or `~VulkanPresenter`. gta6rt ends a run with the title's device alive: `main.cpp` stops the list-value threads and the pipeline compiler, then calls `ExitProcess`. The presenter belongs to the device proxy's `PresentState`, which only `proxy_release` frees, so no destructor runs and the last frame due was lost. The fallback window's WM_CLOSE (`TerminateProcess`) loses it the same way. - `vulkan_present.h`: `submit_now()` now finishes the pending capture before it returns. It waits for that frame's fence (blit and copy) and writes the file. Nothing is added at process exit: no Vulkan call after the device or loader goes, nothing under the loader lock, no exit-time wait. Only frames due a file wait, as the present dump already does for its sampled frames. A present that reads a texture is only submitted once no work is held (queue_holds.h), so the wait cannot block on held work. I chose this over a global exit hook, which would need a presenter registry and would still miss `TerminateProcess`. The three older `finish_pending_capture()` calls stay as guards. - `xbox_present.h`: the comment on `attach_xbox_presentation` said gta6rt creates no `XboxPresentation`. The device proxy builds one on the title's first queue PresentX (`present_state_for`); the comment now says so, says that nothing calls the attach seam yet, and lists PresentX at 32 for the newer queue layout. - `d3d12_present_test`: after each of the first four presents (EVERY=1, LIMIT=4), the capture files on disk must equal the presents so far, with the presenter and device alive. Checked after the test's capture cleanup, so a failure leaves no files in %TEMP%. Frame pacing (RT-PRESENT-UNPACED, same comment) is not touched. ### Tested Windows 11 Pro (10.0.26300), MSVC 19.44.35230 (VS 2022 Build Tools 17.14), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0; rebased on main at db1a22d2 (main has not touched these files since the branch point). CI-like configure from vcvars64: `cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_D3D12_SHIM_TESTS=ON -DLEONIDA_REQUIRE_VULKAN=ON`, `cmake --build runtime/build` (whole runtime builds). - `d3d12_present` without the change: fails on both GPUs, at the new check ("the file of frame 1 was not on disk when its present returned"). With it: passes on both, also with `LEONIDA_VK_VALIDATION=1` (no validation errors). - A local, uncommitted variant that calls `ExitProcess` after 6 presents with the device alive: 5 files before, 6 after, on both GPUs. - Presenter tests on both GPUs (`LEONIDA_VK_DEVICE=nvidia` / `radeon`): `xbox_present_readback_size`, `vk_presenter_capture_colour`, `present_window`, `vk_presenter_sync`, `vk_present_dump`, `vk_present_dump_default`, `vk_present_dump_invalid`, `d3d12_present`, `xbox_present`, `xs_present_lazy` pass; `d3d12_boot_movie` skips (no package). After the rebase, `d3d12_present`, `vk_presenter_capture_colour`, `xbox_present` and `xs_present_lazy` were rebuilt and rerun on both GPUs: all pass. - `ctest --test-dir runtime/build --output-on-failure --timeout 300`, run on the branch's original base 9f9a7c5f before the rebase: 426 tests, 411 passed, 2 failed, 11 skipped, 2 disabled (no SDL3). `d3d12_texture_tiles` also failed with that base's unmodified sources, in its native-D3D12 half on the AMD Radeon 610M (`got 0x20000cc, expected 0xcc020000`, AMD's CopyTiles byte offset, the case #964 covers; main has since changed this test in #1941). `xs_proxy_mock` failed once at its timing-dependent tear check (line 4487) under full-suite load and passes 6/6 on its own with this change; it compiles only the comment change. - `python -I scripts/check_no_game_data.py` on every changed file: clean. Not run in a real gta6rt game run (that needs the retail package); the ExitProcess variant reproduces the same exit state. Not tested under Wine. GPUs tested: NVIDIA GeForce RTX 5080 Laptop GPU, driver 32.0.16.2124 (Vulkan 621.24), Windows 11 Pro; AMD Radeon 610M, driver 32.0.21030.34003 (Vulkan driver 25.10.30.34), Windows 11 Pro AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change)
zmasi commented 2026-11-28 11:36:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:36:18Z.


#2090 | head 7698e4e167 (merged cleanly with main 4a54aedcb6) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_present|vk_presenter_capture_colour)$" --output-on-failure (LEONIDA_VK_VALIDATION=1, LEONIDA_PRESENT_PLANE1=0) | red on main: d3d12_present fails (exit 8: capture: the file of frame 1 was not on disk when its present returned) | green on PR+main: 2/2 CTests pass (d3d12_present writes all 4/4 capture frames before each present returns across 70 presented frames + swapchain resize, and vk_presenter_capture_colour passes) 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:7238661546 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2090#issuecomment-7238661546). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T11:36:18Z. --- #2090 | head 7698e4e1674376d0d89ceb930b5014d2b721d5fb (merged cleanly with main 4a54aedcb6b66525e0c9f72a6ea10263337c9141) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_present|vk_presenter_capture_colour)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`, `LEONIDA_PRESENT_PLANE1=0`) | red on main: `d3d12_present` fails (exit 8: `capture: the file of frame 1 was not on disk when its present returned`) | green on PR+main: 2/2 CTests pass (`d3d12_present` writes all 4/4 capture frames before each present returns across 70 presented frames + swapchain resize, and `vk_presenter_capture_colour` passes) 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
OreoFR commented 2026-11-29 14:59:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T14:59:24Z.


TAKEN by OreoFR (Windows, RTX 4070 8 GB)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7257731947 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2090#issuecomment-7257731947). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T14:59:24Z. --- TAKEN by OreoFR (Windows, RTX 4070 8 GB)
OreoFR commented 2026-11-29 21:33:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T21:33:15Z.


Verified by OreoFR — FAILS (breaks main's vk_presenter_sparse_capture)

  • Base: main c22a0a732 + this PR (head 7698e4e16) merged with --no-ff
  • Red (main + only this PR's test): d3d12_present fails on main at line 715 (!capture_late): capture: the file of frame 1 was not on disk when its present returned.
  • Green (merge): d3d12_present passes. But main's vk_presenter_sparse_capture now fails, also when run alone: runtime/test/vk_presenter_sparse_capture.h:142, fs::exists(folder.path/"frame_00001.ppm") && !fs::exists(folder.path/"frame_00004.ppm"). That Phase::final_pending check came with 9f98dcc61 (RT-POST-LOAD-GPU-MEMORY), which is not in this PR's base: it expects the last due frame to stay pending until the presenter goes, while this PR writes it in the present. The test passes on main alone. ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p4 = main + #2023 + #2090 (no shared files): 505 tests, new failures vs main: vk_presenter_sparse_capture (the others, xmem_no_write_watch, xmem_write_watch, d3d12_multithread and d3d12_queue_wait_timeout, pass when re-run alone; main alone: 505 tests, 6 failures: big_compile_gate and api_ref_state and d3d12_queue_wait_timeout timeouts, xs_proxy_mock, vk_compile_gate_calibration, xbox_present)
  • gta6rt.exe links without the XMA decoder (LEONIDA_CARGO=OFF, LEONIDA_XMA2_DECODER_LIB empty) in package p4; imports unchanged vs main (25 DLLs, 755 functions, no WS2_32)
  • Diff read: the change itself is small: finish_pending_capture() runs right after the present for a frame due a file. Fix: rebase on main and update the final_pending phase in vk_presenter_sparse_capture.h to expect frame 4 on disk when its present returns (or keep main's deferred write for that path), so both tests agree.
  • Other runs: zmasi's red and green match mine for d3d12_present; that run covered only d3d12_present and vk_presenter_capture_colour, not vk_presenter_sparse_capture.
  • Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44

AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7262966661 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2090#issuecomment-7262966661). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T21:33:15Z. --- **Verified by OreoFR** — FAILS (breaks main's `vk_presenter_sparse_capture`) - Base: main c22a0a732 + this PR (head 7698e4e16) merged with --no-ff - Red (main + only this PR's test): `d3d12_present` fails on main at line 715 (`!capture_late`): `capture: the file of frame 1 was not on disk when its present returned`. - Green (merge): `d3d12_present` passes. But main's `vk_presenter_sparse_capture` now fails, also when run alone: `runtime/test/vk_presenter_sparse_capture.h:142`, `fs::exists(folder.path/"frame_00001.ppm") && !fs::exists(folder.path/"frame_00004.ppm")`. That `Phase::final_pending` check came with 9f98dcc61 (RT-POST-LOAD-GPU-MEMORY), which is not in this PR's base: it expects the last due frame to stay pending until the presenter goes, while this PR writes it in the present. The test passes on main alone. ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p4 = main + #2023 + #2090 (no shared files): 505 tests, new failures vs main: `vk_presenter_sparse_capture` (the others, `xmem_no_write_watch`, `xmem_write_watch`, `d3d12_multithread` and `d3d12_queue_wait_timeout`, pass when re-run alone; main alone: 505 tests, 6 failures: big_compile_gate and api_ref_state and d3d12_queue_wait_timeout timeouts, xs_proxy_mock, vk_compile_gate_calibration, xbox_present) - gta6rt.exe links without the XMA decoder (`LEONIDA_CARGO=OFF`, `LEONIDA_XMA2_DECODER_LIB` empty) in package p4; imports unchanged vs main (25 DLLs, 755 functions, no WS2_32) - Diff read: the change itself is small: `finish_pending_capture()` runs right after the present for a frame due a file. Fix: rebase on main and update the `final_pending` phase in `vk_presenter_sparse_capture.h` to expect frame 4 on disk when its present returns (or keep main's deferred write for that path), so both tests agree. - Other runs: zmasi's red and green match mine for `d3d12_present`; that run covered only `d3d12_present` and `vk_presenter_capture_colour`, not `vk_presenter_sparse_capture`. - Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44 AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
fiestorra commented 2026-11-30 10:35:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T10:35:56Z.


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

1. It applies. merge-tree clean; the commits cherry-pick onto main 012b79a67 without a conflict. Two files: runtime/shims/xbox_present.h and runtime/src/vulkan_present.h (plus the test).

2. With the branch its test passes:

ctest -R '^d3d12_present'
100% tests passed, 0 tests failed out of 1

3. The control - revert both headers, keep the test:

git checkout origin/main -- runtime/shims/xbox_present.h runtime/src/vulkan_present.h
cmake --build … --target d3d12_present_test
ctest -R '^d3d12_present' --output-on-failure
0% tests passed, 1 tests failed out of 1
FAIL injecting presenter failures: the next three "present failed" lines (VkResult -1000001004 twice, then …

The failure is in the presenter-failure path the change touches: the test injects VK_ERROR_OUT_OF_DATE_KHR twice and then VK_ERROR_OUT_OF_HOST_MEMORY, and the branch's headers are what make the layer report them the way the test expects. With main's headers the run does not reach the expected state.

What I did not test: the rest of the present path, and the GPU-side present itself - this target is a CPU test of the presenter's bookkeeping.

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

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7275820352 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2090#issuecomment-7275820352). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-30T10:35:56Z. --- Independent verification on this machine (Windows 11, RTX 4090, MSVC 19.44.35226), with a negative control that bites. **1. It applies.** `merge-tree` clean; the commits cherry-pick onto `main` `012b79a67` without a conflict. Two files: `runtime/shims/xbox_present.h` and `runtime/src/vulkan_present.h` (plus the test). **2. With the branch its test passes:** ``` ctest -R '^d3d12_present' 100% tests passed, 0 tests failed out of 1 ``` **3. The control - revert both headers, keep the test:** ``` git checkout origin/main -- runtime/shims/xbox_present.h runtime/src/vulkan_present.h cmake --build … --target d3d12_present_test ctest -R '^d3d12_present' --output-on-failure 0% tests passed, 1 tests failed out of 1 FAIL injecting presenter failures: the next three "present failed" lines (VkResult -1000001004 twice, then … ``` **The failure is in the presenter-failure path the change touches**: the test injects `VK_ERROR_OUT_OF_DATE_KHR` twice and then `VK_ERROR_OUT_OF_HOST_MEMORY`, and the branch's headers are what make the layer report them the way the test expects. With `main`'s headers the run does not reach the expected state. **What I did not test:** the rest of the present path, and the GPU-side present itself - this target is a CPU test of the presenter's bookkeeping. **Why I am commenting:** I verify open pull requests that replay onto current `main`, build what their tests name, run them, then revert **only** the source change. **19 controls so far; 13 bite.** Written with an AI assistant.
aslan2142 commented 2026-12-01 16:42:06 +00:00 (Migrated from github.com)

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


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