Skip to main content

Module hdr

Module hdr 

Source
Expand description

HDR output helpers shared by guests (WGSL) and the host’s self-tests (Rust).

A game renders scene-linear BT.709 color in paper-white units (1.0 = the brightness of SDR white, DEFAULT_PAPER_WHITE_NITS by default) and calls sg_encode_output from WGSL as the last step of its final pass. That function tone-maps to what the output can show and applies the output’s encoding:

OutputModeSurface format / color spaceEncoding
SdrSrgbFormat*UnormSrgb / Srgbroll-off to 1.0; the format applies the sRGB curve
SdrUnorm*Unorm / Srgbroll-off to 1.0, sRGB curve in the shader
ScRgbRgba16Float / ExtendedSrgbLinearroll-off to peak, linear, 1.0 = 80 nits
PqRgb10a2Unorm or Rgba16Float / Bt2100Pqroll-off to peak, BT.709→BT.2020, SMPTE ST 2084

negotiate picks the best mode from a surface’s format capabilities, and falls back to SDR when no HDR color space is offered.

Structs§

Output
The negotiated output: what to put in SurfaceConfiguration and the shader uniform.

Enums§

OutputMode

Constants§

BT709_TO_BT2020
BT.709 → BT.2020 primaries (ITU-R BT.2087), linear light.
DEFAULT_PAPER_WHITE_NITS
BT.2408 reference white for HDR signals.
DEFAULT_PEAK_NITS
Peak assumed when the platform does not report one (Vulkan on Linux never does).
KNEE
Where the highlight roll-off starts, as a fraction of the peak.
SCRGB_NITS
scRGB 1.0 is 80 nits (IEC 61966-2-2).
SDR_KNEE
SDR: identity up to 0.8, then a roll-off towards 1.0 (paper white lands at 0.93).
WGSL
WGSL for guests: paste (or concat!) into a shader module and bind an SgOutput uniform built by Output::uniform.

Functions§

bt709_to_bt2020
encode_output
What sg_encode_output writes for scene-linear BT.709 rgb in paper-white units.
negotiate
Picks the output for a surface offering formats (format, color spaces), in order of preference: PQ on a 10-bit format, scRGB, PQ on fp16, then SDR (an *Srgb format first). allow_hdr = false forces SDR. Returns None only if no format is usable at all.
pq_eotf
SMPTE ST 2084 EOTF: signal → absolute nits.
pq_oetf
SMPTE ST 2084 inverse EOTF: absolute nits → signal in [0, 1].
rolloff
Identity below knee, then an exponential shoulder that approaches peak with a continuous first derivative.
srgb_eotf
srgb_oetf
tonemap
Tone-maps on max(R,G,B) so hue is kept.