From 0a81d11bc06e55089f7061225b9553329f697828 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 3 Sep 2021 01:57:31 -0700 Subject: 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 --- tests/compute/dynamic-dispatch-17.slang | 68 ++++++++++++++++++++++ .../compute/dynamic-dispatch-17.slang.expected.txt | 2 + 2 files changed, 70 insertions(+) create mode 100644 tests/compute/dynamic-dispatch-17.slang create mode 100644 tests/compute/dynamic-dispatch-17.slang.expected.txt (limited to 'tests') 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(); +} + +struct UserDefinedPackedType +{ + float3 val; + uint flags; +}; + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer +RWStructuredBuffer gOutputBuffer; + +//TEST_INPUT: set gObj = new StructuredBuffer[new UserDefinedPackedType{[1.0, 2.0, 3.0], 3}, new UserDefinedPackedType{[2.0, 3.0, 4.0], 4}]; +RWStructuredBuffer 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(rawObj.flags, rawObj); + result += dynamicObj.run(); + } + gOutputBuffer[0] = result; +} + +struct ReturnsZero : IReturnsZero +{ + float get() { return 0.0; } +} +struct FloatVal : IInterface +{ + float val; + float run() + { + Z z; + return val + z.get(); + } +}; +struct Float4Struct { float4 val; } +struct Float4Val : IInterface +{ + Float4Struct val; + float run() + { + 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 -- cgit v1.2.3