summaryrefslogtreecommitdiff
path: root/tests/compute
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-03-06 20:16:20 -0500
committerTim Foley <tfoleyNV@users.noreply.github.com>2019-03-06 17:16:20 -0800
commitc850ba44164ac2bee895137abdd184beb4123090 (patch)
treef6e42ce5998038a1162e95c2a879bb7b06d0573f /tests/compute
parent87610f6def3e3dceac0082c1b60abbe2aee09014 (diff)
* Add support for enum and type lookup via :: (scope operator) (#882)
* Added test for scope operator
Diffstat (limited to 'tests/compute')
-rw-r--r--tests/compute/scope-operator.slang77
-rw-r--r--tests/compute/scope-operator.slang.expected.txt4
2 files changed, 81 insertions, 0 deletions
diff --git a/tests/compute/scope-operator.slang b/tests/compute/scope-operator.slang
new file mode 100644
index 000000000..c50d95965
--- /dev/null
+++ b/tests/compute/scope-operator.slang
@@ -0,0 +1,77 @@
+// scope.slang
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+
+// Confirm that scoping on enums and types works
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+RWStructuredBuffer<int> outputBuffer;
+
+enum Color
+{
+ Red,
+ Green = 2,
+ Blue,
+}
+
+struct Thing
+{
+ int a;
+ struct Another
+ {
+ int b;
+ }
+};
+
+int test(int val)
+{
+ Color c = Color.Red;
+
+ Thing::Another another;
+ another.b = 20;
+
+ if(val > 1)
+ {
+ c = Color.Green;
+ }
+
+ if(c == Color::Red)
+ {
+ if(val & 1)
+ {
+ c = Color::Blue;
+ }
+ }
+
+ switch(c)
+ {
+ case Color::Red:
+ val = 1;
+ break;
+
+ case Color::Green:
+ val = 2;
+ break;
+
+ case Color::Blue:
+ val = 3;
+ break;
+
+ default:
+ val = -1;
+ break;
+ }
+
+ return (val << 4) + int(c) + another.b - 20;
+}
+
+[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/scope-operator.slang.expected.txt b/tests/compute/scope-operator.slang.expected.txt
new file mode 100644
index 000000000..946476280
--- /dev/null
+++ b/tests/compute/scope-operator.slang.expected.txt
@@ -0,0 +1,4 @@
+10
+33
+22
+22