diff options
| author | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 19:45:00 +0100 |
|---|---|---|
| committer | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 19:45:00 +0100 |
| commit | d3b774eed51b76dea1f0ca3888d6b02a997dcd0a (patch) | |
| tree | 00006ce4f15e9b4ba5954aa95dbaeaef2e39083c /runtime/src/present_compose.comp | |
| parent | 09637840630da1db6e126e1a4cffa15c159c8d45 (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/src/present_compose.comp')
| -rw-r--r-- | runtime/src/present_compose.comp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/runtime/src/present_compose.comp b/runtime/src/present_compose.comp index 4592daf70..ff3b0a0c0 100644 --- a/runtime/src/present_compose.comp +++ b/runtime/src/present_compose.comp | |||
| @@ -12,8 +12,8 @@ | |||
| 12 | // it is weighted (SDR: the EOTF, 1.0 = SDR white, Rec.709; HDR10: PQ to nits, Rec.2020). The filtered plane is converted to | 12 | // it is weighted (SDR: the EOTF, 1.0 = SDR white, Rec.709; HDR10: PQ to nits, Rec.2020). The filtered plane is converted to |
| 13 | // the working space of the output (HDR10 output: linear Rec.2020 nits, SDR white = sdr_white nits; SDR output: linear | 13 | // the working space of the output (HDR10 output: linear Rec.2020 nits, SDR white = sdr_white nits; SDR output: linear |
| 14 | // Rec.709, 1.0 = SDR white), plane 1 is blended over plane 0 there, and the sum is encoded once (PQ, or the inverse of | 14 | // Rec.709, 1.0 = SDR white), plane 1 is blended over plane 0 there, and the sum is encoded once (PQ, or the inverse of |
| 15 | // the SDR EOTF). HDR10 plane -> SDR output: extended Reinhard on luminance with the white point at hdr_peak nits, then | 15 | // the SDR EOTF). HDR10 plane -> SDR output: a luminance shoulder (identity below 0.8 of SDR white, extended Reinhard above, peak at |
| 16 | // clipped per channel (no gamut mapping). | 16 | // hdr_peak nits mapped to 1.0), then clipped per channel (no gamut mapping). |
| 17 | #version 450 | 17 | #version 450 |
| 18 | #extension GL_EXT_samplerless_texture_functions : require | 18 | #extension GL_EXT_samplerless_texture_functions : require |
| 19 | 19 | ||
| @@ -106,12 +106,18 @@ vec3 bt2020_to_bt709(vec3 v) { | |||
| 106 | dot(vec3(-0.018151, -0.100579, 1.118730), v)); | 106 | dot(vec3(-0.018151, -0.100579, 1.118730), v)); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | // Extended Reinhard on luminance (Reinhard et al. 2002, eq. 4): Ld = L (1 + L / Lw^2) / (1 + L), colour scaled by Ld / L. | 109 | // Tone map: a shoulder on luminance. Identity up to the knee (0.8 of SDR white), then extended Reinhard (Reinhard et al. |
| 110 | // `v`: linear Rec.709, 1.0 = SDR white; Lw = hdr_peak / sdr_white maps to 1.0. | 110 | // 2002, eq. 4) on the excess, scaled to be continuous in value and slope at the knee and to map the content peak to 1.0: |
| 111 | // with t = 1 - knee, u = (Y - knee) / t, w = (Lw - knee) / t: Yd = knee + t u (1 + u / w^2) / (1 + u). The colour is scaled | ||
| 112 | // by Yd / Y. `v`: linear Rec.709, 1.0 = SDR white; Lw = hdr_peak / sdr_white (at least 1). | ||
| 111 | vec3 tone_map(vec3 v) { | 113 | vec3 tone_map(vec3 v) { |
| 112 | float lw = max(pc.hdr_peak / pc.sdr_white, 1.0); | 114 | const float knee = 0.8; |
| 113 | float y = dot(v, vec3(0.2126, 0.7152, 0.0722)); | 115 | float y = dot(v, vec3(0.2126, 0.7152, 0.0722)); |
| 114 | return v * ((1.0 + y / (lw * lw)) / (1.0 + y)); | 116 | if (y <= knee) return v; |
| 117 | float t = 1.0 - knee; | ||
| 118 | float w = (max(pc.hdr_peak / pc.sdr_white, 1.0) - knee) / t; | ||
| 119 | float u = (y - knee) / t; | ||
| 120 | return v * ((knee + t * u * (1.0 + u / (w * w)) / (1.0 + u)) / y); | ||
| 115 | } | 121 | } |
| 116 | 122 | ||
| 117 | // A linear premultiplied colour of alpha `a` from the plane's space to the output's working space. Both conversions are | 123 | // A linear premultiplied colour of alpha `a` from the plane's space to the output's working space. Both conversions are |