Skip to content

Commit 281d39f

Browse files
num3ricremia
andauthored
Fix for static const literals in HLSL. (#1684)
Signed-off-by: Eric Renaud-Houde <[email protected]> Signed-off-by: Eric Renaud-Houde <[email protected]> Co-authored-by: Rémi Achard <[email protected]>
1 parent 8e04da7 commit 281d39f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/OpenColorIO/GpuShaderUtils.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,18 @@ std::string GpuShaderText::constKeyword() const
335335
case GPU_LANGUAGE_GLSL_4_0:
336336
case GPU_LANGUAGE_GLSL_ES_1_0:
337337
case GPU_LANGUAGE_GLSL_ES_3_0:
338-
case GPU_LANGUAGE_HLSL_DX11:
339338
case GPU_LANGUAGE_MSL_2_0:
340339
{
341340
str += "const";
342341
str += " ";
343342
break;
344343
}
344+
case GPU_LANGUAGE_HLSL_DX11:
345+
{
346+
str += "static const";
347+
str += " ";
348+
break;
349+
}
345350
case LANGUAGE_OSL_1:
346351
case GPU_LANGUAGE_CG:
347352
break;
@@ -380,6 +385,16 @@ std::string GpuShaderText::intKeyword() const
380385
return "int";
381386
}
382387

388+
std::string GpuShaderText::intKeywordConst() const
389+
{
390+
std::string str;
391+
392+
str += constKeyword();
393+
str += intKeyword();
394+
395+
return str;
396+
}
397+
383398
std::string GpuShaderText::colorDecl(const std::string & name) const
384399
{
385400
if (name.empty())
@@ -547,7 +562,7 @@ void GpuShaderText::declareIntArrayConst(const std::string & name, int size, con
547562
case GPU_LANGUAGE_GLSL_ES_1_0:
548563
case GPU_LANGUAGE_GLSL_ES_3_0:
549564
{
550-
nl << "const " << intKeyword() << " " << name << "[" << size << "] = "
565+
nl << intKeywordConst() << " " << name << "[" << size << "] = "
551566
<< intKeyword() << "[" << size << "](";
552567
for (int i = 0; i < size; ++i)
553568
{
@@ -563,7 +578,7 @@ void GpuShaderText::declareIntArrayConst(const std::string & name, int size, con
563578
case GPU_LANGUAGE_HLSL_DX11:
564579
case GPU_LANGUAGE_MSL_2_0:
565580
{
566-
nl << "const " << intKeyword() << " " << name << "[" << size << "] = {";
581+
nl << intKeywordConst() << " " << name << "[" << size << "] = {";
567582
for (int i = 0; i < size; ++i)
568583
{
569584
nl << v[i];

src/OpenColorIO/GpuShaderUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class GpuShaderText
7474
std::string floatDecl(const std::string& name) const;
7575

7676
std::string intKeyword() const;
77+
std::string intKeywordConst() const;
7778

7879
std::string colorDecl(const std::string& name) const;
7980

0 commit comments

Comments
 (0)