Skip to content

WaylandBackend: fix overflow when forwarding mastering primaries - #2525

Merged
matte-schwartz merged 1 commit into
ValveSoftware:masterfrom
matte-schwartz:wayland-mastering-primaries-overflow
Oct 30, 2026
Merged

matte-schwartz merged 1 commit into
ValveSoftware:masterfrom
matte-schwartz:wayland-mastering-primaries-overflow

Conversation

@matte-schwartz

Copy link
Copy Markdown
Collaborator

Rescaling the HDR10 mastering display primaries multiplies a 1/50000-unit value by 1'000'000 in 32 bits, which overflows for any realistic chromaticity. The parent compositor receives garbage, often negative, primaries (BT.2020 green arrives as -1798, 23905 instead of 170000, 797000), and KWin shows HDR10 games clipped to SDR.

The ratio between the infoframe unit (1/50000) and the protocol unit (1/1000000) is exactly 20, so multiply by that instead of widening the intermediate. This is exact and cannot overflow.

Closes: #2524

Rescaling the HDR10 mastering display primaries multiplies a 1/50000-unit
value by 1'000'000 in 32 bits, which overflows for any realistic
chromaticity. The parent compositor receives garbage, often negative,
primaries (BT.2020 green arrives as -1798, 23905 instead of 170000,
797000), and KWin shows HDR10 games clipped to SDR.

The ratio between the infoframe unit (1/50000) and the protocol unit
(1/1000000) is exactly 20, so multiply by that instead of widening the
intermediate. This is exact and cannot overflow.

Closes: ValveSoftware#2524
@Delivator

Copy link
Copy Markdown

Nice hdr works fine with this! Thank you.

@matte-schwartz
matte-schwartz merged commit ecc518b into ValveSoftware:master Oct 30, 2026
1 check passed
@matte-schwartz
matte-schwartz deleted the wayland-mastering-primaries-overflow branch October 30, 2026 19:09
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.

HDR detected by game but clipped to SDR

2 participants