feat(converter): add Bt709LinearToBt2020Pq color space variant#15
Open
lutyjj wants to merge 1 commit into
Open
feat(converter): add Bt709LinearToBt2020Pq color space variant#15lutyjj wants to merge 1 commit into
lutyjj wants to merge 1 commit into
Conversation
Adds a fourth ColorSpace variant for scRGB-linear (BT.709 primaries, linear-light) FP16 input converted to BT.2020+PQ output. Distinct from SrgbToBt2020Pq in that the sRGB EOTF is skipped — scRGB is already linear, and frequently carries values > 1.0 representing HDR highlights beyond SDR white. Routing those through srgb_to_linear() would clamp to [0, 1] and crush exactly the range that needs to survive encode. The remaining math matches SrgbToBt2020Pq: BT.709→BT.2020 gamut mapping in linear light, scale by sdr_reference_white_nits / 10000, then PQ OETF. Reference white differs by source convention — 203 nits for ITU-R BT.2408 SDR-in-HDR (existing default) versus 80 nits for the scRGB spec (IEC 61966-2-2, 1.0 == 80 cd/m²). DXVK's dxvk_color_space.glsl splits these the same way. Required for HDR streaming of DX12 games running under VKD3D-Proton: their swapchains negotiate DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 → VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT (CryEngine titles, Kingdom Come: Deliverance II, Witcher 3 Next-Gen) and submit FP16 linear BT.709 buffers. Without this variant there is no correct encode path for that input: SrgbToBt2020Pq clamps the highlights, Bt2020 passthrough skips the PQ encode entirely. Also adds a runtime setter for sdr_reference_white_nits so callers can flip between 80 and 203 per-frame without rebuilding the converter, mirroring set_color_space / set_full_range — needed when the upstream compositor's color space changes at runtime (e.g. menu ↔ game toggling between sRGB and scRGB). Purely additive: existing Bt709 / Bt2020 / SrgbToBt2020Pq paths are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a fourth ColorSpace variant for scRGB-linear (BT.709 primaries, linear-light) FP16 input converted to BT.2020+PQ output. Distinct from SrgbToBt2020Pq in that the sRGB EOTF is skipped — scRGB is already linear, and frequently carries values > 1.0 representing HDR highlights beyond SDR white. Routing those through srgb_to_linear() would clamp to [0, 1] and crush exactly the range that needs to survive encode.
The remaining math matches SrgbToBt2020Pq: BT.709→BT.2020 gamut mapping in linear light, scale by sdr_reference_white_nits / 10000, then PQ OETF. Reference white differs by source convention — 203 nits for ITU-R BT.2408 SDR-in-HDR (existing default) versus 80 nits for the scRGB spec (IEC 61966-2-2, 1.0 == 80 cd/m²). DXVK's dxvk_color_space.glsl splits these the same way.
Required for HDR streaming of DX12 games running under VKD3D-Proton: their swapchains negotiate
DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 → VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT (CryEngine titles, Kingdom Come: Deliverance II, Witcher 3 Next-Gen) and submit FP16 linear BT.709 buffers. Without this variant there is no correct encode path for that input.
Also adds a runtime setter for sdr_reference_white_nits so callers can flip between 80 and 203 per-frame without rebuilding the converter, mirroring set_color_space / set_full_range — needed when the upstream compositor's color space changes at runtime (e.g. menu ↔ game toggling between sRGB and scRGB, had this in KCD2 - in main menu, when there's no mouse HDR was working fine, but once you start moving the cursor - bam, HDR is gone).
Purely additive, existing Bt709 / Bt2020 / SrgbToBt2020Pq paths are unchanged.
Continuation of hgaiser/moonshine#87.