Skip to content

Commit 4a119df

Browse files
remiadoug-walker
andauthored
Fix OpenGL ES type issues in ACES2 FixedFunction Ops (#2281)
* Fix OpenGL ES type issues in ACES2 FixedFunction Ops Signed-off-by: Rémi Achard <remiachard@gmail.com> * Update src/OpenColorIO/ops/fixedfunction/FixedFunctionOpGPU.cpp Co-authored-by: Doug Walker <doug.walker@autodesk.com> Signed-off-by: Rémi Achard <remiachard@gmail.com> * Add 2D texture path tests for ACES2 cusp and reach table sampling Signed-off-by: Rémi Achard <remiachard@gmail.com> --------- Signed-off-by: Rémi Achard <remiachard@gmail.com> Co-authored-by: Doug Walker <doug.walker@autodesk.com>
1 parent 9abd326 commit 4a119df

2 files changed

Lines changed: 78 additions & 10 deletions

File tree

src/OpenColorIO/ops/fixedfunction/FixedFunctionOpGPU.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -563,18 +563,18 @@ std::string _Add_Reach_table(
563563
ss.indent();
564564

565565
ss.newLine() << ss.floatDecl("i_base") << " = floor(h);";
566-
ss.newLine() << ss.floatDecl("i_lo") << " = i_base + " << table.base_index << ";";
567-
ss.newLine() << ss.floatDecl("i_hi") << " = i_lo + 1;";
566+
ss.newLine() << ss.floatDecl("i_lo") << " = i_base + " << ss.floatKeyword() << "(" << table.base_index << ");";
567+
ss.newLine() << ss.floatDecl("i_hi") << " = i_lo + 1.0;";
568568

569569
if (dimensions == GpuShaderDesc::TEXTURE_1D)
570570
{
571-
ss.newLine() << ss.floatDecl("lo") << " = " << ss.sampleTex1D(name, "(i_lo + 0.5) / " + std::to_string(table.total_size)) << ".r;";
572-
ss.newLine() << ss.floatDecl("hi") << " = " << ss.sampleTex1D(name, "(i_hi + 0.5) / " + std::to_string(table.total_size)) << ".r;";
571+
ss.newLine() << ss.floatDecl("lo") << " = " << ss.sampleTex1D(name, "(i_lo + 0.5) / " + ss.floatKeyword() + " (" + std::to_string(table.total_size) + ")") << ".r;";
572+
ss.newLine() << ss.floatDecl("hi") << " = " << ss.sampleTex1D(name, "(i_hi + 0.5) / " + ss.floatKeyword() + " (" + std::to_string(table.total_size) + ")") << ".r;";
573573
}
574574
else
575575
{
576-
ss.newLine() << ss.floatDecl("lo") << " = " << ss.sampleTex2D(name, ss.float2Const("(i_lo + 0.5) / " + std::to_string(table.total_size), "0.0")) << ".r;";
577-
ss.newLine() << ss.floatDecl("hi") << " = " << ss.sampleTex2D(name, ss.float2Const("(i_hi + 0.5) / " + std::to_string(table.total_size), "0.5")) << ".r;";
576+
ss.newLine() << ss.floatDecl("lo") << " = " << ss.sampleTex2D(name, ss.float2Const("(i_lo + 0.5) / " + ss.floatKeyword() + " (" + std::to_string(table.total_size) + ")", "0.0")) << ".r;";
577+
ss.newLine() << ss.floatDecl("hi") << " = " << ss.sampleTex2D(name, ss.float2Const("(i_hi + 0.5) / " + ss.floatKeyword() + " (" + std::to_string(table.total_size) + ")", "0.5")) << ".r;";
578578
}
579579

580580
ss.newLine() << ss.floatDecl("t") << " = h - i_base;"; // Hardcoded single degree spacing
@@ -901,13 +901,13 @@ std::string _Add_Cusp_table(
901901

902902
if (dimensions == GpuShaderDesc::TEXTURE_1D)
903903
{
904-
ss.newLine() << ss.float3Decl("lo") << " = " << ss.sampleTex1D(name, std::string("(i_hi - 1 + 0.5) / ") + std::to_string(g.gamut_cusp_table.total_size)) << ".rgb;";
905-
ss.newLine() << ss.float3Decl("hi") << " = " << ss.sampleTex1D(name, std::string("(i_hi + 0.5) / ") + std::to_string(g.gamut_cusp_table.total_size)) << ".rgb;";
904+
ss.newLine() << ss.float3Decl("lo") << " = " << ss.sampleTex1D(name, std::string("(" + ss.floatKeyword() + "(i_hi) - 1.0 + 0.5) / ") + ss.floatKeyword() + "(" + std::to_string(g.gamut_cusp_table.total_size) + ")") << ".rgb;";
905+
ss.newLine() << ss.float3Decl("hi") << " = " << ss.sampleTex1D(name, std::string("(" + ss.floatKeyword() + "(i_hi) + 0.5) / ") + ss.floatKeyword() + "(" + std::to_string(g.gamut_cusp_table.total_size) + ")") << ".rgb;";
906906
}
907907
else
908908
{
909-
ss.newLine() << ss.float3Decl("lo") << " = " << ss.sampleTex2D(name, ss.float2Const(std::string("(i_hi - 1 + 0.5) / ") + std::to_string(g.gamut_cusp_table.total_size), "0.5")) << ".rgb;";
910-
ss.newLine() << ss.float3Decl("hi") << " = " << ss.sampleTex2D(name, ss.float2Const(std::string("(i_hi + 0.5) / ") + std::to_string(g.gamut_cusp_table.total_size), "0.5")) << ".rgb;";
909+
ss.newLine() << ss.float3Decl("lo") << " = " << ss.sampleTex2D(name, ss.float2Const(std::string("(" + ss.floatKeyword() + "(i_hi) - 1.0 + 0.5) / ") + ss.floatKeyword() + "(" + std::to_string(g.gamut_cusp_table.total_size) + ")", "0.5")) << ".rgb;";
910+
ss.newLine() << ss.float3Decl("hi") << " = " << ss.sampleTex2D(name, ss.float2Const(std::string("(" + ss.floatKeyword() + "(i_hi) + 0.5) / ") + ss.floatKeyword() + "(" + std::to_string(g.gamut_cusp_table.total_size) + ")", "0.5")) << ".rgb;";
911911
}
912912

913913
ss.newLine() << ss.floatDecl("t") << " = (h - " << hues_array_name << "[i_hi - 1]) / "

tests/gpu/FixedFunctionOp_test.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,74 @@ OCIO_ADD_GPU_TEST(FixedFunction, style_aces2_gamut_compress_inv)
11071107
test.setErrorThreshold(4e-4f);
11081108
}
11091109

1110+
OCIO_ADD_GPU_TEST(FixedFunction, style_aces2_gamut_compress_no1dlut)
1111+
{
1112+
// Test the 2D TEXTURE path used for Reach and Cusp table sampling
1113+
// OpenGL tests would otherwise not use it and prefer 1D TEXTURE
1114+
1115+
const double data[9] = {
1116+
// Peak luminance
1117+
1000.f,
1118+
// P3D65 gamut
1119+
0.680, 0.320, 0.265, 0.690, 0.150, 0.060, 0.3127, 0.3290
1120+
};
1121+
OCIO::FixedFunctionTransformRcPtr func =
1122+
OCIO::FixedFunctionTransform::Create(OCIO::FIXED_FUNCTION_ACES_GAMUT_COMPRESS_20, &data[0], 9);
1123+
func->setDirection(OCIO::TRANSFORM_DIR_INVERSE);
1124+
1125+
test.setProcessor(func);
1126+
1127+
OCIOGPUTest::CustomValues values;
1128+
values.m_inputValues =
1129+
{
1130+
// ACEScg primaries and secondaries scaled by 4
1131+
110.702453613f, 211.251770020f, 25.025110245f, 1.0f,
1132+
168.016815186f, 129.796249390f, 106.183448792f, 1.0f,
1133+
140.814849854f, 193.459213257f, 147.056488037f, 1.0f,
1134+
156.429519653f, 110.938514709f, 192.204727173f, 1.0f,
1135+
80.456542969f, 98.490524292f, 268.442108154f, 1.0f,
1136+
135.172195435f, 175.559280396f, 341.715240479f, 1.0f,
1137+
// OCIO test values
1138+
18.187314987f, 33.819175720f, 4.173158169f, 0.5f,
1139+
80.413116455f, 21.309329987f, 332.159759521f, 1.0f,
1140+
83.447891235f, 37.852291107f, 182.925750732f, 0.0f,
1141+
// ColorChecker24 (SMPTE 2065-1 2021)
1142+
27.411964417f, 13.382769585f, 38.146659851f, 1.0f,
1143+
59.987670898f, 14.391894341f, 39.841842651f, 1.0f,
1144+
43.298923492f, 12.199877739f, 249.107116699f, 1.0f,
1145+
31.489658356f, 14.075142860f, 128.878036499f, 1.0f,
1146+
50.749198914f, 12.731814384f, 285.658966064f, 1.0f,
1147+
64.728637695f, 18.593795776f, 179.324264526f, 1.0f,
1148+
53.399448395f, 37.394428253f, 50.924011230f, 1.0f,
1149+
34.719596863f, 21.616765976f, 271.008331299f, 1.0f,
1150+
43.910713196f, 36.788166046f, 13.975610733f, 1.0f,
1151+
23.196525574f, 15.118354797f, 317.544281006f, 1.0f,
1152+
63.348674774f, 33.283493042f, 119.145133972f, 1.0f,
1153+
64.908889771f, 35.371044159f, 70.842193604f, 1.0f,
1154+
24.876911163f, 23.143159866f, 273.228973389f, 1.0f,
1155+
44.203376770f, 28.918329239f, 144.154159546f, 1.0f,
1156+
32.824356079f, 43.447875977f, 17.892261505f, 1.0f,
1157+
75.830871582f, 39.872474670f, 90.752044678f, 1.0f,
1158+
45.823116302f, 34.652069092f, 348.832092285f, 1.0f,
1159+
43.597240448f, 23.079078674f, 218.454376221f, 1.0f,
1160+
96.212783813f, 0.322624743f, 108.271926880f, 1.0f,
1161+
78.222122192f, 0.094044082f, 33.296318054f, 1.0f,
1162+
60.364795685f, 0.031291425f, 291.004058838f, 1.0f,
1163+
43.659111023f, 0.038717352f, 297.386047363f, 1.0f,
1164+
26.623359680f, 0.269155562f, 234.276382446f, 1.0f,
1165+
12.961384773f, 0.366550505f, 255.025634766f, 1.0f,
1166+
// Spectrally non-selective 18 % reflecting diffuser
1167+
40.609165192f, 0.000000000f, 299.357757568f, 1.0f,
1168+
// Perfect reflecting diffuser
1169+
101.899215698f, 0.000068110f, 5.640549183f, 1.0f,
1170+
};
1171+
test.setCustomValues(values);
1172+
1173+
test.setErrorThreshold(1e-4f);
1174+
1175+
test.getShaderDesc()->setAllowTexture1D(false);
1176+
}
1177+
11101178
// The next four tests run into a problem on some graphics cards where 0.0 * Inf = 0.0,
11111179
// rather than the correct value of NaN. Therefore turning off TestInfinity for these tests.
11121180

0 commit comments

Comments
 (0)