summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/emit.cpp10
-rw-r--r--tests/compute/enum-tag-conversion.slang31
-rw-r--r--tests/compute/enum-tag-conversion.slang.expected.txt4
3 files changed, 45 insertions, 0 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index 84585f248..f17b13762 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -2393,6 +2393,7 @@ struct EmitVisitor
case kIROp_GlobalConstant:
case kIROp_GlobalParam:
case kIROp_Param:
+ case kIROp_Func:
return false;
// Always fold these in, because they are trivial
@@ -2513,6 +2514,15 @@ struct EmitVisitor
}
}
+ // If the instruction is at global scope, then it might represent
+ // a constant (e.g., the value of an enum case).
+ //
+ if(as<IRModuleInst>(inst->getParent()))
+ {
+ if(!inst->mightHaveSideEffects())
+ return true;
+ }
+
// Having dealt with all of the cases where we *must* fold things
// above, we can now deal with the more general cases where we
// *should not* fold things.
diff --git a/tests/compute/enum-tag-conversion.slang b/tests/compute/enum-tag-conversion.slang
new file mode 100644
index 000000000..66b4923e5
--- /dev/null
+++ b/tests/compute/enum-tag-conversion.slang
@@ -0,0 +1,31 @@
+// enum-tag-conversion.slang
+
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+
+// Confirm that a value of `enum` type can have an initializer
+// that includes basic operations like type conversion.
+
+enum RoseColors
+{
+ Red = 16u,
+}
+
+int test(int val)
+{
+ return val + RoseColors.Red;
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+
+ int val = int(tid);
+ val = test(val);
+
+ outputBuffer[tid] = val;
+} \ No newline at end of file
diff --git a/tests/compute/enum-tag-conversion.slang.expected.txt b/tests/compute/enum-tag-conversion.slang.expected.txt
new file mode 100644
index 000000000..a0d427709
--- /dev/null
+++ b/tests/compute/enum-tag-conversion.slang.expected.txt
@@ -0,0 +1,4 @@
+10
+11
+12
+13