Repository navigation
Conversation
When J is at the limit (exactly 100.0 at 100 nits, which passes the J > limit_J_max
guard), solve_J_intersect can return J_intersect a float step above limit_J_max. The
upper-hull base J_max - J_intersect_source in find_gamut_boundary_intersection is then
slightly negative, powf returns NaN, and the gamut_boundary_M <= 0 guard does not catch
it. Through the studio config the range clamp turns the NaN into 0, so some very bright
pixels render black.
Clamp the base at 0 on the CPU and in the generated shader text. The boundary M is then
0 and the existing guard returns {J, 0, h}, as the J > limit_J_max branch does.
Tests: forward and inverse gamut compression for J at the limit and the float steps
below it over all hues, and an output-transform input that reached the limit.
Signed-off-by: Kazuaki Matsumura <ezulfilm@gmail.com>
|
|
|
Hi, thank you for OpenColorIO. I hit this while comparing ACES 2.0 renders: a few very bright pixels came out black while their neighbours were white. What I checked:
If you'd prefer a different fix, I'm happy to change it: clamping the result of This is separate from #2132 (the divide by zero in |
doug-walker
left a comment
There was a problem hiding this comment.
@EzulDev , thanks for the fix!
The fix itself looks good. Thanks for adding the thorough unit tests, although I think those need a bit more work, please see below.
| 100.0f, 10.0f, 46.0f, 1.0f, | ||
| }; | ||
| const size_t num_limit_samples = input_32f.size() / 4; | ||
|
|
There was a problem hiding this comment.
This seems excessive, it's processing 46k values. When the test fails it spams the shell with almost 4k lines of error messages. Please reduce this to a much smaller number of test points. And please just print a failure message for the group, rather than for each point.
There was a problem hiding this comment.
I've reduced it to 8 hues at J = limit_J_max, forward and inverse, with one failure message per direction.
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
When I comment out your fix, this test does not fail for me. I ran it on a Mac with an m5 arm chip. What hardware did it fail for you on?
There was a problem hiding this comment.
It failed on x86-64 (AMD Ryzen 7 5800H, Linux, GCC 13.3). On ARM, clang fuses the multiply-adds in solve_J_intersect, so for that input the J intersection lands exactly at 100 instead of a float step above it, and no NaN occurs: https://godbolt.org/z/PeT8K9zPz. I’ve removed that test. The remaining test uses hues that give NaN without the fix both with and without FMA.
|
@KevinJW, please take a look, when you get a chance, thanks! And tagging @scottdyer for visibility, in case the CTL needs a similar fix. |
Use 8 hues and one failure message per direction. Drop the output transform test: it depends on FMA. Signed-off-by: Kazuaki Matsumura <ezulfilm@gmail.com>
doug-walker
left a comment
There was a problem hiding this comment.
Thanks @EzulDev , those changes look great.
On my Mac, with your fix commented out, all eight of your test points fail in both forward and inverse directions, as desired.
With the fix, the CPU and GPU tests pass.
You may ignore the failing CI jobs, those are unrelated to your PR.
Once we have a second approval, we will merge this for OCIO 2.6.1.
Scott Dyer has now thankfully created a similar PR on the upstream ACES repo:
aces-aswf/aces-core#167
The ACES 2.0 gamut compression returns NaN for some very bright colours.
Example:
Through the built-in studio config, the range clamp after the output transform turns the NaN into 0, so these pixels render black among white neighbours. For example, ACEScct
[1.02502234, 0.90455188, 0.68137096]gives (0, 0, 0) on "sRGB - Display" / "ACES 2.0 - SDR 100 nits (Rec.709)".In this code, J is the lightness in the JMh space the transform works in, and its upper limit
limit_J_maxis exactly 100.0 at 100 nits. A colour with J = 100 passes theJ > limit_J_maxearly-out.solve_J_intersectthen returnsJ_intersect_sourcea float step above the limit (100.0000076), because J = limit_J_max is an exact root of its quadratic. Infind_gamut_boundary_intersection,J_max - J_intersect_sourceis slightly negative,powfof it is NaN, and thegamut_boundary_M <= 0.fguard does not catch the NaN.Fix: clamp that value at 0, on the CPU and in the generated shader text. The boundary M is then 0, and the existing guard returns
{J, 0, h}, the same as for J above the limit (white).Tests:
aces_gamut_comp_20_limit_J: forward and inverse, J at the limit and the 3 float steps below it, all hues in 0.5° steps, 4 values of M; all outputs finite.aces_output_transform_20_limit_J: an AP0 input that reached the limit inside the output transform now gives display white instead of NaN.