summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-10-04 01:40:58 -0700
committerGitHub <noreply@github.com>2020-10-04 01:40:58 -0700
commit3321df74904dfe3a11a41179b66a4c3ce5b57022 (patch)
tree2644bd8c0dcb3cdd148042745ed2fb7c51cd91ed
parent24ecd1fa2f37f3c4949989b53562e8f85833a8f6 (diff)
Handle partial existential parameter type specialization. (#1568)
* Specialize exsitentials parameters in struct fields. * Cleanup. * Handle partial existential parameter type specialization. Co-authored-by: Yong He <yhe@nvidia.com>
-rw-r--r--source/slang/slang-ir-insts.h2
-rw-r--r--source/slang/slang-ir.cpp10
-rw-r--r--tests/compute/interface-param-partial-specialize.slang46
-rw-r--r--tests/compute/interface-param-partial-specialize.slang.expected.txt4
4 files changed, 59 insertions, 3 deletions
diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h
index ef382373f..658e50f28 100644
--- a/source/slang/slang-ir-insts.h
+++ b/source/slang/slang-ir-insts.h
@@ -1807,7 +1807,7 @@ struct IRBuilder
IRInOutType* getInOutType(IRType* valueType);
IRRefType* getRefType(IRType* valueType);
IRPtrTypeBase* getPtrType(IROp op, IRType* valueType);
- IRExistentialBoxType* getExistentialBoxType(IRType* concreteType, IRType* interfaceType);
+ IRType* getExistentialBoxType(IRType* concreteType, IRType* interfaceType);
IRArrayTypeBase* getArrayTypeBase(
IROp op,
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index e9d90adfe..3820119d2 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -2336,10 +2336,14 @@ namespace Slang
operands);
}
- IRExistentialBoxType* IRBuilder::getExistentialBoxType(IRType* concreteType, IRType* interfaceType)
+ IRType* IRBuilder::getExistentialBoxType(IRType* concreteType, IRType* interfaceType)
{
+ // Don't wrap an existential box if concreteType is __Dynamic.
+ if (as<IRDynamicType>(concreteType))
+ return interfaceType;
+
IRInst* operands[] = {concreteType, interfaceType};
- return (IRExistentialBoxType*)getType(kIROp_ExistentialBoxType, 2, operands);
+ return getType(kIROp_ExistentialBoxType, 2, operands);
}
IRArrayTypeBase* IRBuilder::getArrayTypeBase(
@@ -2845,6 +2849,8 @@ namespace Slang
// We want to emit `makeExistential(load(value), witnessTable)`.
//
auto deref = emitLoad(value);
+ if (slotArgs[0]->op == kIROp_DynamicType)
+ return deref;
return emitMakeExistential(type, deref, slotArgs[1]);
}
}
diff --git a/tests/compute/interface-param-partial-specialize.slang b/tests/compute/interface-param-partial-specialize.slang
new file mode 100644
index 000000000..e856e04e8
--- /dev/null
+++ b/tests/compute/interface-param-partial-specialize.slang
@@ -0,0 +1,46 @@
+// Tests generating dynamic dispatch code for a function
+// with existential-struct-typed param by specializing it
+// with __Dynamic. This verifies that the handling of
+// "partially" specializing an existential type is correct.
+
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cuda
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu
+
+[anyValueSize(8)]
+interface IInterface
+{
+ uint eval();
+}
+
+public struct Impl : IInterface
+{
+ uint val;
+ uint eval()
+ {
+ return val;
+ }
+};
+
+struct Params
+{
+ StructuredBuffer<IInterface> obj;
+};
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
+RWStructuredBuffer<uint> gOutputBuffer;
+
+void compute(uint tid, Params p)
+{
+ gOutputBuffer[tid] = p.obj[0].eval();
+}
+
+//TEST_INPUT: entryPointExistentialType __Dynamic
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID,
+//TEST_INPUT:ubuffer(data=[rtti(Impl) witness(Impl, IInterface) 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-param-partial-specialize.slang.expected.txt b/tests/compute/interface-param-partial-specialize.slang.expected.txt
new file mode 100644
index 000000000..98fb6a686
--- /dev/null
+++ b/tests/compute/interface-param-partial-specialize.slang.expected.txt
@@ -0,0 +1,4 @@
+1
+1
+1
+1