From d6130baa8528c0a5b2e1b10b87fe02d8fc1a1b1a Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 20 Nov 2017 05:28:22 -0500 Subject: fixup global generic parameters 1. simplify RoundUpToAlignment() 2. add new a render-compute test case to cover the situation where the entry-point interface (parameter/return types of an entry-point function) is dependent on the global generic type. 3. initial fixes to get this test case to compile (but is not producing correct HLSL output yet) --- source/slang/ir.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'source/slang/ir.cpp') diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 2d3127a61..f5f52e08a 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -3103,10 +3103,22 @@ namespace Slang IRGlobalVar* cloneGlobalVar(IRSpecContext* context, IRGlobalVar* originalVar); IRFunc* cloneFunc(IRSpecContext* context, IRFunc* originalFunc); IRWitnessTable* cloneWitnessTable(IRSpecContext* context, IRWitnessTable* originalVar); + RefPtr cloneSubstitutions( + IRSpecContext* context, + Substitutions* subst); RefPtr IRSpecContext::maybeCloneType(Type* originalType) { - return originalType->Substitute(subst).As(); + auto rsType = originalType->Substitute(subst).As(); + if (auto declRefType = rsType.As()) + { + if (subst) + { + auto newSubst = cloneSubstitutions(this, subst); + insertSubstAtBottom(declRefType->declRef.substitutions, newSubst); + } + } + return rsType; } IRValue* IRSpecContext::maybeCloneValue(IRValue* originalValue) @@ -3243,6 +3255,15 @@ namespace Slang newSubst->outer = cloneSubstitutions(context, subst->outer); return newSubst; } + else if (auto genTypeSubst = dynamic_cast(subst)) + { + RefPtr newSubst = new GlobalGenericParamSubstitution(); + newSubst->actualType = genTypeSubst->actualType; + newSubst->paramDecl = genTypeSubst->paramDecl; + newSubst->witnessTables = genTypeSubst->witnessTables; + newSubst->outer = cloneSubstitutions(context, subst->outer); + return newSubst; + } else SLANG_UNREACHABLE("unimplemented cloneSubstitution"); UNREACHABLE_RETURN(nullptr); -- cgit v1.2.3 From 64108c88836ed6b0335b000d4d127113f6840010 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 21 Nov 2017 19:26:17 -0500 Subject: Add logic to propagate GlobalGenericParamSubstitution --- source/slang/ir.cpp | 10 +++++++++- source/slang/syntax.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'source/slang/ir.cpp') diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index f5f52e08a..109bae353 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -3109,7 +3109,7 @@ namespace Slang RefPtr IRSpecContext::maybeCloneType(Type* originalType) { - auto rsType = originalType->Substitute(subst).As(); + auto rsType = originalType->GetCanonicalType()->Substitute(subst).As(); if (auto declRefType = rsType.As()) { if (subst) @@ -3118,6 +3118,14 @@ namespace Slang insertSubstAtBottom(declRefType->declRef.substitutions, newSubst); } } + else if (auto funcType = rsType.As()) + { + RefPtr newFuncType = new FuncType(); + newFuncType->setSession(funcType->getSession()); + newFuncType->resultType = maybeCloneType(funcType->resultType); + for (auto paramType : funcType->paramTypes) + newFuncType->paramTypes.Add(maybeCloneType(paramType)); + } return rsType; } diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index badfaea4f..2c214a332 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -1309,9 +1309,39 @@ void Type::accept(IValVisitor* visitor, void* extra) UNREACHABLE_RETURN(expr); } + bool hasGlobalGenericSubst(Substitutions * destSubst, GlobalGenericParamSubstitution * genSubst) + { + while (destSubst) + { + if (auto globalParamSubst = dynamic_cast(destSubst)) + { + if (globalParamSubst->paramDecl == genSubst->paramDecl) + return true; + } + destSubst = destSubst->outer; + } + return false; + } + void insertGlobalGenericSubstitutions(RefPtr & destSubst, Substitutions * srcSubst) + { + while (srcSubst) + { + if (auto globalGenSubst = dynamic_cast(srcSubst)) + { + if (!hasGlobalGenericSubst(destSubst, globalGenSubst)) + { + RefPtr cpyGlobalGenSubst = new GlobalGenericParamSubstitution(*globalGenSubst); + cpyGlobalGenSubst->outer = nullptr; + insertSubstAtBottom(destSubst, cpyGlobalGenSubst); + } + } + srcSubst = srcSubst->outer; + } + } DeclRefBase DeclRefBase::SubstituteImpl(Substitutions* subst, int* ioDiff) { + insertGlobalGenericSubstitutions(substitutions, subst); if (!substitutions) return *this; int diff = 0; -- cgit v1.2.3