summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-layout.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-07-21 22:52:27 -0700
committerGitHub <noreply@github.com>2022-07-21 22:52:27 -0700
commit73b52f6075eb8a4f674e5d66d2a6192ca71f26d3 (patch)
tree0fb7fbea8356323dcb0ac4173cf2fc97c02d3fcf /source/slang/slang-ir-layout.cpp
parent91c8c3f32c4b827dedc74d2ecdfe72a3403fc357 (diff)
Allow dynamic dispatch to handle nested interface-typed fields. (#2336)
Diffstat (limited to 'source/slang/slang-ir-layout.cpp')
-rw-r--r--source/slang/slang-ir-layout.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/source/slang/slang-ir-layout.cpp b/source/slang/slang-ir-layout.cpp
index c89d15808..cbf0a6e61 100644
--- a/source/slang/slang-ir-layout.cpp
+++ b/source/slang/slang-ir-layout.cpp
@@ -3,6 +3,8 @@
#include "slang-ir-insts.h"
+#include "slang-ir-generics-lowering-context.h"
+
// This file implements facilities for computing and caching layout
// information on IR types.
//
@@ -194,7 +196,52 @@ static Result _calcNaturalSizeAndAlignment(
outSizeAndAlignment);
}
break;
-
+ case kIROp_AnyValueType:
+ {
+ auto anyValType = cast<IRAnyValueType>(type);
+ outSizeAndAlignment->size = getIntVal(anyValType->getSize());
+ outSizeAndAlignment->alignment = 4;
+ return SLANG_OK;
+ }
+ break;
+ case kIROp_TupleType:
+ {
+ auto tupleType = cast<IRTupleType>(type);
+ IRSizeAndAlignment resultLayout;
+ for (UInt i = 0; i < tupleType->getOperandCount(); i++)
+ {
+ auto elementType = tupleType->getOperand(i);
+ IRSizeAndAlignment fieldTypeLayout;
+ SLANG_RETURN_ON_FAIL(getNaturalSizeAndAlignment(target, (IRType*)elementType, &fieldTypeLayout));
+ resultLayout.size = align(resultLayout.size, fieldTypeLayout.alignment);
+ resultLayout.alignment = std::max(resultLayout.alignment, fieldTypeLayout.alignment);
+ }
+ *outSizeAndAlignment = resultLayout;
+ return SLANG_OK;
+ }
+ break;
+ case kIROp_WitnessTableType:
+ case kIROp_WitnessTableIDType:
+ case kIROp_RTTIHandleType:
+ {
+ outSizeAndAlignment->size = kRTTIHandleSize;
+ outSizeAndAlignment->alignment = 4;
+ return SLANG_OK;
+ }
+ break;
+ case kIROp_InterfaceType:
+ {
+ auto interfaceType = cast<IRInterfaceType>(type);
+ auto size = SharedGenericsLoweringContext::getInterfaceAnyValueSize(interfaceType, interfaceType->sourceLoc);
+ size += kRTTIHeaderSize;
+ size = align(size, 4);
+ IRSizeAndAlignment resultLayout;
+ resultLayout.size = size;
+ resultLayout.alignment = 4;
+ *outSizeAndAlignment = resultLayout;
+ return SLANG_OK;
+ }
+ break;
case kIROp_MatrixType:
{
auto matType = cast<IRMatrixType>(type);