Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 49 additions & 42 deletions src/OpenColorIO/GpuShaderUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,18 @@ void GpuShaderText::declareFloatArrayConst(const std::string & name, int size, c
}

auto nl = newLine();

auto emitArrayValues = [&]()
{
for (int i = 0; i < size; ++i)
{
nl << getFloatString(v[i], m_lang);
if (i + 1 != size)
{
nl << ", ";
}
}
};

switch (m_lang)
{
Expand All @@ -524,34 +536,30 @@ void GpuShaderText::declareFloatArrayConst(const std::string & name, int size, c
{
nl << floatKeywordConst() << " " << name << "[" << size << "] = ";
nl << floatKeyword() << "[" << size << "](";
for (int i = 0; i < size; ++i)
{
nl << getFloatString(v[i], m_lang);
if (i + 1 != size)
{
nl << ", ";
}
}
emitArrayValues();
nl << ");";
break;
}
case LANGUAGE_OSL_1:
case GPU_LANGUAGE_CG:
case GPU_LANGUAGE_HLSL_SM_5_0:
{
nl << floatKeywordConst();
nl << " " << name << "[" << size << "] = {";
emitArrayValues();
nl << "};";
break;
}

case GPU_LANGUAGE_MSL_2_0:
{
nl << floatKeywordConst() << " " << name << "[" << size << "] = {";
for (int i = 0; i < size; ++i)
{
nl << getFloatString(v[i], m_lang);
if (i + 1 != size)
{
nl << ", ";
}
}
nl << "constant constexpr static float";
nl << " " << name << "[" << size << "] = {";
emitArrayValues();
nl << "};";
break;
}

}
}

Expand All @@ -567,6 +575,18 @@ void GpuShaderText::declareIntArrayConst(const std::string & name, int size, con
}

auto nl = newLine();

auto emitArrayValues = [&]()
{
for (int i = 0; i < size; ++i)
{
nl << v[i];
if (i + 1 != size)
{
nl << ", ";
}
}
};

switch (m_lang)
{
Expand All @@ -578,44 +598,31 @@ void GpuShaderText::declareIntArrayConst(const std::string & name, int size, con
{
nl << intKeywordConst() << " " << name << "[" << size << "] = "
<< intKeyword() << "[" << size << "](";
for (int i = 0; i < size; ++i)
{
nl << v[i];
if (i + 1 != size)
{
nl << ", ";
}
}
emitArrayValues();
nl << ");";
break;
}
case GPU_LANGUAGE_HLSL_SM_5_0:
{
nl << intKeywordConst();
nl << " " << name << "[" << size << "] = {";
emitArrayValues();
nl << "};";
break;
}
case GPU_LANGUAGE_MSL_2_0:
{
nl << intKeywordConst() << " " << name << "[" << size << "] = {";
for (int i = 0; i < size; ++i)
{
nl << v[i];
if (i + 1 != size)
{
nl << ", ";
}
}
nl << "constant constexpr static int";
nl << " " << name << "[" << size << "] = {";
emitArrayValues();
nl << "};";
break;
}
case LANGUAGE_OSL_1:
case GPU_LANGUAGE_CG:
{
nl << intKeyword() << " " << name << "[" << size << "] = {";
for (int i = 0; i < size; ++i)
{
nl << v[i];
if (i + 1 != size)
{
nl << ", ";
}
}
emitArrayValues();
nl << "};";
break;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/cpu/GpuShader_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,10 +1032,10 @@ ocioOCIOMain(
// Declaration of all helper methods


const int ocio_grading_rgbcurve_knotsOffsets_0[8] = {0, 5, -1, 0, -1, 0, -1, 0};
const float ocio_grading_rgbcurve_knots_0[5] = {0., 0.333333343, 0.5, 0.666666508, 1.};
const int ocio_grading_rgbcurve_coefsOffsets_0[8] = {0, 12, -1, 0, -1, 0, -1, 0};
const float ocio_grading_rgbcurve_coefs_0[12] = {0.0982520878, 0.393008381, 0.347727984, 0.08693178, 0.934498608, 1., 1.13100278, 1.246912, 0., 0.322416425, 0.5, 0.698159397};
constant constexpr static int ocio_grading_rgbcurve_knotsOffsets_0[8] = {0, 5, -1, 0, -1, 0, -1, 0};
constant constexpr static float ocio_grading_rgbcurve_knots_0[5] = {0., 0.333333343, 0.5, 0.666666508, 1.};
constant constexpr static int ocio_grading_rgbcurve_coefsOffsets_0[8] = {0, 12, -1, 0, -1, 0, -1, 0};
constant constexpr static float ocio_grading_rgbcurve_coefs_0[12] = {0.0982520878, 0.393008381, 0.347727984, 0.08693178, 0.934498608, 1., 1.13100278, 1.246912, 0., 0.322416425, 0.5, 0.698159397};

float ocio_grading_rgbcurve_evalBSplineCurve_0(int curveIdx, float x)
{
Expand Down