diff options
Diffstat (limited to 'runtime/shims/xbox_present.cpp')
| -rw-r--r-- | runtime/shims/xbox_present.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/runtime/shims/xbox_present.cpp b/runtime/shims/xbox_present.cpp index 6fbed007d..f048504e8 100644 --- a/runtime/shims/xbox_present.cpp +++ b/runtime/shims/xbox_present.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | #include "xbox_present.h" | 2 | #include "xbox_present.h" |
| 3 | 3 | ||
| 4 | #include "d3d12_trace.h" | 4 | #include "d3d12_trace.h" |
| 5 | #include "d3d12_xs_device.h" | ||
| 5 | 6 | ||
| 6 | #include "../src/vulkan_present.h" | 7 | #include "../src/vulkan_present.h" |
| 7 | 8 | ||
| @@ -30,10 +31,10 @@ void log_once(bool& done, const char* text) { | |||
| 30 | } // namespace | 31 | } // namespace |
| 31 | 32 | ||
| 32 | XboxPresentation::XboxPresentation(std::unique_ptr<WindowPresenter> presenter, leonida::FrameClock* clock, | 33 | XboxPresentation::XboxPresentation(std::unique_ptr<WindowPresenter> presenter, leonida::FrameClock* clock, |
| 33 | std::shared_ptr<leonida::FrameTokenSource> tokens) | 34 | std::shared_ptr<leonida::FrameTokenSource> tokens, bool current_origin_poll) |
| 34 | : presenter_(std::move(presenter)), | 35 | : presenter_(std::move(presenter)), |
| 35 | own_clock_(clock ? nullptr : std::make_unique<leonida::SteadyFrameClock>()), | 36 | own_clock_(clock ? nullptr : std::make_unique<leonida::SteadyFrameClock>()), |
| 36 | pacer_(clock ? *clock : *own_clock_, std::move(tokens)) { | 37 | pacer_(clock ? *clock : *own_clock_, std::move(tokens), current_origin_poll) { |
| 37 | // A present waiting for a swapchain image gives up once SuspendX has been called. | 38 | // A present waiting for a swapchain image gives up once SuspendX has been called. |
| 38 | presenter_->set_abort([this] { return pacer_.suspended(); }); | 39 | presenter_->set_abort([this] { return pacer_.suspended(); }); |
| 39 | // LEONIDA_SDR_EOTF=gamma22 (or 2.2, any case) decodes SDR with a pure power of 2.2 instead of piecewise sRGB; "srgb" or | 40 | // LEONIDA_SDR_EOTF=gamma22 (or 2.2, any case) decodes SDR with a pure power of 2.2 instead of piecewise sRGB; "srgb" or |
| @@ -316,4 +317,39 @@ HRESULT XboxPresentation::ResumeX() { | |||
| 316 | return S_OK; | 317 | return S_OK; |
| 317 | } | 318 | } |
| 318 | 319 | ||
| 320 | bool attach_xbox_presentation(void* device_proxy, XboxPresentation* presentation) { | ||
| 321 | if (!presentation) return rt::d3d12_xs::set_presentation_handler(device_proxy, nullptr); | ||
| 322 | rt::d3d12_xs::PresentationHandler handler{}; | ||
| 323 | handler.context = presentation; | ||
| 324 | handler.set_frame_interval = [](void* ctx, IUnknown* output, UINT interval_us, UINT latency, UINT flags) { | ||
| 325 | return static_cast<XboxPresentation*>(ctx)->SetFrameIntervalX(output, interval_us, latency, flags); | ||
| 326 | }; | ||
| 327 | handler.schedule_frame_event = [](void* ctx, UINT event, UINT offset_us, UINT flags) { | ||
| 328 | return static_cast<XboxPresentation*>(ctx)->ScheduleFrameEventX(event, offset_us, flags); | ||
| 329 | }; | ||
| 330 | handler.wait_frame_event = [](void* ctx, UINT event, DWORD timeout_ms, UINT flags, std::uint64_t* token) { | ||
| 331 | return static_cast<XboxPresentation*>(ctx)->WaitFrameEventX(event, timeout_ms, flags, token); | ||
| 332 | }; | ||
| 333 | handler.get_frame_statistics = [](void* ctx, std::uint64_t token, UINT type_mask, UINT* count, void* out) { | ||
| 334 | return static_cast<XboxPresentation*>(ctx)->GetFrameStatisticsX( | ||
| 335 | token, type_mask, count, static_cast<leonida::FrameStatistic*>(out)); | ||
| 336 | }; | ||
| 337 | handler.present_x = [](void* ctx, UINT plane_count, const void* planes, const void* params) { | ||
| 338 | return static_cast<XboxPresentation*>(ctx)->PresentX( | ||
| 339 | plane_count, static_cast<const XboxPresentPlaneParameters*>(planes), | ||
| 340 | static_cast<const XboxPresentParameters*>(params)); | ||
| 341 | }; | ||
| 342 | handler.suspend_x = [](void* ctx, UINT flags) { | ||
| 343 | return static_cast<XboxPresentation*>(ctx)->SuspendX(flags); | ||
| 344 | }; | ||
| 345 | handler.resume_x = [](void* ctx) { | ||
| 346 | return static_cast<XboxPresentation*>(ctx)->ResumeX(); | ||
| 347 | }; | ||
| 348 | return rt::d3d12_xs::set_presentation_handler(device_proxy, &handler); | ||
| 349 | } | ||
| 350 | |||
| 351 | bool detach_xbox_presentation(void* device_proxy) { | ||
| 352 | return rt::d3d12_xs::set_presentation_handler(device_proxy, nullptr); | ||
| 353 | } | ||
| 354 | |||
| 319 | } // namespace rt::d3d12 | 355 | } // namespace rt::d3d12 |