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:45:00 +0100
committerAlxcBTW <187763517+AlxcBTW@users.noreply.github.com>2026-11-22 19:45:00 +0100
commitd3b774eed51b76dea1f0ca3888d6b02a997dcd0a (patch)
tree00006ce4f15e9b4ba5954aa95dbaeaef2e39083c /runtime/shims/xbox_present.cpp
parent09637840630da1db6e126e1a4cffa15c159c8d45 (diff)
PresentX planes: tone map shoulder, SDR white query off the present path, review fixes
- Tone map: identity up to 0.8 of SDR white, extended Reinhard shoulder above it, continuous in value and slope, content peak maps to 1.0 (SDR-range content is no longer darkened). - The Windows SDR white level is read by a background thread (about once a second, only while HDR10 is in use); PresentX reads an atomic. A failed query keeps the last good value; QueryDisplayConfig retries on ERROR_INSUFFICIENT_BUFFER. - LEONIDA_SDR_EOTF is case-insensitive, unknown or too long values are logged; setters are atomics; <cwchar> for wcscmp. - Tests: eight-step HDR10 ramp with hand-calculated bytes, curve properties (monotonic, identity below the knee, peak 1, slope continuity), HDR10 plane 1 over SDR plane 0 on HDR10 and SDR outputs, hand-calculated 50% overlay bytes, query cost. - Docs 4.5: shoulder description, query cost, sources marked (KWin claim unverified, vkd3d-proton file partly read, the measured 80 nits only covers the SDR fallback path). - present_compose.inc rebuilt with glslc 2026.4 (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.cpp54
1 files changed, 43 insertions, 11 deletions
diff --git a/runtime/shims/xbox_present.cpp b/runtime/shims/xbox_present.cpp
index a2c16ca19..9e20c28d6 100644
--- a/runtime/shims/xbox_present.cpp
+++ b/runtime/shims/xbox_present.cpp
@@ -2,6 +2,7 @@
2 2
3#include "../src/vulkan_present.h" 3#include "../src/vulkan_present.h"
4 4
5#include <cerrno>
5#include <chrono> 6#include <chrono>
6#include <cstdio> 7#include <cstdio>
7#include <cstdlib> 8#include <cstdlib>
@@ -31,25 +32,56 @@ XboxPresentation::XboxPresentation(std::unique_ptr<WindowPresenter> presenter, l
31 pacer_(clock ? *clock : *own_clock_) { 32 pacer_(clock ? *clock : *own_clock_) {
32 // A present waiting for a swapchain image gives up once SuspendX has been called. 33 // A present waiting for a swapchain image gives up once SuspendX has been called.
33 presenter_->set_abort([this] { return pacer_.suspended(); }); 34 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 // LEONIDA_SDR_EOTF=gamma22 (or 2.2, any case) decodes SDR with a pure power of 2.2 instead of piecewise sRGB; "srgb" or
35 char eotf[16] = {}; 36 // unset keeps the default; anything else (also a value too long for the buffer, ERANGE) is logged once and ignored.
37 char eotf[32] = {};
36 std::size_t eotf_length = 0; 38 std::size_t eotf_length = 0;
37 if (getenv_s(&eotf_length, eotf, "LEONIDA_SDR_EOTF") == 0 && eotf_length > 1 && 39 const errno_t env = getenv_s(&eotf_length, eotf, "LEONIDA_SDR_EOTF");
38 (!std::strcmp(eotf, "gamma22") || !std::strcmp(eotf, "2.2"))) 40 if (env == 0 && eotf_length > 1) {
39 sdr_eotf_ = leonida::PresentPlanes::SdrEotf::gamma22; 41 if (!_stricmp(eotf, "gamma22") || !_stricmp(eotf, "2.2")) sdr_eotf_ = leonida::PresentPlanes::SdrEotf::gamma22;
42 else if (_stricmp(eotf, "srgb") != 0)
43 std::fprintf(stderr, "[rt] present: LEONIDA_SDR_EOTF=%s is not srgb, gamma22 or 2.2: piecewise sRGB used\n", eotf);
44 } else if (env == ERANGE) {
45 std::fprintf(stderr, "[rt] present: LEONIDA_SDR_EOTF is too long to be srgb, gamma22 or 2.2: piecewise sRGB used\n");
46 }
47 display_white_thread_ = std::thread([this] { display_white_worker(); });
48}
49
50XboxPresentation::~XboxPresentation() {
51 {
52 std::lock_guard lock(worker_mutex_);
53 worker_stop_ = true;
54 }
55 worker_wake_.notify_all();
56 display_white_thread_.join();
57 presenter_->set_abort(nullptr);
40} 58}
41 59
42XboxPresentation::~XboxPresentation() { presenter_->set_abort(nullptr); } 60// Windows' SDR white level costs a QueryDisplayConfig and two DisplayConfigGetDeviceInfo calls (measured in
61// xbox_present_test, docs section 4.5): too much for the present path, which would hitch once a second and feed the pacer.
62// So it is read here, about once a second while an HDR10 swapchain is in use, and PresentX reads the cached value.
63void XboxPresentation::display_white_worker() {
64 std::unique_lock lock(worker_mutex_);
65 while (!worker_stop_) {
66 if (white_wanted_.load()) {
67 lock.unlock();
68 const float nits = presenter_->display_sdr_white_nits();
69 if (nits > 0.0f) display_white_ = nits; // a failed query keeps the last good value
70 lock.lock();
71 }
72 worker_wake_.wait_for(lock, std::chrono::seconds(1), [this] { return worker_stop_; });
73 }
74}
43 75
44float XboxPresentation::effective_sdr_white_nits() { 76float XboxPresentation::effective_sdr_white_nits() {
45 if (sdr_white_override_ > 0.0f) return sdr_white_override_; 77 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 78 if (!presenter_->hdr_active()) return 203.0f; // the Windows setting belongs to HDR mode
47 const auto now = std::chrono::steady_clock::now(); 79 if (!white_wanted_.exchange(true)) { // first HDR10 present: have it read now
48 if (display_white_time_ == std::chrono::steady_clock::time_point{} || now - display_white_time_ > std::chrono::seconds(1)) { 80 std::lock_guard lock(worker_mutex_);
49 display_white_ = presenter_->display_sdr_white_nits(); 81 worker_wake_.notify_all();
50 display_white_time_ = now;
51 } 82 }
52 return display_white_ > 0.0f ? display_white_ : 203.0f; 83 const float cached = display_white_;
84 return cached > 0.0f ? cached : 203.0f;
53} 85}
54 86
55HRESULT XboxPresentation::SetFrameIntervalX(IUnknown*, UINT interval_period_us, UINT latency, UINT flags) { 87HRESULT XboxPresentation::SetFrameIntervalX(IUnknown*, UINT interval_period_us, UINT latency, UINT flags) {