diff options
Diffstat (limited to 'source/slang/slang-compiler.cpp')
| -rw-r--r-- | source/slang/slang-compiler.cpp | 144 |
1 files changed, 69 insertions, 75 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 64afef136..1c0bed065 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -199,10 +199,12 @@ namespace Slang // RefPtr<EntryPoint> EntryPoint::create( + Linkage* linkage, DeclRef<FuncDecl> funcDeclRef, Profile profile) { RefPtr<EntryPoint> entryPoint = new EntryPoint( + linkage, funcDeclRef.GetName(), profile, funcDeclRef); @@ -210,10 +212,12 @@ namespace Slang } RefPtr<EntryPoint> EntryPoint::createDummyForPassThrough( + Linkage* linkage, Name* name, Profile profile) { RefPtr<EntryPoint> entryPoint = new EntryPoint( + linkage, name, profile, DeclRef<FuncDecl>()); @@ -221,103 +225,93 @@ namespace Slang } EntryPoint::EntryPoint( + Linkage* linkage, Name* name, Profile profile, DeclRef<FuncDecl> funcDeclRef) - : m_name(name) + : ComponentType(linkage) + , m_name(name) , m_profile(profile) , m_funcDeclRef(funcDeclRef) { - // In order for later code generation to work, we need to track what - // modules each entry point depends on. We will build up the dependency - // list here when an `EntryPoint` gets created. - // - // We know an entry point depends on the module that declared the - // entry-point function itself. - // - // Note: we are carefully handling the case where `module` could - // be null, becase of "dummy" entry points created for pass-through - // compilation. + // Collect any specialization parameters used by the entry point // - if(auto module = getModule()) + _collectShaderParams(); + } + + Module* EntryPoint::getModule() + { + return Slang::getModule(getFuncDecl()); + } + + Index EntryPoint::getSpecializationParamCount() + { + return m_genericSpecializationParams.getCount() + m_existentialSpecializationParams.getCount(); + } + + SpecializationParam const& EntryPoint::getSpecializationParam(Index index) + { + auto genericParamCount = m_genericSpecializationParams.getCount(); + if(index < genericParamCount) { - m_dependencyList.addDependency(module); + return m_genericSpecializationParams[index]; } - // - // TODO: We also need to include the modules needed by any generic - // arguments in the dependency list, since in the general case they - // might come from modules other than the one defining the entry point. + else + { + return m_existentialSpecializationParams[index - genericParamCount]; + } + } - // The following is a bit of a hack. - // - // Back-end code generation relies on us having computed layouts for all tagged - // unions that end up being used in the code, which means we need a way to find - // all such types that get used in a program (and the stuff it imports). - // - // For now we are assuming a tagged union type only comes into existence - // as a (top-level) argument for a generic type parameter, so that we - // can check for them here and cache them on the entry point. + Index EntryPoint::getRequirementCount() + { + // The only requirement of an entry point is the module that contains it. // - // A longer-term strategy might need to consider any (tagged or untagged) - // union types that get used inside of a module, and also take - // those lists into account. + // TODO: We will eventually want to support the case of an entry + // point nested in a `struct` type, in which case there should be + // a single requirement representing that outer type (so that multiple + // entry points nested under the same type can share the storage + // for parameters at that scope). + + // Note: the defensive coding is here because the + // "dummy" entry points we create for pass-through + // compilation will not have an associated module. // - // An even longer-term strategy would be to allow type layout to - // be performed on IR types, so taht we don't need to have front-end - // code worrying about this stuff. - // - for( auto subst = funcDeclRef.substitutions.substitutions; subst; subst = subst->outer ) + if( auto module = getModule() ) { - if( auto genericSubst = as<GenericSubstitution>(subst) ) - { - for( auto arg : genericSubst->args ) - { - if( auto taggedUnionType = as<TaggedUnionType>(arg) ) - { - m_taggedUnionTypes.add(taggedUnionType); - } - } - } + return 1; } - - // Collect any existential-type parameters used by the entry point - // - _collectShaderParams(); + return 0; } - Module* EntryPoint::getModule() + RefPtr<ComponentType> EntryPoint::getRequirement(Index index) { - return Slang::getModule(getFuncDecl()); + SLANG_UNUSED(index); + SLANG_ASSERT(index == 0); + SLANG_ASSERT(getModule()); + return getModule(); } - Linkage* EntryPoint::getLinkage() + void EntryPoint::acceptVisitor(ComponentTypeVisitor* visitor, SpecializationInfo* specializationInfo) { - return getModule()->getLinkage(); + visitor->visitEntryPoint(this, as<EntryPointSpecializationInfo>(specializationInfo)); } - // - // EntryPointGroup - // - - RefPtr<EntryPointGroup> EntryPointGroup::create( - Linkage* linkage, - List<RefPtr<EntryPoint>> const& entryPoints, - DiagnosticSink* sink) + List<Module*> const& EntryPoint::getModuleDependencies() { - RefPtr<EntryPointGroup> group = new EntryPointGroup(linkage); - - for( auto entryPoint : entryPoints ) - { - for( auto module : entryPoint->getModuleDependencies() ) - { - group->m_dependencyList.addDependency(module); - } - group->m_entryPoints.add(entryPoint); - } + if(auto module = getModule()) + return module->getModuleDependencies(); - group->_collectShaderParams(sink); + static List<Module*> empty; + return empty; + } - return group; + List<String> const& EntryPoint::getFilePathDependencies() + { + if(auto module = getModule()) + return getModule()->getFilePathDependencies(); + + static List<String> empty; + return empty; } // @@ -1949,7 +1943,7 @@ SlangResult dissassembleDXILUsingDXC( TargetRequest* targetReq, Int entryPointIndex) { - auto program = compileRequest->getSpecializedProgram(); + auto program = compileRequest->getSpecializedGlobalAndEntryPointsComponentType(); auto targetProgram = program->getTargetProgram(targetReq); auto backEndReq = compileRequest->getBackEndReq(); @@ -2020,7 +2014,7 @@ SlangResult dissassembleDXILUsingDXC( return result; RefPtr<BackEndCompileRequest> backEndRequest = new BackEndCompileRequest( - m_program->getLinkageImpl(), + m_program->getLinkage(), sink, m_program); @@ -2083,7 +2077,7 @@ SlangResult dissassembleDXILUsingDXC( if (compileRequest->isCommandLineCompile) { auto linkage = compileRequest->getLinkage(); - auto program = compileRequest->getSpecializedProgram(); + auto program = compileRequest->getSpecializedGlobalAndEntryPointsComponentType(); for (auto targetReq : linkage->targets) { Index entryPointCount = program->getEntryPointCount(); |
