Skip to content

vulkan_present: keep continuous readback valid on OUT_OF_DATE present - #2507

Open
lixonik wants to merge 1 commit into
ProjectLeonida:mainfrom
lixonik:rt-present-resize-readback
Open

lixonik wants to merge 1 commit into
ProjectLeonida:mainfrom
lixonik:rt-present-resize-readback

Conversation

@lixonik

@lixonik lixonik commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a regression from 9f98dcc61 (RT-POST-LOAD-GPU-MEMORY) in VulkanPresenter::submit_now() (runtime/src/vulkan_present.h) that broke xbox_present case F (xbox_present_test.cpp:1226) on NVIDIA RTX 5070 during window resize.

When the window is resized between presents, vkQueuePresentKHR on Windows/NVIDIA can return VK_ERROR_OUT_OF_DATE_KHR after the command buffer -- including the vkCmdCopyImageToBuffer transfer into capture_buffer_ -- has already been submitted (submitted == VK_SUCCESS). submit_now() still returns VK_SUCCESS, and xbox_present_test.cpp:1224 explicitly expects the composed frame to remain readable through read_back().

Commit 9f98dcc61 cleared captured_ = false before submission and moved the captured_ = true assignment inside if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR). As a result, any VK_ERROR_OUT_OF_DATE_KHR from vkQueuePresentKHR left captured_ == false and caused read_back() to fail.

This change:

  • Keeps disk-capture scheduling (pending_capture_ = frame.done) gated on VK_SUCCESS || VK_SUBOPTIMAL_KHR so only shown frames are written to disk.
  • Sets captured_, captured_extent_, and captured_format_ whenever copy_frame && capture_ptr_ ran and result is VK_SUCCESS, VK_SUBOPTIMAL_KHR, or VK_ERROR_OUT_OF_DATE_KHR (leaving VK_ERROR_SURFACE_LOST_KHR and other failures uncaptured).

Verification

  • Negative control (main 39f52f39c): ctest --output-on-failure -R ^xbox_present$ failed deterministically at xbox_present_test.cpp:1226 (line 1226: present_planes(&one, 1)) during case F window resize (320x240 -> 400x300).
  • With this PR:

Claimed in #1608 (comment) (RT-PRESENT-RESIZE-READBACK). No game files used.

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally).
AI-assisted (Antigravity, Gemini).

@Tyrannys Tyrannys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent verification of head b8486b4a5 on profile M: RTX 4070 SUPER 12 GB, NVIDIA 621.01, Windows 11, Ryzen 7 9800X3D. MSVC RelWithDebInfo.

  • Negative control, main 39f52f39c: ctest -C RelWithDebInfo --output-on-failure -R "^xbox_present$" failed 2 of 2 runs, at line 1226: present_planes(&one, 1) (case F, window resize). So this is not just an RTX 5070 issue: the 4070 SUPER on 621.01 hits it too.
  • With this PR (merged on 39f52f39c together with #2505, which only touches a compile-pool test): ctest -C RelWithDebInfo --output-on-failure -R "^(xbox_present|d3d12_present)$" passed 3 of 3 runs (xbox_present 2.95-4.06 s, d3d12_present 1.62-1.97 s). The resize case is part of xbox_present, and it ran on the card.
  • Code read: pending_capture_ (disk capture) is still set only for a shown present. captured_ is now also set for VK_ERROR_OUT_OF_DATE_KHR, but only after vkQueueSubmit succeeded, so the copy into capture_buffer_ was really queued. VK_ERROR_SURFACE_LOST_KHR still clears it.

Clean. Approving. No game files used.

AI-assisted (Claude Code).

@timbot103

Copy link
Copy Markdown
Contributor

Reviewed at head b8486b4a5 on Windows 11 (MSVC 2022 19.44) with dual-GPU Vulkan validation (LEONIDA_VK_VALIDATION=1, Vulkan SDK 1.4.363.0).

Verification

  • Built xbox_present_readback_size_test and xbox_present_test.
  • xbox_present_readback_size_test: passed.
  • xbox_present_test (LEONIDA_PRESENT_PLANE1=0, LEONIDA_VK_VALIDATION=1): all cases passed with 0 validation errors on both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02) — notably fixing the resize OUT_OF_DATE failure previously reproduced on RTX 5080 (window resized 320x240 -> 400x300 -> 200x150 -> 320x240 between composed presents: ok).

Notes (non-blocking)

  • Advancing frame_index_ after submit and publishing capture extent/format on VK_ERROR_OUT_OF_DATE_KHR (vulkan_present.h:364-374, 650-717, 1336-1412) is sound because the capture copy and transfer-to-host barrier were already submitted and fenced before vkQueuePresentKHR, while surface-loss clears capture and minimize skips it.
  • Minor (vulkan_present.h:360-363): Consider updating the contract comment stating a skipped present stays unreadable until a frame is shown so it mentions the OUT_OF_DATE submitted-capture case as well.

Approve.

AI-assisted review + local MSVC/dual-GPU verification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants