summaryrefslogtreecommitdiffstats
path: root/source/slang/type-layout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/type-layout.cpp')
-rw-r--r--source/slang/type-layout.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp
index 8fa790dd8..30b2ee01a 100644
--- a/source/slang/type-layout.cpp
+++ b/source/slang/type-layout.cpp
@@ -1222,6 +1222,11 @@ SimpleLayoutInfo GetLayoutImpl(
return GetLayoutImpl(subContext, type, outTypeLayout, SimpleLayoutInfo());
}
+int findGenericParam(List<RefPtr<GenericParamLayout>> & genericParameters, GlobalGenericParamDecl * decl)
+{
+ return (int)genericParameters.FindFirst([=](RefPtr<GenericParamLayout> & x) {return x->decl.Ptr() == decl; });
+}
+
SimpleLayoutInfo GetLayoutImpl(
TypeLayoutContext const& context,
Type* type,
@@ -1599,6 +1604,25 @@ SimpleLayoutInfo GetLayoutImpl(
return info;
}
+ else if (auto globalGenParam = declRef.As<GlobalGenericParamDecl>())
+ {
+ SimpleLayoutInfo info;
+ info.alignment = 0;
+ info.size = 0;
+ info.kind = LayoutResourceKind::GenericResource;
+ if (outTypeLayout)
+ {
+ auto genParamTypeLayout = new GenericParamTypeLayout();
+ // we should have already populated ProgramLayout::genericEntryPointParams list at this point,
+ // so we can find the index of this generic param decl in the list
+ genParamTypeLayout->type = type;
+ genParamTypeLayout->paramIndex = findGenericParam(context.targetReq->layout->globalGenericParams, genParamTypeLayout->getGlobalGenericParamDecl());
+ genParamTypeLayout->rules = rules;
+ genParamTypeLayout->findOrAddResourceInfo(LayoutResourceKind::GenericResource)->count++;
+ *outTypeLayout = genParamTypeLayout;
+ }
+ return info;
+ }
}
else if (auto errorType = type->As<ErrorType>())
{
@@ -1667,4 +1691,12 @@ RefPtr<TypeLayout> CreateTypeLayout(
return CreateTypeLayout(context, type, SimpleLayoutInfo());
}
+RefPtr<GlobalGenericParamDecl> GenericParamTypeLayout::getGlobalGenericParamDecl()
+{
+ auto declRefType = type->AsDeclRefType();
+ SLANG_ASSERT(declRefType);
+ auto rsDeclRef = declRefType->declRef.As<GlobalGenericParamDecl>();
+ return rsDeclRef.getDecl();
+}
+
} // namespace Slang