upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/xbox_present.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/shims/xbox_present.cpp')
-rw-r--r--runtime/shims/xbox_present.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/runtime/shims/xbox_present.cpp b/runtime/shims/xbox_present.cpp
index dd5f810cf..f8791e1bf 100644
--- a/runtime/shims/xbox_present.cpp
+++ b/runtime/shims/xbox_present.cpp
@@ -1,6 +1,7 @@
1#include "xbox_present.h" 1#include "xbox_present.h"
2 2
3#include "d3d12_trace.h" 3#include "d3d12_trace.h"
4#include "d3d12_xs_device.h"
4 5
5#include "../src/vulkan_present.h" 6#include "../src/vulkan_present.h"
6 7
@@ -66,6 +67,7 @@ XboxPresentation::XboxPresentation(std::unique_ptr<WindowPresenter> presenter, l
66} 67}
67 68
68XboxPresentation::~XboxPresentation() { 69XboxPresentation::~XboxPresentation() {
70 if (presents_.load() > 0) log_pacing_summary();
69 { 71 {
70 std::lock_guard lock(worker_mutex_); 72 std::lock_guard lock(worker_mutex_);
71 worker_stop_ = true; 73 worker_stop_ = true;
@@ -75,6 +77,26 @@ XboxPresentation::~XboxPresentation() {
75 presenter_->set_abort(nullptr); 77 presenter_->set_abort(nullptr);
76} 78}
77 79
80void XboxPresentation::log_pacing_summary() const {
81 const leonida::FramePacingSummary s = pacer_.pacing_summary();
82 std::fprintf(stderr,
83 "[rt] present: pacing summary frames=%llu samples=%llu target_us=%u mean_us=%.1f drift_us=%+.1f "
84 "p50_us=%llu p95_us=%llu p99_us=%llu latency_samples=%llu latency_p50_us=%llu "
85 "latency_p95_us=%llu latency_p99_us=%llu\n",
86 static_cast<unsigned long long>(s.frames),
87 static_cast<unsigned long long>(s.samples),
88 s.target_interval_us,
89 s.mean_us,
90 s.drift_us,
91 static_cast<unsigned long long>(s.p50_us),
92 static_cast<unsigned long long>(s.p95_us),
93 static_cast<unsigned long long>(s.p99_us),
94 static_cast<unsigned long long>(s.latency_samples),
95 static_cast<unsigned long long>(s.latency_p50_us),
96 static_cast<unsigned long long>(s.latency_p95_us),
97 static_cast<unsigned long long>(s.latency_p99_us));
98}
99
78// Windows' SDR white level costs a QueryDisplayConfig and two DisplayConfigGetDeviceInfo calls (measured in 100// Windows' SDR white level costs a QueryDisplayConfig and two DisplayConfigGetDeviceInfo calls (measured in
79// xbox_present_test, docs section 4.5): too much for the present path, which would hitch once a second and feed the pacer. 101// xbox_present_test, docs section 4.5): too much for the present path, which would hitch once a second and feed the pacer.
80// So it is read here, about once a second while an HDR10 swapchain is in use, and PresentX reads the cached value. 102// So it is read here, about once a second while an HDR10 swapchain is in use, and PresentX reads the cached value.
@@ -314,4 +336,39 @@ HRESULT XboxPresentation::ResumeX() {
314 return S_OK; 336 return S_OK;
315} 337}
316 338
339bool attach_xbox_presentation(void* device_proxy, XboxPresentation* presentation) {
340 if (!presentation) return rt::d3d12_xs::set_presentation_handler(device_proxy, nullptr);
341 rt::d3d12_xs::PresentationHandler handler{};
342 handler.context = presentation;
343 handler.set_frame_interval = [](void* ctx, IUnknown* output, UINT interval_us, UINT latency, UINT flags) {
344 return static_cast<XboxPresentation*>(ctx)->SetFrameIntervalX(output, interval_us, latency, flags);
345 };
346 handler.schedule_frame_event = [](void* ctx, UINT event, UINT offset_us, UINT flags) {
347 return static_cast<XboxPresentation*>(ctx)->ScheduleFrameEventX(event, offset_us, flags);
348 };
349 handler.wait_frame_event = [](void* ctx, UINT event, DWORD timeout_ms, UINT flags, std::uint64_t* token) {
350 return static_cast<XboxPresentation*>(ctx)->WaitFrameEventX(event, timeout_ms, flags, token);
351 };
352 handler.get_frame_statistics = [](void* ctx, std::uint64_t token, UINT type_mask, UINT* count, void* out) {
353 return static_cast<XboxPresentation*>(ctx)->GetFrameStatisticsX(
354 token, type_mask, count, static_cast<leonida::FrameStatistic*>(out));
355 };
356 handler.present_x = [](void* ctx, UINT plane_count, const void* planes, const void* params) {
357 return static_cast<XboxPresentation*>(ctx)->PresentX(
358 plane_count, static_cast<const XboxPresentPlaneParameters*>(planes),
359 static_cast<const XboxPresentParameters*>(params));
360 };
361 handler.suspend_x = [](void* ctx, UINT flags) {
362 return static_cast<XboxPresentation*>(ctx)->SuspendX(flags);
363 };
364 handler.resume_x = [](void* ctx) {
365 return static_cast<XboxPresentation*>(ctx)->ResumeX();
366 };
367 return rt::d3d12_xs::set_presentation_handler(device_proxy, &handler);
368}
369
370bool detach_xbox_presentation(void* device_proxy) {
371 return rt::d3d12_xs::set_presentation_handler(device_proxy, nullptr);
372}
373
317} // namespace rt::d3d12 374} // namespace rt::d3d12