Skip to content

measure the peak of each frame for the SDR conversion, registry only - #291

Closed
adipose wants to merge 2 commits into
Aleksoid1978:masterfrom
adipose:sdr-peak-measure-upstream
Closed

adipose wants to merge 2 commits into
Aleksoid1978:masterfrom
adipose:sdr-peak-measure-upstream

Conversation

@adipose

@adipose adipose commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

I split this out of #290 so that one can go in without it. It builds on #290, and only the top commit is new here.

This takes the content peak from each frame instead of the metadata, when the Metadata method is selected. It has no controls on the settings page, only registry values:

  1. SdrMeasurePeak, off by default.
  2. SdrPeakWindowMs, 3000. The peak is averaged over this window.
  3. SdrPeakFloorNits, 640. The peak never goes below this.
  4. SdrPeakSceneCuts, off. Restarts the window at a scene change.

Direct3D 11 builds a histogram in a compute shader. Direct3D 9 has no compute shader, so it reduces the frame to one texel in ps_3_0. The statistics show the frame peak and the peak in use.

It only runs where the conversion is a correction pass after the video processor. When the shaders do the conversion it falls back to the metadata.

A flat PQ 0.65 field (390 nits, MaxCLL 2000) at 200 nits goes to the 640 floor. It should be 235.2 and it reads 235.5 on Direct3D 11 and 234.1 on Direct3D 9.

The Fixed method is the existing curve and stays the default. The Metadata
method builds the curve from the content's peak and the SDR display nits:
MaxCLL, then the mastering display peak, then 1000 nits. Dolby Vision
profile 5 has no HDR10 metadata, so its RPU supplies the same values, from
level 6 or source_max_pq.

It works the same on Direct3D 9 and 11, through the video processor or the
shaders, for PQ, HLG and Dolby Vision.
With the Metadata method, SdrMeasurePeak takes the content peak from each
frame instead of the metadata. Direct3D 11 builds a histogram in a compute
shader. Direct3D 9 has none, so the frame is reduced in ps_3_0 to a single
texel. Both smooth the peak over a window.

The settings are only read from the registry, with no controls on the page:
SdrMeasurePeak, SdrPeakWindowMs (default 3000), SdrPeakFloorNits (default
640) and SdrPeakSceneCuts. The statistics show the peak in use.
@Aleksoid1978

Copy link
Copy Markdown
Owner

That is definitely not necessary. No one is going to enable it via the registry, and 99.99% of users don't need it anyway.

@clsid2

clsid2 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Enabling this can be done by adding extra choice in dropdown after other patch is added first that gives the fixed/metadata choices.

@Aleksoid1978

Copy link
Copy Markdown
Owner

Why go to such lengths and write so much code just for SDR conversion? Anyone who wants HDR watches it on a screen that supports HDR output.

@clsid2

clsid2 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

There are plenty of people who don't have a HDR screen.

And the measuring of peak nits can probably also be utilized for the local tonemapping to further improve that quality as well.

@Aleksoid1978

Copy link
Copy Markdown
Owner

What’s wrong with local tone mapping? It works based on metadata—the same way media players and TVs do.

@clsid2

clsid2 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Metadata with a single peak value for entire movie does not give optimal result.
Explained here:
clsid2#2
Measuring is one of the big reasons why Madvr has better HDR quality, also for local tonemapping.

It is is same reason why HDR10+ with dynamic metadata is better than basic HDR10. The metadata is adjusted per frame/scene.

@Aleksoid1978

Copy link
Copy Markdown
Owner

I know.

@adipose

adipose commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for looking at it. On the one hand you don't see the point but on the other hand you understand the gap it closes.

On my office monitor I have disabled HDR because I don't like the levels it puts out. Tone mapping is very useful in that case, and better tone mapping is better. :)

@Aleksoid1978

Copy link
Copy Markdown
Owner

Alright—go ahead and add it as an option to the current dropdown list.

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