diff options
| author | Yong He <yonghe@outlook.com> | 2024-02-28 23:26:51 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-28 23:26:51 -0800 |
| commit | c6756d76fd70424f5b3bd1d910a5afc46dc7c83e (patch) | |
| tree | 444f16cdfe6a872ce658824052665bd78a59218d | |
| parent | 73a61edda8893901acad05bb4e7d3110db5041a8 (diff) | |
Allow non-static const to be considered compile-time constant. (#3645)
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 6 | ||||
| -rw-r--r-- | tests/bugs/gh-3643.slang | 14 |
2 files changed, 16 insertions, 4 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 811e4b395..55ff90759 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -1654,12 +1654,10 @@ namespace Slang if(_checkForCircularityInConstantFolding(decl, circularityInfo)) return nullptr; - // In HLSL, `static const` is used to mark compile-time constant expressions - if(!decl->hasModifier<HLSLStaticModifier>()) - return nullptr; + // In HLSL, `const` is used to mark compile-time constant expressions. if(!decl->hasModifier<ConstModifier>()) return nullptr; - // Extern static const is not considered compile-time constant by the front-end. + // Extern const is not considered compile-time constant by the front-end. if (decl->hasModifier<ExternModifier>()) return nullptr; diff --git a/tests/bugs/gh-3643.slang b/tests/bugs/gh-3643.slang new file mode 100644 index 000000000..5d8d8191c --- /dev/null +++ b/tests/bugs/gh-3643.slang @@ -0,0 +1,14 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -entry PSMain -stage fragment +struct PSInput +{ + float4 color : COLOR; +}; + +// CHECK: OpEntryPoint + +float4 PSMain(PSInput input) : SV_TARGET +{ + const int nTaps = 2; + const float flOffsets[ nTaps ] = { 0.0, 0.1 }; + return input.color.rgba + flOffsets[0].xxxx; +}
\ No newline at end of file |
