Skip to content

feat(converter): add Bt709LinearToBt2020Pq color space variant#15

Open
lutyjj wants to merge 1 commit into
hgaiser:mainfrom
lutyjj:bt709-linear-bt2020pq
Open

feat(converter): add Bt709LinearToBt2020Pq color space variant#15
lutyjj wants to merge 1 commit into
hgaiser:mainfrom
lutyjj:bt709-linear-bt2020pq

Conversation

@lutyjj
Copy link
Copy Markdown

@lutyjj lutyjj commented May 18, 2026

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant