From d930c65e7fef6414af363e1f8d4fff52beb448af Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 5 Oct 2020 10:30:27 -0700 Subject: Update the type of a call inst during specialization. (#1569) --- source/slang/slang-ir-specialize.cpp | 6 +++ tests/compute/interface-assoc-type-param.slang | 60 ++++++++++++++++++++++ .../interface-assoc-type-param.slang.expected.txt | 4 ++ 3 files changed, 70 insertions(+) create mode 100644 tests/compute/interface-assoc-type-param.slang create mode 100644 tests/compute/interface-assoc-type-param.slang.expected.txt diff --git a/source/slang/slang-ir-specialize.cpp b/source/slang/slang-ir-specialize.cpp index ceba4b03c..caaa700a0 100644 --- a/source/slang/slang-ir-specialize.cpp +++ b/source/slang/slang-ir-specialize.cpp @@ -901,6 +901,12 @@ struct SpecializationContext if(!calleeFunc) return; + // Update result type since the callee may have been changed. + if (inst->getDataType() != calleeFunc->getResultType()) + { + inst->setFullType(calleeFunc->getResultType()); + } + // We can only specialize if we have access to a body for the callee. // if(!calleeFunc->isDefinition()) diff --git a/tests/compute/interface-assoc-type-param.slang b/tests/compute/interface-assoc-type-param.slang new file mode 100644 index 000000000..d43a43fc9 --- /dev/null +++ b/tests/compute/interface-assoc-type-param.slang @@ -0,0 +1,60 @@ +// Tests using associated types through an existential-struct-typed param. + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cuda +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu + +[anyValueSize(8)] +interface IInterface +{ + associatedtype TEval:IEval; + TEval getEval(); +} + +[anyValueSize(8)] +interface IEval +{ + uint eval(); +} + +struct Impl : IInterface +{ + uint val; + struct TEval : IEval + { + uint val; + uint eval() + { + return val; + } + }; + TEval getEval() + { + TEval rs; + rs.val = val; + return rs; + } +}; + +struct Params +{ + StructuredBuffer obj; +}; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer +RWStructuredBuffer gOutputBuffer; + +void compute(uint tid, Params p) +{ + gOutputBuffer[tid] = p.obj[0].getEval().eval(); +} + +//TEST_INPUT: entryPointExistentialType Impl + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID, +//TEST_INPUT:ubuffer(data=[0 0 0 0 1 0], stride=4):name=params.obj + uniform Params params) +{ + uint tid = dispatchThreadID.x; + compute(tid, params); +} \ No newline at end of file diff --git a/tests/compute/interface-assoc-type-param.slang.expected.txt b/tests/compute/interface-assoc-type-param.slang.expected.txt new file mode 100644 index 000000000..98fb6a686 --- /dev/null +++ b/tests/compute/interface-assoc-type-param.slang.expected.txt @@ -0,0 +1,4 @@ +1 +1 +1 +1 -- cgit v1.2.3