diff options
| -rw-r--r-- | slang.h | 14 | ||||
| -rw-r--r-- | source/slang/slang-check.cpp | 10 | ||||
| -rw-r--r-- | source/slang/slang-compiler.h | 31 | ||||
| -rw-r--r-- | source/slang/slang-reflection.cpp | 1 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 69 |
5 files changed, 95 insertions, 30 deletions
@@ -2820,9 +2820,10 @@ namespace slang It is an error to create a composite component type that recursively aggregates the a single module more than once. */ - virtual SLANG_NO_THROW IComponentType* SLANG_MCALL createCompositeComponentType( + virtual SLANG_NO_THROW SlangResult SLANG_MCALL createCompositeComponentType( IComponentType* const* componentTypes, SlangInt componentTypeCount, + IComponentType** outCompositeComponentType, ISlangBlob** outDiagnostics = nullptr) = 0; /** Specialize a type based on type arguments. @@ -2965,13 +2966,12 @@ namespace slang The `specializationArgs` array must have `specializationArgCount` entries, and this must match the number of specialization parameters on this component type. - If the specialization arguments are not valid, then the function will return null. - If any diagnostics (error or warnings) are produced, they will be written to `outDiagnostics`. */ - virtual SLANG_NO_THROW IComponentType* SLANG_MCALL specialize( + virtual SLANG_NO_THROW SlangResult SLANG_MCALL specialize( SpecializationArg const* specializationArgs, SlangInt specializationArgCount, + IComponentType** outSpecializedComponentType, ISlangBlob** outDiagnostics = nullptr) = 0; }; #define SLANG_UUID_IComponentType { 0x5bc42be8, 0x5c50, 0x4929, { 0x9e, 0x5e, 0xd1, 0x5e, 0x7c, 0x24, 0x1, 0x5f } }; @@ -2999,7 +2999,6 @@ namespace slang #define SLANG_UUID_IModule { 0xc720e64, 0x8722, 0x4d31, { 0x89, 0x90, 0x63, 0x8a, 0x98, 0xb1, 0xc2, 0x79 } } - /** Argument used for specialization to types/values. */ struct SpecializationArg @@ -3041,6 +3040,11 @@ SLANG_API SlangResult spCompileRequest_getProgram( SlangCompileRequest* request, slang::IComponentType** outProgram); +SLANG_API SlangResult spCompileRequest_getEntryPoint( + SlangCompileRequest* request, + SlangInt entryPointIndex, + slang::IComponentType** outEntryPoint); + #endif /* DEPRECATED DEFINITIONS diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp index 33fc10e45..cec6b02a2 100644 --- a/source/slang/slang-check.cpp +++ b/source/slang/slang-check.cpp @@ -10840,7 +10840,8 @@ static bool doesParameterMatch( /// account any specialization arguments the user might have supplied. /// RefPtr<ComponentType> createUnspecializedGlobalAndEntryPointsComponentType( - FrontEndCompileRequest* compileRequest) + FrontEndCompileRequest* compileRequest, + List<RefPtr<ComponentType>>& outUnspecializedEntryPoints) { auto linkage = compileRequest->getLinkage(); auto sink = compileRequest->getSink(); @@ -10880,6 +10881,7 @@ static bool doesParameterMatch( // entryPointReq->getTranslationUnit()->entryPoints.add(entryPoint); + outUnspecializedEntryPoints.add(entryPoint); allComponentTypes.add(entryPoint); } } @@ -10958,6 +10960,7 @@ static bool doesParameterMatch( // translationUnit->entryPoints.add(entryPoint); + outUnspecializedEntryPoints.add(entryPoint); allComponentTypes.add(entryPoint); } } @@ -11570,7 +11573,8 @@ static bool doesParameterMatch( /// compilation (e.g., from the command line). /// RefPtr<ComponentType> createSpecializedGlobalAndEntryPointsComponentType( - EndToEndCompileRequest* endToEndReq) + EndToEndCompileRequest* endToEndReq, + List<RefPtr<ComponentType>>& outSpecializedEntryPoints) { auto specializedGlobalComponentType = endToEndReq->getSpecializedGlobalComponentType(); @@ -11587,6 +11591,8 @@ static bool doesParameterMatch( auto specializedEntryPoint = createSpecializedEntryPoint(endToEndReq, unspecializedEntryPoint, entryPointInfo); allComponentTypes.add(specializedEntryPoint); + + outSpecializedEntryPoints.add(specializedEntryPoint); } RefPtr<ComponentType> composed = CompositeComponentType::create(endToEndReq->getLinkage(), allComponentTypes); diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 0b97e2af7..c43af9506 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -287,9 +287,10 @@ namespace Slang SlangInt targetIndex, slang::IBlob** outCode, slang::IBlob** outDiagnostics) SLANG_OVERRIDE; - SLANG_NO_THROW IComponentType* SLANG_MCALL specialize( + SLANG_NO_THROW SlangResult SLANG_MCALL specialize( slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, + slang::IComponentType** outSpecializedComponentType, ISlangBlob** outDiagnostics) SLANG_OVERRIDE; /// Get the linkage (aka "session" in the public API) for this component type. @@ -810,12 +811,17 @@ namespace Slang return Super::getEntryPointCode(entryPointIndex, targetIndex, outCode, outDiagnostics); } - SLANG_NO_THROW IComponentType* SLANG_MCALL specialize( + SLANG_NO_THROW SlangResult SLANG_MCALL specialize( slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, + slang::IComponentType** outSpecializedComponentType, ISlangBlob** outDiagnostics) SLANG_OVERRIDE { - return Super::specialize(specializationArgs, specializationArgCount, outDiagnostics); + return Super::specialize( + specializationArgs, + specializationArgCount, + outSpecializedComponentType, + outDiagnostics); } // @@ -1077,10 +1083,11 @@ namespace Slang SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModule( const char* moduleName, slang::IBlob** outDiagnostics = nullptr) override; - SLANG_NO_THROW slang::IComponentType* SLANG_MCALL createCompositeComponentType( - slang::IComponentType* const* componentTypes, - SlangInt componentTypeCount, - ISlangBlob** outDiagnostics = nullptr) override; + SLANG_NO_THROW SlangResult SLANG_MCALL createCompositeComponentType( + slang::IComponentType* const* componentTypes, + SlangInt componentTypeCount, + slang::IComponentType** outCompositeComponentType, + ISlangBlob** outDiagnostics = nullptr) override; SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL specializeType( slang::TypeReflection* type, slang::SpecializationArg const* specializationArgs, @@ -1408,12 +1415,16 @@ namespace Slang /// Get a component type that represents the global scope of the compile request, plus the requested entry points. ComponentType* getGlobalAndEntryPointsComponentType() { return m_globalAndEntryPointsComponentType; } + List<RefPtr<ComponentType>> const& getUnspecializedEntryPoints() { return m_unspecializedEntryPoints; } + private: /// A component type that includes only the global scopes of the translation unit(s) that were compiled. RefPtr<ComponentType> m_globalComponentType; /// A component type that extends the global scopes with all of the entry points that were specified. RefPtr<ComponentType> m_globalAndEntryPointsComponentType; + + List<RefPtr<ComponentType>> m_unspecializedEntryPoints; }; /// A "legacy" program composes multiple translation units from a single compile request, @@ -1727,6 +1738,11 @@ namespace Slang ComponentType* getSpecializedGlobalComponentType() { return m_specializedGlobalComponentType; } ComponentType* getSpecializedGlobalAndEntryPointsComponentType() { return m_specializedGlobalAndEntryPointsComponentType; } + ComponentType* getSpecializedEntryPointComponentType(Index index) + { + return m_specializedEntryPoints[index]; + } + private: void init(); @@ -1736,6 +1752,7 @@ namespace Slang RefPtr<FrontEndCompileRequest> m_frontEndReq; RefPtr<ComponentType> m_specializedGlobalComponentType; RefPtr<ComponentType> m_specializedGlobalAndEntryPointsComponentType; + List<RefPtr<ComponentType>> m_specializedEntryPoints; RefPtr<BackEndCompileRequest> m_backEndReq; // For output diff --git a/source/slang/slang-reflection.cpp b/source/slang/slang-reflection.cpp index 5e6fd10cd..a6015b31c 100644 --- a/source/slang/slang-reflection.cpp +++ b/source/slang/slang-reflection.cpp @@ -1522,4 +1522,3 @@ SLANG_API SlangReflectionType* spReflection_specializeType( return convert(specializedType); } - diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index da04587fd..d5adae722 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -497,16 +497,22 @@ SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModule( return asExternal(module); } -SLANG_NO_THROW slang::IComponentType* SLANG_MCALL Linkage::createCompositeComponentType( - slang::IComponentType* const* componentTypes, - SlangInt componentTypeCount, - ISlangBlob** outDiagnostics) +SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompositeComponentType( + slang::IComponentType* const* componentTypes, + SlangInt componentTypeCount, + slang::IComponentType** outCompositeComponentType, + ISlangBlob** outDiagnostics) { // Attempting to create a "composite" of just one component type should // just return the component type itself, to avoid redundant work. // if( componentTypeCount == 1) - return componentTypes[0]; + { + auto componentType = componentTypes[0]; + componentType->addRef(); + *outCompositeComponentType = componentType; + return SLANG_OK; + } DiagnosticSink sink(getSourceManager()); @@ -521,7 +527,9 @@ SLANG_NO_THROW slang::IComponentType* SLANG_MCALL Linkage::createCompositeCompon childComponents); sink.getBlobIfNeeded(outDiagnostics); - return asExternal(composite.detach()); + + *outCompositeComponentType = asExternal(composite.detach()); + return SLANG_OK; } SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL Linkage::specializeType( @@ -953,13 +961,15 @@ RefPtr<ComponentType> createUnspecializedGlobalComponentType( FrontEndCompileRequest* compileRequest); RefPtr<ComponentType> createUnspecializedGlobalAndEntryPointsComponentType( - FrontEndCompileRequest* compileRequest); + FrontEndCompileRequest* compileRequest, + List<RefPtr<ComponentType>>& outUnspecializedEntryPoints); RefPtr<ComponentType> createSpecializedGlobalComponentType( EndToEndCompileRequest* endToEndReq); RefPtr<ComponentType> createSpecializedGlobalAndEntryPointsComponentType( - EndToEndCompileRequest* endToEndReq); + EndToEndCompileRequest* endToEndReq, + List<RefPtr<ComponentType>>& outSpecializedEntryPoints); void FrontEndCompileRequest::checkAllTranslationUnits() { @@ -1092,7 +1102,9 @@ SlangResult FrontEndCompileRequest::executeActionsInner() if (getSink()->GetErrorCount() != 0) return SLANG_FAIL; - m_globalAndEntryPointsComponentType = createUnspecializedGlobalAndEntryPointsComponentType(this); + m_globalAndEntryPointsComponentType = createUnspecializedGlobalAndEntryPointsComponentType( + this, + m_unspecializedEntryPoints); if (getSink()->GetErrorCount() != 0) return SLANG_FAIL; @@ -1208,6 +1220,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner() // m_specializedGlobalComponentType = getUnspecializedGlobalComponentType(); m_specializedGlobalAndEntryPointsComponentType = getUnspecializedGlobalAndEntryPointsComponentType(); + m_specializedEntryPoints = getFrontEndReq()->getUnspecializedEntryPoints(); return SLANG_OK; } @@ -1221,7 +1234,9 @@ SlangResult EndToEndCompileRequest::executeActionsInner() if (getSink()->GetErrorCount() != 0) return SLANG_FAIL; - m_specializedGlobalAndEntryPointsComponentType = createSpecializedGlobalAndEntryPointsComponentType(this); + m_specializedGlobalAndEntryPointsComponentType = createSpecializedGlobalAndEntryPointsComponentType( + this, + m_specializedEntryPoints); if (getSink()->GetErrorCount() != 0) return SLANG_FAIL; @@ -1260,6 +1275,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner() m_specializedGlobalComponentType = getUnspecializedGlobalComponentType(); m_specializedGlobalAndEntryPointsComponentType = composedProgram; + m_specializedEntryPoints = getFrontEndReq()->getUnspecializedEntryPoints(); } // Generate output code, in whatever format was requested @@ -1788,6 +1804,11 @@ RefPtr<ComponentType> ComponentType::specialize( SlangInt specializationArgCount, DiagnosticSink* sink) { + if(specializationArgCount == 0) + { + return this; + } + List<SpecializationArg> specializationArgs; specializationArgs.addRange( inSpecializationArgs, @@ -1810,9 +1831,10 @@ RefPtr<ComponentType> ComponentType::specialize( sink); } -SLANG_NO_THROW slang::IComponentType* SLANG_MCALL ComponentType::specialize( +SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::specialize( slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, + slang::IComponentType** outSpecializedComponentType, ISlangBlob** outDiagnostics) { DiagnosticSink sink(getLinkage()->getSourceManager()); @@ -1825,7 +1847,7 @@ SLANG_NO_THROW slang::IComponentType* SLANG_MCALL ComponentType::specialize( { // TODO: diagnose sink.getBlobIfNeeded(outDiagnostics); - return nullptr; + return SLANG_FAIL; } List<SpecializationArg> expandedArgs; @@ -1842,7 +1864,7 @@ SLANG_NO_THROW slang::IComponentType* SLANG_MCALL ComponentType::specialize( default: sink.getBlobIfNeeded(outDiagnostics); - return nullptr; + return SLANG_FAIL; } expandedArgs.add(expandedArg); } @@ -1854,7 +1876,9 @@ SLANG_NO_THROW slang::IComponentType* SLANG_MCALL ComponentType::specialize( sink.getBlobIfNeeded(outDiagnostics); - return specializedComponentType; + *outSpecializedComponentType = specializedComponentType.detach(); + + return SLANG_OK; } /// Visitor used by `ComponentType::enumerateModules` @@ -3305,12 +3329,27 @@ SLANG_API SlangResult spCompileRequest_getProgram( { if( !request ) return SLANG_ERROR_INVALID_PARAMETER; auto req = Slang::asInternal(request); - auto program = req->getSpecializedGlobalAndEntryPointsComponentType(); + auto program = req->getSpecializedGlobalComponentType(); *outProgram = Slang::ComPtr<slang::IComponentType>(program).detach(); return SLANG_OK; } +SLANG_API SlangResult spCompileRequest_getEntryPoint( + SlangCompileRequest* request, + SlangInt entryPointIndex, + slang::IComponentType** outEntryPoint) +{ + if( !request ) return SLANG_ERROR_INVALID_PARAMETER; + auto req = Slang::asInternal(request); + + auto entryPoint = req->getSpecializedEntryPointComponentType(entryPointIndex); + + *outEntryPoint = Slang::ComPtr<slang::IComponentType>(entryPoint).detach(); + return SLANG_OK; +} + + SLANG_API SlangReflection* spGetReflection( SlangCompileRequest* request) { |
