Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions runtime/shims/xbox_present.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions runtime/src/vulkan_present.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 25 additions & 2 deletions runtime/test/d3d12_present_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<unsigned long long>(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
Expand Down