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

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

📋 Pull Request Information

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

Base: main ← Head: rt-capture-last-frame


📝 Commits (1)

  • 7698e4e present: a LEONIDA_CAPTURE file is written by the present it captures (RT-CAPTURE-LAST-FRAME)

📊 Changes

3 files changed (+36 additions, -6 deletions)

View changed files

📝 runtime/shims/xbox_present.h (+7 -4)
📝 runtime/src/vulkan_present.h (+4 -0)
📝 runtime/test/d3d12_present_test.cpp (+25 -2)

📄 Description

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)

🔄 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/2090 **Author:** [@c0pperlane](https://github.com/c0pperlane) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `rt-capture-last-frame` --- ### 📝 Commits (1) - [`7698e4e`](https://github.com/ubiquitarianism/leonida/commit/7698e4e1674376d0d89ceb930b5014d2b721d5fb) present: a LEONIDA_CAPTURE file is written by the present it captures (RT-CAPTURE-LAST-FRAME) ### 📊 Changes **3 files changed** (+36 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/xbox_present.h` (+7 -4) 📝 `runtime/src/vulkan_present.h` (+4 -0) 📝 `runtime/test/d3d12_present_test.cpp` (+25 -2) </details> ### 📄 Description 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) --- <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#2096
No description provided.