From a2a7c4d988b2b7126130d9dcbe4ec94e1ce8424b Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 2 Sep 2020 12:21:28 -0700 Subject: Allow unspecialized existential shader parameters (dynamic dispatch). (#1529) * Allow unspecialized existential shader parameters (dynamic dispatch). * Fixes. * Fixes * disable cuda test --- source/slang/slang-lower-to-ir.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-lower-to-ir.cpp') diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 539027e74..ee5338236 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -1038,6 +1038,11 @@ static void addLinkageDecoration( { builder->addExportDecoration(inst, mangledName); } + if (decl->findModifier()) + { + builder->addPublicDecoration(inst); + builder->addKeepAliveDecoration(inst); + } } static void addLinkageDecoration( @@ -5161,6 +5166,15 @@ struct DeclLoweringVisitor : DeclVisitor return LoweredValInfo::simple(inst); } + bool isPublicType(Type* type) + { + if (auto declRefType = as(type)) + { + if (declRefType->declRef.getDecl()->findModifier()) + return true; + } + return false; + } void lowerWitnessTable( IRGenContext* subContext, @@ -5211,6 +5225,12 @@ struct DeclLoweringVisitor : DeclVisitor astReqWitnessTable->witnessedType, astReqWitnessTable->baseType); subBuilder->addExportDecoration(irSatisfyingWitnessTable, mangledName.getUnownedSlice()); + if (isPublicType(astReqWitnessTable->witnessedType)) + { + subBuilder->addPublicDecoration(irSatisfyingWitnessTable); + subBuilder->addKeepAliveDecoration(irSatisfyingWitnessTable); + } + // Recursively lower the sub-table. lowerWitnessTable( subContext, @@ -5327,6 +5347,11 @@ struct DeclLoweringVisitor : DeclVisitor // Create the IR-level witness table auto irWitnessTable = subBuilder->createWitnessTable(irWitnessTableBaseType); addLinkageDecoration(context, irWitnessTable, inheritanceDecl, mangledName.getUnownedSlice()); + if (parentDecl->findModifier()) + { + subBuilder->addPublicDecoration(irWitnessTable); + subBuilder->addKeepAliveDecoration(irWitnessTable); + } // Register the value now, rather than later, to avoid any possible infinite recursion. setGlobalValue(context, inheritanceDecl, LoweredValInfo::simple(irWitnessTable)); @@ -6154,6 +6179,8 @@ struct DeclLoweringVisitor : DeclVisitor SLANG_UNREACHABLE("associatedtype should have been handled by visitAssocTypeDecl."); } + bool isPublicType = decl->findModifier() != nullptr; + // Given a declaration of a type, we need to make sure // to output "witness tables" for any interfaces this // type has declared conformance to. @@ -6171,11 +6198,11 @@ struct DeclLoweringVisitor : DeclVisitor // Emit any generics that should wrap the actual type. auto outerGeneric = emitOuterGenerics(subContext, decl, decl); - IRStructType* irStruct = subBuilder->createStructType(); addNameHint(context, irStruct, decl); addLinkageDecoration(context, irStruct, decl); + subBuilder->setInsertInto(irStruct); // A `struct` that inherits from another `struct` must start @@ -6183,6 +6210,8 @@ struct DeclLoweringVisitor : DeclVisitor // for( auto inheritanceDecl : decl->getMembersOfType() ) { + if (isPublicType) + ensureDecl(context, inheritanceDecl); auto superType = inheritanceDecl->base; if(auto superDeclRefType = as(superType)) { -- cgit v1.2.3