summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-09-03 01:57:31 -0700
committerGitHub <noreply@github.com>2021-09-03 01:57:31 -0700
commit0a81d11bc06e55089f7061225b9553329f697828 (patch)
tree31cc310eeb7cae68a5e3e49d882578da7e565dde /tests
parentcf7dddae74ae990c2b46a9feeaea3b7a33ec077d (diff)
Fix crash: dynamic dispatch of generic interface method. (#1929)
* Fix crash: dynamic dispatch of generic interface method. * Fix memory error. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/dynamic-dispatch-17.slang68
-rw-r--r--tests/compute/dynamic-dispatch-17.slang.expected.txt2
2 files changed, 70 insertions, 0 deletions
diff --git a/tests/compute/dynamic-dispatch-17.slang b/tests/compute/dynamic-dispatch-17.slang
new file mode 100644
index 000000000..bc2b9a6d9
--- /dev/null
+++ b/tests/compute/dynamic-dispatch-17.slang
@@ -0,0 +1,68 @@
+// Test using generic interface methods with dynamic dispatch.
+
+//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
+
+interface IReturnsZero
+{
+ float get();
+}
+
+[anyValueSize(16)]
+interface IInterface
+{
+ float run<Z:IReturnsZero>();
+}
+
+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, 2.0, 3.0], 3}, new UserDefinedPackedType{[2.0, 3.0, 4.0], 4}];
+RWStructuredBuffer<UserDefinedPackedType> gObj;
+
+//TEST_INPUT: type_conformance FloatVal:IInterface = 3
+//TEST_INPUT: type_conformance Float4Val:IInterface = 4
+
+[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<ReturnsZero>();
+ }
+ gOutputBuffer[0] = result;
+}
+
+struct ReturnsZero : IReturnsZero
+{
+ float get() { return 0.0; }
+}
+struct FloatVal : IInterface
+{
+ float val;
+ float run<Z:IReturnsZero>()
+ {
+ Z z;
+ return val + z.get();
+ }
+};
+struct Float4Struct { float4 val; }
+struct Float4Val : IInterface
+{
+ Float4Struct val;
+ float run<Z:IReturnsZero>()
+ {
+ Z z;
+ return val.val.x + val.val.y + z.get();
+ }
+};
diff --git a/tests/compute/dynamic-dispatch-17.slang.expected.txt b/tests/compute/dynamic-dispatch-17.slang.expected.txt
new file mode 100644
index 000000000..253df0793
--- /dev/null
+++ b/tests/compute/dynamic-dispatch-17.slang.expected.txt
@@ -0,0 +1,2 @@
+type: float
+6.0