From e5b796db188416dfc414dab27b92c86b0b53de2b Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 10 Sep 2020 15:10:11 -0700 Subject: Allow existential types in `StructuredBuffer` element type. (#1536) * Allow existential types in `StructuredBuffer` element type. * Handle StructuredBuffer.Load/.Consume methods * Clean up unnecessary changes * Code cleanup * Update test comment --- tests/compute/dynamic-dispatch-13.slang | 45 ++++++++++++++++++++++ .../compute/dynamic-dispatch-13.slang.expected.txt | 4 ++ 2 files changed, 49 insertions(+) create mode 100644 tests/compute/dynamic-dispatch-13.slang create mode 100644 tests/compute/dynamic-dispatch-13.slang.expected.txt (limited to 'tests') diff --git a/tests/compute/dynamic-dispatch-13.slang b/tests/compute/dynamic-dispatch-13.slang new file mode 100644 index 000000000..723f42f52 --- /dev/null +++ b/tests/compute/dynamic-dispatch-13.slang @@ -0,0 +1,45 @@ +// Test using interface typed shader parameters wrapped inside a `StructuredBuffer`. + +//TEST(compute):COMPARE_COMPUTE:-cpu +//DISABLE_TEST(compute):COMPARE_COMPUTE:-cuda -xslang -disable-specialization + +[anyValueSize(8)] +interface IInterface +{ + int run(int input); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer +RWStructuredBuffer gOutputBuffer; + +//TEST_INPUT:ubuffer(data=[rtti(MyImpl) witness(MyImpl, IInterface) 1 0], stride=4):name=gCb +StructuredBuffer gCb; + +//TEST_INPUT:ubuffer(data=[rtti(MyImpl) witness(MyImpl, IInterface) 1 0], stride=4):name=gCb1 +StructuredBuffer gCb1; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + let tid = dispatchThreadID.x; + + let inputVal : int = tid; + IInterface v0 = gCb.Load(0); + IInterface v1 = gCb1[0]; + let outputVal = v0.run(inputVal) + v1.run(inputVal); + + gOutputBuffer[tid] = outputVal; +} + +// Specialize gCb1, but not gCb2 +//TEST_INPUT: globalExistentialType MyImpl +//TEST_INPUT: globalExistentialType __Dynamic +// Type must be marked `public` to ensure it is visible in the generated DLL. +public struct MyImpl : IInterface +{ + int val; + int run(int input) + { + return input + val; + } +}; diff --git a/tests/compute/dynamic-dispatch-13.slang.expected.txt b/tests/compute/dynamic-dispatch-13.slang.expected.txt new file mode 100644 index 000000000..628d2a8fd --- /dev/null +++ b/tests/compute/dynamic-dispatch-13.slang.expected.txt @@ -0,0 +1,4 @@ +2 +4 +6 +8 -- cgit v1.2.3