summaryrefslogtreecommitdiffstats
path: root/tests/compute/dynamic-dispatch-16.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-08-25 10:27:22 -0700
committerGitHub <noreply@github.com>2021-08-25 10:27:22 -0700
commit33f7e1599cbecb32c23787b37b2bf3b34bdd5c84 (patch)
tree1fcdadfa1d03a21668606439402e80e6a754162c /tests/compute/dynamic-dispatch-16.slang
parent3b0b920608928f8cb39dc9116043d5a8644149c3 (diff)
Add `createDynamicObject` stdlib function. (#1923)
This function takes a user provided `typeID` and arbitrary typed value, and turns them into an existential value whose `witnessTableID` is `typeID` and whose `anyValue` is the user provided value. This allows the users to pack the runtime type id info in arbitrary way.
Diffstat (limited to 'tests/compute/dynamic-dispatch-16.slang')
-rw-r--r--tests/compute/dynamic-dispatch-16.slang56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/compute/dynamic-dispatch-16.slang b/tests/compute/dynamic-dispatch-16.slang
new file mode 100644
index 000000000..5ceb75cd7
--- /dev/null
+++ b/tests/compute/dynamic-dispatch-16.slang
@@ -0,0 +1,56 @@
+// Test packing a user provided value and typeID into an existential value.
+
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -vk -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0 -use-dxil -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx11 -profile sm_5_0 -output-using-type
+
+[anyValueSize(16)]
+interface IInterface
+{
+ float run();
+}
+
+struct UserDefinedPackedType
+{
+ float3 val;
+ uint flags;
+};
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer
+RWStructuredBuffer<float> gOutputBuffer;
+
+//TEST_INPUT: set gObj = new StructuredBuffer<UserDefinedPackedType>[new UserDefinedPackedType{[1.0, 0.0, 0.0], 0}, new UserDefinedPackedType{[2.0, 3.0, 4.0], 1}];
+RWStructuredBuffer<UserDefinedPackedType> gObj;
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ float result = 0.0;
+ for (int i = 0; i < 2; i++)
+ {
+ var rawObj = gObj.Load(i);
+ IInterface dynamicObj = createDynamicObject<IInterface, UserDefinedPackedType>(rawObj.flags, rawObj);
+ result += dynamicObj.run();
+ }
+ gOutputBuffer[0] = result;
+}
+
+// Type must be marked `public` to ensure it is visible in the generated DLL.
+public struct FloatVal : IInterface
+{
+ float val;
+ float run()
+ {
+ return val;
+ }
+};
+interface ISomething{void g();}
+struct Float4Struct : ISomething { float4 val; void g() {} }
+public struct Float4Val : IInterface
+{
+ Float4Struct val;
+ float run()
+ {
+ return val.val.x + val.val.y;
+ }
+};