summaryrefslogtreecommitdiffstats
path: root/tests/experiments/generic/type-to-value-5.slang
diff options
context:
space:
mode:
Diffstat (limited to 'tests/experiments/generic/type-to-value-5.slang')
-rw-r--r--tests/experiments/generic/type-to-value-5.slang56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/experiments/generic/type-to-value-5.slang b/tests/experiments/generic/type-to-value-5.slang
new file mode 100644
index 000000000..ce3271d47
--- /dev/null
+++ b/tests/experiments/generic/type-to-value-5.slang
@@ -0,0 +1,56 @@
+//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
+
+/* Test here is to try and associate a value with a type
+
+Here we try to associate by having a value defined on the type, and then set the type
+on the associated type.
+
+Doesn't work because ...
+
+.slang(29): error 30027: 'Type' is not a member of '.This'.
+ return e::Type::kE;
+
+*/
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+enum class Enum
+{
+ A, B
+};
+
+interface IHasType
+{
+ associatedtype Type;
+};
+
+// This is a little perverse, because I'm defining as an associated type that is
+// the same as itself
+struct A : IHasType
+{
+ typedef A Type;
+ static const Enum kE = Enum::A;
+};
+
+struct B : IHasType
+{
+ typedef B Type;
+ static const Enum kE = Enum::B;
+};
+
+Enum getType(IHasType e)
+{
+ return e::Type::kE;
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int index = dispatchThreadID.x;
+
+ B b;
+ let e = getType(b);
+
+ outputBuffer[dispatchThreadID.x] = int(e);
+} \ No newline at end of file