diff --git a/runtime/shims/xbox_present.h b/runtime/shims/xbox_present.h index 86381f2d62..107b5f6411 100644 --- a/runtime/shims/xbox_present.h +++ b/runtime/shims/xbox_present.h @@ -207,10 +207,13 @@ inline constexpr UINT xbox_frame_event_vblank = leonida::frame_event_vblank; inline constexpr UINT xbox_frame_event_flip = leonida::frame_event_flip; inline constexpr UINT xbox_frame_wait_token_on_timeout = leonida::frame_wait_flag_token_on_timeout; -// Seam for the presenter, not yet called by the runtime: gta6rt creates no XboxPresentation, and only -// d3d12_boot_movie_test and xbox_present_test construct one. Wires it into a d3d12_xs device proxy's frame-event -// slots (78–81) and queue PresentX (slot 30, or LEONIDA_XS_PRESENT_X_SLOT); SuspendX and ResumeX are routed only -// when LEONIDA_XS_SUSPEND_X_SLOT / LEONIDA_XS_RESUME_X_SLOT are set. Passing nullptr detaches the presentation. +// Seam for a presentation the caller owns, which nothing calls yet. gta6rt does not need it: its device proxy builds +// an XboxPresentation of its own on the title's first queue PresentX (present_state_for in d3d12_xs_device.cpp) and +// keeps it until the proxy goes; PresentX reaches that one while nothing is attached here, and slots 78–81 only +// with LEONIDA_FRAME_PACING=1. Attaching wires `presentation` into a d3d12_xs device proxy's frame-event slots +// (78–81) and queue PresentX (slot 30, 32 in the newer queue layout, or LEONIDA_XS_PRESENT_X_SLOT) ahead of that; +// SuspendX and ResumeX are routed only when LEONIDA_XS_SUSPEND_X_SLOT / LEONIDA_XS_RESUME_X_SLOT are set. Passing +// nullptr detaches the presentation. bool attach_xbox_presentation(void* device_proxy, XboxPresentation* presentation); bool detach_xbox_presentation(void* device_proxy); diff --git a/runtime/src/vulkan_present.h b/runtime/src/vulkan_present.h index d494233d3a..3bc41765d7 100644 --- a/runtime/src/vulkan_present.h +++ b/runtime/src/vulkan_present.h @@ -683,6 +683,10 @@ class VulkanPresenter { captured_extent_ = extent_; captured_format_ = format_; } + // LEONIDA_CAPTURE: a frame due a file has it written here, once its copy is done, not by the next present. A + // run ends with the device and this presenter alive (gta6rt's ExitProcess runs no destructor), so a file left + // for later lost the last frame. Only frames due a file wait, as the present dump above does for its frames. + if (const VkResult r = finish_pending_capture(); r != VK_SUCCESS) return stop(r); if (result == VK_ERROR_SURFACE_LOST_KHR) { // The surface was lost during the present (display disconnected, a driver reset of the window's // plane): vkd3d keeps rendering to nothing, and the next present recreates surface and swapchain. diff --git a/runtime/test/d3d12_present_test.cpp b/runtime/test/d3d12_present_test.cpp index b94e958522..9ff65bf738 100644 --- a/runtime/test/d3d12_present_test.cpp +++ b/runtime/test/d3d12_present_test.cpp @@ -470,9 +470,28 @@ int main() { return SUCCEEDED(queue->Signal(fence.p, ++signalled)); }; + // The capture files on disk so far (LEONIDA_CAPTURE_LIMIT is 4, so at most frames 1 to 4). + const auto capture_files = [&]() -> std::uint64_t { + std::uint64_t files = 0; + for (int i = 1; i <= 4; ++i) { + wchar_t path[MAX_PATH + 32]{}; + swprintf_s(path, L"%s\\frame_%05d.ppm", capture_dir, i); + if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES) ++files; + } + return files; + }; + // Every present is counted unless the surface reported it out of date, which the driver may do around a - // resize; the double counts those. - for (int i = 0; i < 60; ++i) EXPECT(frame(1)); + // resize; the double counts those. Each present due a capture file has written it by the time it returns, + // with the presenter and the device still alive: a run ends in that state (gta6rt's ExitProcess destroys + // neither), so a file left for the next present or the presenter's destructor is lost, and N presents + // gave N-1 files. Checked with the other capture checks below, after the files are removed. + std::uint64_t capture_late = 0; // the first present whose file was not on disk when it returned + for (int i = 0; i < 60; ++i) { + EXPECT(frame(1)); + const std::uint64_t shown = presenter->presented(); + if (capture_dir[0] && !capture_late && shown <= 4 && capture_files() != shown) capture_late = shown; + } EXPECT(presenter->presented() == 60 - driver::out_of_date); const VkExtent2D first = presenter->extent(); EXPECT(first.width == width && first.height == height); @@ -685,10 +704,14 @@ int main() { std::fabs(b - (red ? 0 : 230)) <= 3.0) ++matching; } std::printf("capture: %d correct images, %d index rows, %d matching frame colours\n", exact_files, lines, matching); + if (capture_late) + std::printf("capture: the file of frame %llu was not on disk when its present returned\n", + static_cast(capture_late)); index.close(); DeleteFileA((std::string(narrow) + "\\index.txt").c_str()); RemoveDirectoryA(narrow); EXPECT(exact_files == 4 && lines == 4 && matching == 4); + EXPECT(!capture_late); } presenter.reset(); // before the device's queue and resources go