Skip to content

WaylandBackend: fix integer overflow when forwarding mastering primaries - #2523

Closed
Delivator wants to merge 1 commit into
ValveSoftware:masterfrom
Delivator:waylandbackend-fix-mastering-primaries-overflow
Closed

Delivator wants to merge 1 commit into
ValveSoftware:masterfrom
Delivator:waylandbackend-fix-mastering-primaries-overflow

Conversation

@Delivator

Copy link
Copy Markdown

Note

This PR was written entirely by an AI (Claude Code). I (Delivator) don't have technical knowledge here — I just want to play games in HDR and I'm happy if this helps. I tested it on my machine and can provide logs.

The mastering display primaries are rescaled from 0.00002 to 1e-6 units in 32-bit, which overflows (35400 * 1'000'000). Compositors get garbage, often negative, chromaticities:

before: set_mastering_display_primaries(20805, 34301, -1798, 23905, -40798, -39899, -30897, -14597)
after:  set_mastering_display_primaries(708000, 292000, 170000, 797000, 131000, 46000, 312700, 329000)

On KDE Plasma 6.8.1 (nested, --hdr-enabled, HDR10 game) this clipped the picture to SDR; with the fix HDR works again.

Related: #2091.

🤖 Generated with Claude Code

The HDR10 mastering display primaries and white point (units of 0.00002)
were rescaled to wp-color-management units (1e-6) with
`(int32_t)x * 1'000'000 / 0xC350`, which overflows int32 for any value
above ~2147. Compositors therefore received garbage, often negative,
chromaticities, e.g. for BT.2020/D65 metadata:

  set_mastering_display_primaries(20805, 34301, -1798, 23905,
                                  -40798, -39899, -30897, -14597)

instead of (708000, 292000, 170000, 797000, 131000, 46000, 312700,
329000). KWin 6.8 derives the clip range and tone mapping from the
mastering volume, which clipped HDR10 content to SDR in nested gamescope.

Do the multiplication in 64-bit before narrowing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kisak-valve

Copy link
Copy Markdown
Member

If you don't understand the code in a pull request you're making, don't post it.

@matte-schwartz

Copy link
Copy Markdown
Collaborator

if you find real bugs, please just report them using the template. the burden of sifting through llm output to try and find actual bugs is a lot easier if you just keep things short and simple in an issue, in particular steps to reproduce the issue.

@Delivator

Copy link
Copy Markdown
Author

Yeah you're right my bad. I do have a real bug which this fixed (for me at least) Will create an issue now.

@Delivator Delivator mentioned this pull request Oct 28, 2026
3 of 6 tasks
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.

3 participants