summaryrefslogtreecommitdiff
path: root/tests/compute/generic-struct.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-12-21 19:50:22 -0500
committerGitHub <noreply@github.com>2017-12-21 19:50:22 -0500
commitfab52a1bd6aa056ba91a2697133e62a169866242 (patch)
tree239e42c6e9fd2907afe52974cccda41555bde2ba /tests/compute/generic-struct.slang
parent6f681279d99e72e717bb2b91763b80e570ae725b (diff)
parent00490154ef0762839556b5884ba9b7523b265a1c (diff)
Merge pull request #324 from tfoleyNV/generic-struct-specialization
Support generic `struct` types during IR-based emit
Diffstat (limited to 'tests/compute/generic-struct.slang')
-rw-r--r--tests/compute/generic-struct.slang37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/compute/generic-struct.slang b/tests/compute/generic-struct.slang
new file mode 100644
index 000000000..fd56ae0e9
--- /dev/null
+++ b/tests/compute/generic-struct.slang
@@ -0,0 +1,37 @@
+//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+
+// Check that user code can declare and use a generic
+// `struct` type.
+
+RWStructuredBuffer<int> outputBuffer;
+
+__generic<T>
+struct GenStruct
+{
+ T x;
+ T y;
+};
+
+__generic<T>
+T test(T val)
+{
+ GenStruct<T> gs;
+ gs.x = val;
+ gs.y = val;
+ return gs.x;
+}
+
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+
+ float outVal = 0;
+
+ outVal += test<uint>(tid);
+ outVal += test<float>(tid * 16.0f);
+
+ outputBuffer[tid] = int(outVal);
+} \ No newline at end of file