diff options
| author | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-23 02:15:15 +0100 |
|---|---|---|
| committer | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-23 02:15:15 +0100 |
| commit | 003baa94c1fcba61e324dbeb947e8bd401f4f837 (patch) | |
| tree | 10c60314513d90af84a03ad7e814b0772ba12db8 /runtime/src/vulkan_present.h | |
| parent | 48cee7c2c69e502cc864b0789a9cf5bb88e98658 (diff) | |
| parent | 03b09a086592a197db64d91655c6e65c30764d96 (diff) | |
Merge origin/main into queue-wait-before-signal
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 8c3329c1e..5c8e1477e 100644 --- a/runtime/src/vulkan_present.h +++ b/runtime/src/vulkan_present.h | |||
| @@ -63,13 +63,19 @@ struct PresentPlane { | |||
| 63 | bool has_source_rect = false; | 63 | bool has_source_rect = false; |
| 64 | float dest[4] = {0, 0, 1, 1}; // left, top, right, bottom as fractions of the output (0..1) | 64 | float dest[4] = {0, 0, 1, 1}; // left, top, right, bottom as fractions of the output (0..1) |
| 65 | bool point_filter = false; // nearest texel; otherwise bilinear inside the source rectangle | 65 | bool point_filter = false; // nearest texel; otherwise bilinear inside the source rectangle |
| 66 | bool hdr10 = false; // the texture holds ST.2084 (PQ) Rec.2020 values; otherwise G2.2 Rec.709 ones | 66 | bool hdr10 = false; // the texture holds ST.2084 (PQ) Rec.2020 values; otherwise sRGB or G2.2 (PresentPlanes::sdr_eotf) Rec.709 ones |
| 67 | bool straight_alpha = false; // plane 1 only: alpha is not premultiplied into the colour | 67 | bool straight_alpha = false; // plane 1 only: alpha is not premultiplied into the colour |
| 68 | }; | 68 | }; |
| 69 | struct PresentPlanes { | 69 | struct PresentPlanes { |
| 70 | PresentPlane plane[2]; | 70 | PresentPlane plane[2]; |
| 71 | std::uint32_t count = 1; | 71 | std::uint32_t count = 1; |
| 72 | float sdr_white_nits = 203.0f; // what SDR white maps to in an HDR10 output, and what HDR10 is divided by for SDR | 72 | // 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). |
| 73 | float sdr_white_nits = 203.0f; | ||
| 74 | // How SDR planes (and an SDR output) are encoded: piecewise sRGB (default; what Windows applies to SDR content in HDR | ||
| 75 | // mode, community-sourced, docs section 4.5) or a pure power of 2.2. | ||
| 76 | enum class SdrEotf : std::uint32_t { srgb = 0, gamma22 = 1 }; | ||
| 77 | SdrEotf sdr_eotf = SdrEotf::srgb; | ||
| 78 | float hdr_peak_nits = 1000.0f; // peak of the HDR10 content: the white point of the tone map on an SDR output | ||
| 73 | }; | 79 | }; |
| 74 | 80 | ||
| 75 | namespace detail { | 81 | namespace detail { |
| @@ -240,13 +246,15 @@ public: | |||
| 240 | // destination rectangle of the window, plane 1 blended over plane 0, composed by a compute pass into an RGBA16F image | 246 | // destination rectangle of the window, plane 1 blended over plane 0, composed by a compute pass into an RGBA16F image |
| 241 | // that is then copied to the swapchain image. Colour spaces are converted to the swapchain's: when a plane is HDR10 and | 247 | // that is then copied to the swapchain image. Colour spaces are converted to the swapchain's: when a plane is HDR10 and |
| 242 | // the surface lists an HDR10 (ST.2084) format the swapchain uses it (hdr_active()), else the HDR10 planes are | 248 | // the surface lists an HDR10 (ST.2084) format the swapchain uses it (hdr_active()), else the HDR10 planes are |
| 243 | // converted to SDR by clipping (no tone mapping). The swapchain is always UNORM here; sRGB-format sources are | 249 | // tone mapped to SDR (shoulder above 0.8 of SDR white, then clipped). Planes are filtered and blended in linear light. The swapchain |
| 250 | // is always UNORM here; sRGB-format sources are | ||
| 244 | // encoded again by the pass. Sources must be single-sample, sampled (no DENY_SHADER_RESOURCE) float/UNORM/sRGB | 251 | // encoded again by the pass. Sources must be single-sample, sampled (no DENY_SHADER_RESOURCE) float/UNORM/sRGB |
| 245 | // colour textures; others are refused (VK_ERROR_FORMAT_NOT_SUPPORTED). Rectangles outside their range give | 252 | // colour textures; others are refused (VK_ERROR_FORMAT_NOT_SUPPORTED). Rectangles outside their range give |
| 246 | // VK_ERROR_UNKNOWN. vsync and `tear` as for present(). | 253 | // VK_ERROR_UNKNOWN. vsync and `tear` as for present(). |
| 247 | VkResult present_planes(const PresentPlanes& planes, bool vsync, bool tear = false) { | 254 | VkResult present_planes(const PresentPlanes& planes, bool vsync, bool tear = false) { |
| 248 | if (planes.count < 1 || planes.count > 2) return VK_ERROR_UNKNOWN; | 255 | if (planes.count < 1 || planes.count > 2) return VK_ERROR_UNKNOWN; |
| 249 | if (!(planes.sdr_white_nits > 0.0f) || !std::isfinite(planes.sdr_white_nits)) return VK_ERROR_UNKNOWN; | 256 | if (!(planes.sdr_white_nits > 0.0f) || !std::isfinite(planes.sdr_white_nits)) return VK_ERROR_UNKNOWN; |
| 257 | if (!(planes.hdr_peak_nits > 0.0f) || !std::isfinite(planes.hdr_peak_nits)) return VK_ERROR_UNKNOWN; | ||
| 250 | for (std::uint32_t i = 0; i < planes.count; ++i) { | 258 | for (std::uint32_t i = 0; i < planes.count; ++i) { |
| 251 | const PresentPlane& plane = planes.plane[i]; | 259 | const PresentPlane& plane = planes.plane[i]; |
| 252 | ResourceBinding binding; | 260 | ResourceBinding binding; |
| @@ -776,6 +784,8 @@ private: | |||
| 776 | push.plane_count = planes.count; | 784 | push.plane_count = planes.count; |
| 777 | push.out_hdr = (hdr_active_ || force_hdr_encoding_) ? 1u : 0u; | 785 | push.out_hdr = (hdr_active_ || force_hdr_encoding_) ? 1u : 0u; |
| 778 | push.sdr_white = planes.sdr_white_nits; | 786 | push.sdr_white = planes.sdr_white_nits; |
| 787 | push.sdr_eotf = std::uint32_t(planes.sdr_eotf); | ||
| 788 | push.hdr_peak = planes.hdr_peak_nits; | ||
| 779 | push.width = extent_.width; | 789 | push.width = extent_.width; |
| 780 | push.height = extent_.height; | 790 | push.height = extent_.height; |
| 781 | composer_->record(commands, slot, frame.views[0], read_layout[0], frame.views[1] ? frame.views[1] : frame.views[0], | 791 | composer_->record(commands, slot, frame.views[0], read_layout[0], frame.views[1] ? frame.views[1] : frame.views[0], |
| @@ -1003,7 +1013,7 @@ private: | |||
| 1003 | if (!found && !warned_hdr_) { | 1013 | if (!found && !warned_hdr_) { |
| 1004 | warned_hdr_ = true; | 1014 | warned_hdr_ = true; |
| 1005 | std::fprintf(stderr, "[rt] present: the surface has no HDR10 (ST.2084) format; HDR10 planes are converted to " | 1015 | std::fprintf(stderr, "[rt] present: the surface has no HDR10 (ST.2084) format; HDR10 planes are converted to " |
| 1006 | "SDR by clipping\n"); | 1016 | "SDR by tone mapping\n"); |
| 1007 | } | 1017 | } |
| 1008 | } | 1018 | } |
| 1009 | for (const VkFormat wanted : srgb ? std::array<VkFormat, 2>{VK_FORMAT_B8G8R8A8_SRGB, VK_FORMAT_R8G8B8A8_SRGB} | 1019 | for (const VkFormat wanted : srgb ? std::array<VkFormat, 2>{VK_FORMAT_B8G8R8A8_SRGB, VK_FORMAT_R8G8B8A8_SRGB} |