You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
invert3x3's singularity guard (1e-20) cannot fire for float32 chromaticity matrices #4194
invert3x3 in src/fl/gfx/colorimetric_response.h:68 rejects a matrix as singular when fabs(det) < 1e-20f. For the matrices it is actually given — columns of CIE XYZ built from chromaticities, so entries of order 1 — that threshold is about thirteen orders of magnitude too tight to ever fire.
Measured
Primaries with red and green identical, which is as singular as a matrix gets:
r=(0.6400,0.3300) g=(0.6400,0.3300) b=(0.1500,0.0600)
columns R=(1.939394, 1.000000, 0.090909)
G=(1.939394, 1.000000, 0.090909) <- identical
det = -1.094e-7
guard (1e-20) rejects: no
The determinant is mathematically exactly zero. It computes as -1.094e-7 because at -O3 the compiler reassociates and contracts the expression, so the cancellation is not exact — and 1e-7 is roughly where float32's cancellation floor sits for operands of order 1.
invert3x3 therefore returns true and produces an inverse scaled by 1/det ≈ -9.1e6 — entirely rounding noise.
Consequences
build_source_matrix returns true for those primaries, and so did buildSourceMatrixQ16, despite the latter's documented contract: "False if the primaries are collinear, which makes the primary matrix singular."
Other callers of invert3x3 are in the same position; I have not audited them:
Note that buildRgbSolveMatrixQ16 in device_solve.cpp.hppdoes reject collinear emitters, so the emitter side is covered by something else — this is specifically the invert3x3 path.
Worked around, not fixed
#4195 adds a geometric check to buildSourceMatrixQ16: twice the area of the primary triangle, rejected below 1e-4. That is a quantity with meaning at this scale — sRGB's is 0.224, some three and a half thousand times larger — and it makes that one function's documented contract true.
It does not fix invert3x3, which is shared. The root fix is a relative determinant test: compare |det| against the product of the column norms (or the largest term in the expansion) rather than against an absolute constant. That changes behaviour for every caller, which is why it wants a maintainer's call rather than being folded into a pipeline PR.
Activity
feat(gfx): compose the streaming pipeline core (P6, #4040)
feat(gfx): compose the streaming pipeline core (P6, #4040) (#4195)
fix(gfx): make invert3x3's singularity guard relative (#4194) (#4243)