From 9f3e83cf0d664c87a618edf08d834829178030e6 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 6 Sep 2022 16:08:48 -0700 Subject: Specialize and SSA in a loop + better diagnostics on dynamic dispatch failure (#2396) * Report diagnostic when dynamic dispatch failed instead of crashing. * Specialize and SSA in a loop. Explicit specialization only interface. Co-authored-by: Yong He --- tests/bugs/specialize-existential-in-generic.slang | 42 ++++++++++++++++++++++ ...alize-existential-in-generic.slang.expected.txt | 4 +++ 2 files changed, 46 insertions(+) create mode 100644 tests/bugs/specialize-existential-in-generic.slang create mode 100644 tests/bugs/specialize-existential-in-generic.slang.expected.txt (limited to 'tests') diff --git a/tests/bugs/specialize-existential-in-generic.slang b/tests/bugs/specialize-existential-in-generic.slang new file mode 100644 index 000000000..31ef75512 --- /dev/null +++ b/tests/bugs/specialize-existential-in-generic.slang @@ -0,0 +1,42 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj + +[Specialize] +interface IAssoc +{ + int getInner(); +} + +interface IFoo +{ + associatedtype Assoc : IAssoc; + Assoc getValue(); +} + +struct Impl : IFoo +{ + struct Assoc : IAssoc { int getInner() { return 1; } } + Assoc getValue() { Assoc r; return r; } +} + +struct GenType +{ + T obj; + int doThing() + { + IAssoc soc = obj.getValue(); // "boxing" into an existential + + // a specialized version of this function should call specialized method instead of going through dynamic dispatch. + return soc.getInner(); + } +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer +RWStructuredBuffer gOutputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + GenType val; + gOutputBuffer[tid] = val.doThing(); +} \ No newline at end of file diff --git a/tests/bugs/specialize-existential-in-generic.slang.expected.txt b/tests/bugs/specialize-existential-in-generic.slang.expected.txt new file mode 100644 index 000000000..ef529012e --- /dev/null +++ b/tests/bugs/specialize-existential-in-generic.slang.expected.txt @@ -0,0 +1,4 @@ +1 +1 +1 +1 \ No newline at end of file -- cgit v1.2.3