diff options
| author | Yong He <yonghe@outlook.com> | 2017-11-20 05:28:22 -0500 |
|---|---|---|
| committer | Yong He <yonghe@outlook.com> | 2017-11-20 05:28:22 -0500 |
| commit | d6130baa8528c0a5b2e1b10b87fe02d8fc1a1b1a (patch) | |
| tree | 6aa5b2fe3a0fbfd8d2a02b38da9ca96f9fbd10ef /source | |
| parent | 3dff5a53a21ab2404918e772962004767024c0f3 (diff) | |
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)
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/ir.cpp | 23 | ||||
| -rw-r--r-- | source/slang/parameter-binding.cpp | 38 | ||||
| -rw-r--r-- | source/slang/syntax.cpp | 17 | ||||
| -rw-r--r-- | source/slang/syntax.h | 1 | ||||
| -rw-r--r-- | source/slang/type-layout.h | 2 |
5 files changed, 66 insertions, 15 deletions
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<Substitutions> cloneSubstitutions( + IRSpecContext* context, + Substitutions* subst); RefPtr<Type> IRSpecContext::maybeCloneType(Type* originalType) { - return originalType->Substitute(subst).As<Type>(); + auto rsType = originalType->Substitute(subst).As<Type>(); + if (auto declRefType = rsType.As<DeclRefType>()) + { + 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<GlobalGenericParamSubstitution*>(subst)) + { + RefPtr<GlobalGenericParamSubstitution> 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); diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 836ed254f..0daa2abc7 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -1425,6 +1425,16 @@ static RefPtr<TypeLayout> processEntryPointParameter( return structLayout; } + else if (auto globalGenericParam = declRef.As<GlobalGenericParamDecl>()) + { + 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->shared->programLayout->globalGenericParams, globalGenericParam.getDecl()); + genParamTypeLayout->findOrAddResourceInfo(LayoutResourceKind::GenericResource)->count++; + return genParamTypeLayout; + } else { SLANG_UNEXPECTED("unhandled type kind"); @@ -1442,7 +1452,8 @@ static RefPtr<TypeLayout> processEntryPointParameter( static void collectEntryPointParameters( ParameterBindingContext* context, - EntryPointRequest* entryPoint) + EntryPointRequest* entryPoint, + Substitutions* typeSubst) { FuncDecl* entryPointFuncDecl = entryPoint->decl; if (!entryPointFuncDecl) @@ -1507,7 +1518,7 @@ static void collectEntryPointParameters( auto paramTypeLayout = processEntryPointParameterWithPossibleSemantic( context, paramDecl.Ptr(), - paramDecl->type.type, + paramDecl->type.type->Substitute(typeSubst).As<Type>(), state, paramVarLayout); @@ -1539,7 +1550,7 @@ static void collectEntryPointParameters( auto resultTypeLayout = processEntryPointParameterWithPossibleSemantic( context, entryPointFuncDecl, - resultType, + resultType->Substitute(typeSubst).As<Type>(), state, resultLayout); @@ -1632,7 +1643,7 @@ static void collectParameters( for( auto& entryPoint : translationUnit->entryPoints ) { context->stage = entryPoint->profile.GetStage(); - collectEntryPointParameters(context, entryPoint.Ptr()); + collectEntryPointParameters(context, entryPoint.Ptr(), nullptr); } } @@ -1891,13 +1902,7 @@ RefPtr<ProgramLayout> specializeProgramLayout( newProgramLayout = new ProgramLayout(); newProgramLayout->bindingForHackSampler = programLayout->bindingForHackSampler; newProgramLayout->hackSamplerVar = programLayout->hackSamplerVar; - for (auto & entryPoint : programLayout->entryPoints) - { - RefPtr<EntryPointLayout> newEntryPoint = new EntryPointLayout(*entryPoint); - // TODO: for now just copy existing entry point layouts, but we eventually need to - // specialize these as well... - newProgramLayout->entryPoints.Add(newEntryPoint); - } + newProgramLayout->globalGenericParams = programLayout->globalGenericParams; List<RefPtr<TypeLayout>> paramTypeLayouts; auto globalStructLayout = getGlobalStructLayout(programLayout); @@ -1919,7 +1924,7 @@ RefPtr<ProgramLayout> specializeProgramLayout( SharedParameterBindingContext sharedContext; sharedContext.compileRequest = targetReq->compileRequest; sharedContext.defaultLayoutRules = layoutContext.getRulesFamily(); - sharedContext.programLayout = programLayout; + sharedContext.programLayout = newProgramLayout; // Create a sub-context to collect parameters that get // declared into the global scope @@ -1928,6 +1933,15 @@ RefPtr<ProgramLayout> specializeProgramLayout( context.translationUnit = nullptr; context.layoutContext = layoutContext; + + for (auto & translationUnit : targetReq->compileRequest->translationUnits) + { + for (auto & entryPoint : translationUnit->entryPoints) + { + collectEntryPointParameters(&context, entryPoint, typeSubst); + } + } + auto constantBufferRules = context.getRulesFamily()->getConstantBufferRules(); structLayout->rules = constantBufferRules; diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index e43dd9074..badfaea4f 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -1709,7 +1709,22 @@ void Type::accept(IValVisitor* visitor, void* extra) return sb.ProduceString(); } - + void insertSubstAtBottom(RefPtr<Substitutions> & substHead, RefPtr<Substitutions> substToInsert) + { + if (!substHead) + { + substHead = substToInsert; + return; + } + auto subst = substHead; + RefPtr<Substitutions> lastSubst = subst; + while (subst->outer) + { + lastSubst = subst; + subst = subst->outer; + } + lastSubst->outer = substToInsert; + } void insertSubstAtTop(DeclRefBase & declRef, RefPtr<Substitutions> substToInsert) { diff --git a/source/slang/syntax.h b/source/slang/syntax.h index b4d550ef5..f3690d9ae 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -1156,6 +1156,7 @@ namespace Slang Session* session, Decl* decl); + void insertSubstAtBottom(RefPtr<Substitutions> & substHead, RefPtr<Substitutions> substToInsert); RefPtr<ThisTypeSubstitution> getNewThisTypeSubst(DeclRefBase & declRef); RefPtr<ThisTypeSubstitution> getThisTypeSubst(DeclRefBase & declRef, bool insertSubstEntry); void removeSubstitution(DeclRefBase & declRef, RefPtr<Substitutions> subst); diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h index 4ce6dc355..07530bdfc 100644 --- a/source/slang/type-layout.h +++ b/source/slang/type-layout.h @@ -676,7 +676,7 @@ createStructuredBufferTypeLayout( RefPtr<Type> structuredBufferType, RefPtr<Type> elementType); - +int findGenericParam(List<RefPtr<GenericParamLayout>> & genericParameters, GlobalGenericParamDecl * decl); // } |
