feat(hdr): HDR contrast row, also grading the game's native HDR #1941
Closed
j64esatxzdrhfg wants to merge 1 commit from
j64esatxzdrhfg/feat/hdr-contrast into main
pull from: j64esatxzdrhfg/feat/hdr-contrast
merge into: MagicBeanDev:main
MagicBeanDev:main
MagicBeanDev:github/pr/2893
MagicBeanDev:github/pr/2890
MagicBeanDev:github/pr/2887
MagicBeanDev:github/pr/2878
MagicBeanDev:github/pr/2875
MagicBeanDev:github/pr/2874
MagicBeanDev:github/pr/2873
MagicBeanDev:github/pr/2871
MagicBeanDev:github/pr/2756
MagicBeanDev:github/pr/2897
MagicBeanDev:github/pr/2896
MagicBeanDev:github/pr/2718
MagicBeanDev:github/pr/2842
MagicBeanDev:github/pr/2691
MagicBeanDev:github/pr/2895
MagicBeanDev:github/pr/2743
MagicBeanDev:github/pr/2765
MagicBeanDev:github/pr/2708
MagicBeanDev:github/pr/2732
MagicBeanDev:github/pr/2755
MagicBeanDev:github/pr/2817
MagicBeanDev:github/pr/2876
MagicBeanDev:release-please--branches--main
MagicBeanDev:release-please--branches--main--release-notes
MagicBeanDev:github/pr/2778
MagicBeanDev:github/pr/2888
MagicBeanDev:github/pr/2866
MagicBeanDev:github/pr/2877
MagicBeanDev:github/pr/2800
MagicBeanDev:github/pr/2829
MagicBeanDev:github/pr/2850
MagicBeanDev:github/pr/2889
MagicBeanDev:github/pr/2882
MagicBeanDev:github/pr/2860
MagicBeanDev:github/pr/2849
MagicBeanDev:github/pr/2886
MagicBeanDev:github/pr/2794
MagicBeanDev:github/pr/2840
MagicBeanDev:github/pr/2830
MagicBeanDev:github/pr/2834
MagicBeanDev:github/pr/2719
MagicBeanDev:github/pr/2742
MagicBeanDev:github/pr/2741
MagicBeanDev:github/pr/2820
MagicBeanDev:github/pr/2771
MagicBeanDev:github/pr/2859
MagicBeanDev:github/pr/2858
MagicBeanDev:github/pr/2823
MagicBeanDev:github/pr/2757
MagicBeanDev:github/pr/2769
MagicBeanDev:github/pr/2844
MagicBeanDev:github/pr/2843
MagicBeanDev:github/pr/2673
MagicBeanDev:github/pr/2855
MagicBeanDev:github/pr/2739
MagicBeanDev:github/pr/2807
MagicBeanDev:github/pr/2851
MagicBeanDev:github/pr/2789
MagicBeanDev:github/pr/2814
MagicBeanDev:github/pr/2818
MagicBeanDev:github/pr/2774
MagicBeanDev:github/pr/2772
MagicBeanDev:github/pr/2750
MagicBeanDev:github/pr/2786
MagicBeanDev:github/pr/2785
MagicBeanDev:github/pr/2782
MagicBeanDev:github/pr/2779
MagicBeanDev:github/pr/2775
MagicBeanDev:github/pr/2706
MagicBeanDev:github/pr/2766
MagicBeanDev:github/pr/2747
MagicBeanDev:github/pr/2759
MagicBeanDev:github/pr/2745
MagicBeanDev:github/pr/2740
MagicBeanDev:github/pr/2733
MagicBeanDev:github/pr/2725
MagicBeanDev:github/pr/2727
MagicBeanDev:github/pr/2728
MagicBeanDev:github/pr/2729
MagicBeanDev:github/pr/2721
MagicBeanDev:github/pr/2722
MagicBeanDev:github/pr/2715
MagicBeanDev:github/pr/2714
MagicBeanDev:github/pr/2707
MagicBeanDev:github/pr/2703
MagicBeanDev:github/pr/2705
MagicBeanDev:github/pr/2697
MagicBeanDev:github/pr/2679
MagicBeanDev:github/pr/2676
MagicBeanDev:github/pr/2669
MagicBeanDev:docs/what-hookshot-connects-to
MagicBeanDev:fix/hdr-encode-test
MagicBeanDev:fix/main-tests
MagicBeanDev:fix/play-cache-files
MagicBeanDev:perf/game-barrier-order
MagicBeanDev:feat/heap-lazy
MagicBeanDev:feat/texture-detail
MagicBeanDev:perf/astc-opaque-bc1
MagicBeanDev:fix/fs-dir-lock
MagicBeanDev:fix/framegen-native-kept
MagicBeanDev:fix/update-no-downgrade
MagicBeanDev:port/k10-gcn-f16-mirrors
MagicBeanDev:fix/framegen-mult-cap
MagicBeanDev:chore/release-as-2.1.1
MagicBeanDev:perf/pcache-load-switch
MagicBeanDev:fix/prepare-progress-log
MagicBeanDev:fix/update-closes-stale-game
MagicBeanDev:fix/hdr-scaled-sampled
MagicBeanDev:perf/first-start-preset
MagicBeanDev:perf/zero-upload
MagicBeanDev:fix/vcore-escape-2s
MagicBeanDev:test/fake-gh-atomic
MagicBeanDev:perf/batch-idle-flush
MagicBeanDev:test/finish-stub-a
MagicBeanDev:chore/record-2.1.0
MagicBeanDev:fix/main-red-tests
MagicBeanDev:fix/test-display-startup-driver-cache
MagicBeanDev:feat/mesh-shader-mode
MagicBeanDev:fix/menu-probes-at-startup
MagicBeanDev:fix/fps-counter-classic
MagicBeanDev:fix/test-log-batch-flake
MagicBeanDev:fix/narrow-screen-hud
MagicBeanDev:ci/prereleases
MagicBeanDev:release/v2.0.15
MagicBeanDev:hotfix/v2.0.15
MagicBeanDev:fix/present-ahead-replay
MagicBeanDev:release/v2.0.13
MagicBeanDev:fix/bracket-paths-2013
MagicBeanDev:fix/hdr-overlays-2013
MagicBeanDev:fix/fps-counter-scale-2013
MagicBeanDev:fix/stick-seen-at-rest
MagicBeanDev:hotfix/menu-fits-screen
MagicBeanDev:fix/f1-always-opens-menu
MagicBeanDev:fix/ini-keep-lines
MagicBeanDev:claude/cranky-pike-7cf247
MagicBeanDev:perf/texture-answer-flat
MagicBeanDev:fix/stamp-test-modules
MagicBeanDev:fix/appimage-fonts
MagicBeanDev:fix/display-awake
MagicBeanDev:release/v2.0.12
MagicBeanDev:fix/discord-windows
MagicBeanDev:rc/v2.0.12-tests
MagicBeanDev:fix/dlss-keep-feature
MagicBeanDev:rc/v2.0.12
MagicBeanDev:button-icons
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
autorelease: pending
autorelease: tagged
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
github_actions
Pull requests that update GitHub Actions code
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
question
Further information is requested
testing wanted
wontfix
This will not be worked on
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!1941
Loading…
Reference in a new issue
No description provided.
Delete branch "j64esatxzdrhfg/feat/hdr-contrast"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Players asked for a contrast control for HDR, as the RenoDX HDR mods have. The Expanded picture is otherwise fixed at the game's SDR contrast.
What changed
shaders/hdr_encode.comp: after the SDR expansion (mode 0, Expanded, unchanged) or the game's own PQ picture decoded (mode 1, Native), the light is graded as RenoDX's Contrast does it: on luminance relative to the paper white,pow(Y * exposure / 0.18, contrast) * 0.18, hue kept. Exposure is pushed as 1 for now. Push constants grow to 48 bytes.row_showntakes it in the paper white / peak clause): 50–200% in steps of 5, default 100%, saved ashdr_contrast. Its help says the highlights ease into the peak brightness, and that Native is graded under the peak brightness the game is told.shaders/hdr_encode_comp_spv.h: glslang 16.6.0, with the source hash line as before.test_hdr_encode.pyruns the shader's owngrade()/shoulder()in Python, and also checks the push constants and the row.test_upscaler_rows.pychecks the row's visibility.Testing: RTX 5080, 3840x2160 HDR10, 800 nits peak, 300 nits paper white, Expanded at 100% and 150% in a build of main (
8c92fe3) with this series (screenshots, tone-mapped to SDR for this page). Before the shoulder, 150% clipped the highlights; that was found and fixed in game on the v2.0.13 build. Rebased directly on maind7a7306: it compiles with the build's clang.tests/run_all.py hdr_encode upscaler_rows present_aspect present_geometry present_source_crop upscale_independent menupass (19), exceptpresent_aspect_vulkan. That one fails to compile the same way on main (its stubs predate the HDR pass), and #1942 fixes them.In game after the review changes (a build of main
d7a7306with this series, Native, 800 nits peak row, 330 nits paper white): at 100% the game's own picture topped out at about 700 nits; at 150% the graded picture's brightest light was 784 nits, under the peak row, with the light shaft still graded rather than cut flat (screenshots). Expanded's math is unchanged.Not tested: AMD/Intel, Linux, displays other than 800 nits.
Screenshots (Expanded, 800 nits peak, 300 nits paper white)
Native (800 nits peak, 330 nits paper white)
HDR10 captures, tone-mapped to SDR for this page (paper white to white, highlights rolled off up to 800 nits).
🤖 Generated with Claude Code
Thanks, the Expanded side of this looks right to me. I went through the shoulder: it meets the graded curve at the knee with slope 1, it rises for s above and below 1 (b(1+b) > 0 in both cases), and it lands exactly on the peak at grade(top). At 100% the
contrast != 1.0gate is exact, since100 / 100.0fis exactly 1. Running the shader's owngrade()/shoulder()in Python is a nice way to test this. The push constants (48 bytes, same order on both sides), thehdr_contrastini key (clamped on load), the row's visibility and the stubbed fixtures all match, and the header's hash line matches the shader at this head.The Native half is where I have questions:
present_native_pqstays false), so on its own this PR can't grade the game's HDR, despite the title and the row's help text. Also, with Sharpness, the scaling filter or ultrawide's sides on,framegen_scalestill writes the game's PQ codes into an RGBA8scale.scaled, so the grade works on 8-bit PQ. Contrast above 100% will make that banding worse. #1942 fixes both. I'd land #1941 and #1942 together (or fold the Native part into #1942), and say so in the description.Nits:
row_showncould foldhdr_contrastinto the existing paper white / peak clause instead of adding a second one (the test string would follow). Exposure is pushed as a constant 1, which is fine, but it's dead weight until a row uses it.CI hasn't run on this branch yet (no checks reported). It's 63 commits behind main but GitHub reports it mergeable. No other discussion on the PR so far. The Expanded path looks ready to me.
For Native,
topis the HDR peak row, but the game's own picture isn't bounded by it. If the game puts light abovepc.peak / pc.white,shoulder()takes thet >= 1branch and the luminance limit below then clips it at the peak. With the row at 1000 nits and the game's highlights reaching 1500, everything from about 1000 to 1500 ends up flat at the peak as soon as contrast moves off 100%. At 100% the pass is skipped and those highlights show. That's the flat-cut highlights the shoulder was added to avoid, just on the Native side. Could Native use a top that covers what the game can output (the PQ ceiling, or the game's own peak setting if you can read it), or should the row's text at least say the peak row has to match the game's?nit:
(v != &opts.hdr_white && v != &opts.hdr_peak && v != &opts.hdr_contrast) || opts.hdr != 0reads as one rule (update the string intest_upscaler_rows.pywith it).Thanks. This is now rebased directly onto main
d7a7306; #1940's commit is gone, since its fix landed with #2038.row_shown: folded into the existing clause (inline).0a28ff2gives RGB10A2 its own cache class, Native is taken on main. But with Sharpness, the scaling filter or the sides on, Native still reaches the pass through RGBA8 until #1942 scales it in 10 bits.Changed. Native's grade is now fitted under the peak the game is told: the HDR peak row, which Hookshot passes to the game as its display's peak, and which the game's own light stays under (about 700 nits at most with an 800-nit row, in game).
pc.peak / pc.white, the same as Expanded.test_hdr_encode.pyruns the shader'sgrade()/shoulder()over every PQ code:Done:
(v != &opts.hdr_white && v != &opts.hdr_peak && v != &opts.hdr_contrast) || opts.hdr != 0. The string intest_upscaler_rows.pyfollows.Thanks, fitting Native under the peak row and dropping the peak limit for it answers this; nothing gets cut flat by the pass any more.
One small thing left on the "as at 100%" part: past the top the shoulder continues with slope 1 in graded light, and in the game's light that's a slope of about
contrast * grade(top) / top. At 800 nits peak and 330 paper white I get, for game light of 790 / 800 / 810 / 900 / 1000 nits: 798 / 800 / 855 / 1367 / 1967 at 150%, and 749 / 800 / 801 / 813 / 826 at 50%. So above the row the game's light is stretched about 5x at 150% (the display will clip it) and squashed at 50%, with a kink right at the peak. Since you saw the game stay well under the row, that's a nit, not a blocker. Continuing in ungraded light instead (top + (y - top)in the game's light oncey > top) would make it really "as at 100%" there. This code is on main now (via #2342), so it would be a follow-up.Re-review at
35f8125. Both of my earlier points are resolved:row_shownis folded into the existing clause (fixed). Exposure is kept as the constant 1 (answered, fine by me).I checked the rest again. The shader hash in the header matches the shader at this head. Push constants are 48 bytes on both sides. Expanded at 100% is unchanged: the gate skips the grade, and the new luminance limit can't fire there because the expansion already tops out at the peak. With HDR off nothing here runs, so SDR output is unchanged. No new option id (the row is saved under its
hdr_contrastini key), so nothing collides with main's or the open PRs' ids. Native at 100% still skips the pass inpresent_image.However, this PR's whole change is already on main. #2342 was squash-merged today as
a0dfd28, and it carried the whole stack (#1941, #1942, #2243). Every line this PR adds is on main, apart from the ones #1942/#2243 later changed. That's also why GitHub shows every file conflicting. So there's nothing left to merge here, and I think this PR (and probably #1942 and #2243 too, once you've checked) can be closed as landed via #2342. I'd have approved it otherwise. CI only ran the title check (passed).I think this can be closed: it reached main inside #2342 (
a0dfd28, "FSR 4 for the game's native HDR"), which was stacked on #1941, #1942 and #2243 and squash-merged. I checked file by file against origin/main:HDR contrastrow is at vk_menu.cpp:781, andhdr_contrastis inrow_shown.The conflicts GitHub shows are that history and nothing else: there's nothing left here to merge. Thanks for the work, it shipped.
Closing as landed: this reached main inside #2342's squash merge (
a0dfd28), which was stacked on #1941, #1942 and #2243. Thanks @Joey-Magnus for checking it file by file, and @hckrman101 for the reviews. The last nit (Native light above the peak row continuing in ungraded light,top + (y - top)) I'll send as its own small follow-up.