diff options
| author | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 19:17:24 +0100 |
|---|---|---|
| committer | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 19:17:24 +0100 |
| commit | 09637840630da1db6e126e1a4cffa15c159c8d45 (patch) | |
| tree | 1640424e353a07e67236534f6cbec4fc4fe5699a /runtime/src/vulkan_present.h | |
| parent | 97daa1aec0e11d9b063b32a5da6c176d55793330 (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/src/vulkan_present.h')
| -rw-r--r-- | runtime/src/vulkan_present.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/runtime/src/vulkan_present.h b/runtime/src/vulkan_present.h index 65a129b0e..09fb4490e 100644 --- a/runtime/src/vulkan_present.h +++ b/runtime/src/vulkan_present.h | |||
| @@ -58,13 +58,19 @@ struct PresentPlane { | |||
| 58 | bool has_source_rect = false; | 58 | bool has_source_rect = false; |
| 59 | float dest[4] = {0, 0, 1, 1}; // left, top, right, bottom as fractions of the output (0..1) | 59 | float dest[4] = {0, 0, 1, 1}; // left, top, right, bottom as fractions of the output (0..1) |
| 60 | bool point_filter = false; // nearest texel; otherwise bilinear inside the source rectangle | 60 | bool point_filter = false; // nearest texel; otherwise bilinear inside the source rectangle |
| 61 | bool hdr10 = false; // the texture holds ST.2084 (PQ) Rec.2020 values; otherwise G2.2 Rec.709 ones | 61 | bool hdr10 = false; // the texture holds ST.2084 (PQ) Rec.2020 values; otherwise sRGB or G2.2 (PresentPlanes::sdr_eotf) Rec.709 ones |
| 62 | bool straight_alpha = false; // plane 1 only: alpha is not premultiplied into the colour | 62 | bool straight_alpha = false; // plane 1 only: alpha is not premultiplied into the colour |
| 63 | }; | 63 | }; |
| 64 | struct PresentPlanes { | 64 | struct PresentPlanes { |
| 65 | PresentPlane plane[2]; | 65 | PresentPlane plane[2]; |
| 66 | std::uint32_t count = 1; | 66 | std::uint32_t count = 1; |
| 67 | float sdr_white_nits = 203.0f; // what SDR white maps to in an HDR10 output, and what HDR10 is divided by for SDR | 67 | // What SDR white maps to in an HDR10 output, and what HDR10 is divided by for an SDR one (the white of the SDR output). |
| 68 | float sdr_white_nits = 203.0f; | ||
| 69 | // How SDR planes (and an SDR output) are encoded: piecewise sRGB (default; what Windows applies to SDR content in HDR | ||
| 70 | // mode, community-sourced, docs section 4.5) or a pure power of 2.2. | ||
| 71 | enum class SdrEotf : std::uint32_t { srgb = 0, gamma22 = 1 }; | ||
| 72 | SdrEotf sdr_eotf = SdrEotf::srgb; | ||
| 73 | float hdr_peak_nits = 1000.0f; // peak of the HDR10 content: the white point of the tone map on an SDR output | ||
| 68 | }; | 74 | }; |
| 69 | 75 | ||
| 70 | namespace detail { | 76 | namespace detail { |
| @@ -230,13 +236,15 @@ public: | |||
| 230 | // destination rectangle of the window, plane 1 blended over plane 0, composed by a compute pass into an RGBA16F image | 236 | // destination rectangle of the window, plane 1 blended over plane 0, composed by a compute pass into an RGBA16F image |
| 231 | // that is then copied to the swapchain image. Colour spaces are converted to the swapchain's: when a plane is HDR10 and | 237 | // that is then copied to the swapchain image. Colour spaces are converted to the swapchain's: when a plane is HDR10 and |
| 232 | // the surface lists an HDR10 (ST.2084) format the swapchain uses it (hdr_active()), else the HDR10 planes are | 238 | // the surface lists an HDR10 (ST.2084) format the swapchain uses it (hdr_active()), else the HDR10 planes are |
| 233 | // converted to SDR by clipping (no tone mapping). The swapchain is always UNORM here; sRGB-format sources are | 239 | // tone mapped to SDR (extended Reinhard, then clipped). Planes are filtered and blended in linear light. The swapchain |
| 240 | // is always UNORM here; sRGB-format sources are | ||
| 234 | // encoded again by the pass. Sources must be single-sample, sampled (no DENY_SHADER_RESOURCE) float/UNORM/sRGB | 241 | // encoded again by the pass. Sources must be single-sample, sampled (no DENY_SHADER_RESOURCE) float/UNORM/sRGB |
| 235 | // colour textures; others are refused (VK_ERROR_FORMAT_NOT_SUPPORTED). Rectangles outside their range give | 242 | // colour textures; others are refused (VK_ERROR_FORMAT_NOT_SUPPORTED). Rectangles outside their range give |
| 236 | // VK_ERROR_UNKNOWN. vsync and `tear` as for present(). | 243 | // VK_ERROR_UNKNOWN. vsync and `tear` as for present(). |
| 237 | VkResult present_planes(const PresentPlanes& planes, bool vsync, bool tear = false) { | 244 | VkResult present_planes(const PresentPlanes& planes, bool vsync, bool tear = false) { |
| 238 | if (planes.count < 1 || planes.count > 2) return VK_ERROR_UNKNOWN; | 245 | if (planes.count < 1 || planes.count > 2) return VK_ERROR_UNKNOWN; |
| 239 | if (!(planes.sdr_white_nits > 0.0f) || !std::isfinite(planes.sdr_white_nits)) return VK_ERROR_UNKNOWN; | 246 | if (!(planes.sdr_white_nits > 0.0f) || !std::isfinite(planes.sdr_white_nits)) return VK_ERROR_UNKNOWN; |
| 247 | if (!(planes.hdr_peak_nits > 0.0f) || !std::isfinite(planes.hdr_peak_nits)) return VK_ERROR_UNKNOWN; | ||
| 240 | for (std::uint32_t i = 0; i < planes.count; ++i) { | 248 | for (std::uint32_t i = 0; i < planes.count; ++i) { |
| 241 | const PresentPlane& plane = planes.plane[i]; | 249 | const PresentPlane& plane = planes.plane[i]; |
| 242 | ResourceBinding binding; | 250 | ResourceBinding binding; |
| @@ -675,6 +683,8 @@ private: | |||
| 675 | push.plane_count = planes.count; | 683 | push.plane_count = planes.count; |
| 676 | push.out_hdr = (hdr_active_ || force_hdr_encoding_) ? 1u : 0u; | 684 | push.out_hdr = (hdr_active_ || force_hdr_encoding_) ? 1u : 0u; |
| 677 | push.sdr_white = planes.sdr_white_nits; | 685 | push.sdr_white = planes.sdr_white_nits; |
| 686 | push.sdr_eotf = std::uint32_t(planes.sdr_eotf); | ||
| 687 | push.hdr_peak = planes.hdr_peak_nits; | ||
| 678 | push.width = extent_.width; | 688 | push.width = extent_.width; |
| 679 | push.height = extent_.height; | 689 | push.height = extent_.height; |
| 680 | composer_->record(commands, slot, frame.views[0], read_layout[0], frame.views[1] ? frame.views[1] : frame.views[0], | 690 | composer_->record(commands, slot, frame.views[0], read_layout[0], frame.views[1] ? frame.views[1] : frame.views[0], |
| @@ -902,7 +912,7 @@ private: | |||
| 902 | if (!found && !warned_hdr_) { | 912 | if (!found && !warned_hdr_) { |
| 903 | warned_hdr_ = true; | 913 | warned_hdr_ = true; |
| 904 | std::fprintf(stderr, "[rt] present: the surface has no HDR10 (ST.2084) format; HDR10 planes are converted to " | 914 | std::fprintf(stderr, "[rt] present: the surface has no HDR10 (ST.2084) format; HDR10 planes are converted to " |
| 905 | "SDR by clipping\n"); | 915 | "SDR by tone mapping\n"); |
| 906 | } | 916 | } |
| 907 | } | 917 | } |
| 908 | for (const VkFormat wanted : srgb ? std::array<VkFormat, 2>{VK_FORMAT_B8G8R8A8_SRGB, VK_FORMAT_R8G8B8A8_SRGB} | 918 | for (const VkFormat wanted : srgb ? std::array<VkFormat, 2>{VK_FORMAT_B8G8R8A8_SRGB, VK_FORMAT_R8G8B8A8_SRGB} |