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:
authorAlxcBTW <187763517+AlxcBTW@users.noreply.github.com>2026-11-22 19:17:24 +0100
committerAlxcBTW <187763517+AlxcBTW@users.noreply.github.com>2026-11-22 19:17:24 +0100
commit09637840630da1db6e126e1a4cffa15c159c8d45 (patch)
tree1640424e353a07e67236534f6cbec4fc4fe5699a /runtime/shims/xbox_present.cpp
parent97daa1aec0e11d9b063b32a5da6c176d55793330 (diff)
PresentX planes: filter and blend in linear light, selectable SDR EOTF, Windows SDR white level, tone map
- Compose pass decodes every texel to linear (premultiplied) before filtering, converts the plane to the output's linear working space (Rec.2020 nits for HDR10, Rec.709 relative to SDR white for SDR), blends there and encodes once. - SDR EOTF is piecewise sRGB by default (community-sourced Windows behaviour), gamma 2.2 by XboxPresentation::set_sdr_eotf or LEONIDA_SDR_EOTF=gamma22. - SDR white: set_sdr_white_nits override, else DISPLAYCONFIG_SDR_WHITE_LEVEL of the window's output while HDR10 is active, else 203 nits (BT.2408). - HDR10 on an SDR output: extended Reinhard on luminance (white point at the content peak, default 1000 nits) instead of a hard clip. - HDR metadata stays unsent; docs section 4.5 documents the decisions and cites the sources. - CPU reference model and xbox_present_test updated (linear model, EOTF option, 50% overlay, tone map, white level query). - present_compose.inc rebuilt with glslc 2026.4 (byte-reproducible, spirv-val clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/xbox_present.cpp')
-rw-r--r--runtime/shims/xbox_present.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/runtime/shims/xbox_present.cpp b/runtime/shims/xbox_present.cpp
index 54c74b959..a2c16ca19 100644
--- a/runtime/shims/xbox_present.cpp
+++ b/runtime/shims/xbox_present.cpp
@@ -2,7 +2,10 @@
2 2
3#include "../src/vulkan_present.h" 3#include "../src/vulkan_present.h"
4 4
5#include <chrono>
5#include <cstdio> 6#include <cstdio>
7#include <cstdlib>
8#include <cstring>
6 9
7namespace rt::d3d12 { 10namespace rt::d3d12 {
8 11
@@ -28,10 +31,27 @@ XboxPresentation::XboxPresentation(std::unique_ptr<WindowPresenter> presenter, l
28 pacer_(clock ? *clock : *own_clock_) { 31 pacer_(clock ? *clock : *own_clock_) {
29 // A present waiting for a swapchain image gives up once SuspendX has been called. 32 // A present waiting for a swapchain image gives up once SuspendX has been called.
30 presenter_->set_abort([this] { return pacer_.suspended(); }); 33 presenter_->set_abort([this] { return pacer_.suspended(); });
34 // LEONIDA_SDR_EOTF=gamma22 (or 2.2) decodes SDR with a pure power of 2.2 instead of piecewise sRGB.
35 char eotf[16] = {};
36 std::size_t eotf_length = 0;
37 if (getenv_s(&eotf_length, eotf, "LEONIDA_SDR_EOTF") == 0 && eotf_length > 1 &&
38 (!std::strcmp(eotf, "gamma22") || !std::strcmp(eotf, "2.2")))
39 sdr_eotf_ = leonida::PresentPlanes::SdrEotf::gamma22;
31} 40}
32 41
33XboxPresentation::~XboxPresentation() { presenter_->set_abort(nullptr); } 42XboxPresentation::~XboxPresentation() { presenter_->set_abort(nullptr); }
34 43
44float XboxPresentation::effective_sdr_white_nits() {
45 if (sdr_white_override_ > 0.0f) return sdr_white_override_;
46 if (!presenter_->hdr_active()) return 203.0f; // the Windows setting belongs to HDR mode
47 const auto now = std::chrono::steady_clock::now();
48 if (display_white_time_ == std::chrono::steady_clock::time_point{} || now - display_white_time_ > std::chrono::seconds(1)) {
49 display_white_ = presenter_->display_sdr_white_nits();
50 display_white_time_ = now;
51 }
52 return display_white_ > 0.0f ? display_white_ : 203.0f;
53}
54
35HRESULT XboxPresentation::SetFrameIntervalX(IUnknown*, UINT interval_period_us, UINT latency, UINT flags) { 55HRESULT XboxPresentation::SetFrameIntervalX(IUnknown*, UINT interval_period_us, UINT latency, UINT flags) {
36 return from_pacer(pacer_.set_frame_interval(interval_period_us, latency, flags)); 56 return from_pacer(pacer_.set_frame_interval(interval_period_us, latency, flags));
37} 57}
@@ -150,7 +170,9 @@ HRESULT XboxPresentation::PresentX(UINT plane_count, const XboxPresentPlaneParam
150 // Every shown plane: a 2D texture, a source rectangle inside it, a placement inside the output. 170 // Every shown plane: a 2D texture, a source rectangle inside it, a placement inside the output.
151 leonida::PresentPlanes composed; 171 leonida::PresentPlanes composed;
152 composed.count = overlay ? 2 : 1; 172 composed.count = overlay ? 2 : 1;
153 composed.sdr_white_nits = sdr_white_nits_; 173 composed.sdr_white_nits = effective_sdr_white_nits();
174 composed.sdr_eotf = sdr_eotf_;
175 composed.hdr_peak_nits = hdr_peak_nits_;
154 for (UINT i = 0; i < composed.count; ++i) { 176 for (UINT i = 0; i < composed.count; ++i) {
155 const XboxPresentPlaneParameters& p = planes[i]; 177 const XboxPresentPlaneParameters& p = planes[i];
156 ID3D12Resource* source = p.ppResources[0]; 178 ID3D12Resource* source = p.ppResources[0];