diff options
| -rw-r--r-- | include/slang.h | 25 | ||||
| -rw-r--r-- | source/slang-record-replay/record/slang-module.cpp | 11 | ||||
| -rw-r--r-- | source/slang-record-replay/record/slang-module.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-compiler-tu.cpp | 80 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 38 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 4 | ||||
| -rw-r--r-- | tests/library/linked.spirv | bin | 0 -> 816 bytes | |||
| -rw-r--r-- | tools/gfx-unit-test/precompiled-module-2.cpp | 18 |
8 files changed, 158 insertions, 21 deletions
diff --git a/include/slang.h b/include/slang.h index 81b3ac1cb..6e4ab6250 100644 --- a/include/slang.h +++ b/include/slang.h @@ -5601,13 +5601,34 @@ namespace slang SlangInt32 index) = 0; virtual SLANG_NO_THROW DeclReflection* SLANG_MCALL getModuleReflection() = 0; + }; + + #define SLANG_UUID_IModule IModule::getTypeGuid() + + /* Experimental interface for doing target precompilation of slang modules */ + struct IModulePrecompileService_Experimental : public ISlangUnknown + { + //uuidgen output: 8e12e8e3 - 5fcd - 433e - afcb - 13a088bc5ee5 + SLANG_COM_INTERFACE(0x8e12e8e3, 0x5fcd, 0x433e, { 0xaf, 0xcb, 0x13, 0xa0, 0x88, 0xbc, 0x5e, 0xe5 }) virtual SLANG_NO_THROW SlangResult SLANG_MCALL precompileForTarget( SlangCompileTarget target, ISlangBlob** outDiagnostics) = 0; + + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPrecompiledTargetCode( + SlangCompileTarget target, + IBlob** outCode, + IBlob** outDiagnostics = nullptr) = 0; + + virtual SLANG_NO_THROW SlangInt SLANG_MCALL getModuleDependencyCount() = 0; + + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getModuleDependency( + SlangInt dependencyIndex, + IModule** outModule, + IBlob** outDiagnostics = nullptr) = 0; }; - - #define SLANG_UUID_IModule IModule::getTypeGuid() + + #define SLANG_UUID_IModulePrecompileService_Experimental IModulePrecompileService_Experimental::getTypeGuid() /** Argument used for specialization to types/values. */ diff --git a/source/slang-record-replay/record/slang-module.cpp b/source/slang-record-replay/record/slang-module.cpp index 1ad04d4dc..5f624a2e0 100644 --- a/source/slang-record-replay/record/slang-module.cpp +++ b/source/slang-record-replay/record/slang-module.cpp @@ -213,17 +213,6 @@ namespace SlangRecord return res; } - SLANG_NO_THROW SlangResult ModuleRecorder::precompileForTarget( - SlangCompileTarget target, - ISlangBlob** outDiagnostics) - { - // TODO: We should record this call - // https://github.com/shader-slang/slang/issues/4853 - slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); - SlangResult res = m_actualModule->precompileForTarget(target, outDiagnostics); - return res; - } - IEntryPointRecorder* ModuleRecorder::getEntryPointRecorder(slang::IEntryPoint* entryPoint) { IEntryPointRecorder* entryPointRecord = nullptr; diff --git a/source/slang-record-replay/record/slang-module.h b/source/slang-record-replay/record/slang-module.h index ce009eac8..2a22bd214 100644 --- a/source/slang-record-replay/record/slang-module.h +++ b/source/slang-record-replay/record/slang-module.h @@ -46,9 +46,6 @@ namespace SlangRecord virtual SLANG_NO_THROW SlangInt32 SLANG_MCALL getDependencyFileCount() override; virtual SLANG_NO_THROW char const* SLANG_MCALL getDependencyFilePath( SlangInt32 index) override; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL precompileForTarget( - SlangCompileTarget target, - ISlangBlob** outDiagnostics) override; // Interfaces for `IComponentType` virtual SLANG_NO_THROW slang::ISession* SLANG_MCALL getSession() override diff --git a/source/slang/slang-compiler-tu.cpp b/source/slang/slang-compiler-tu.cpp index 57a1133fc..8ae06a419 100644 --- a/source/slang/slang-compiler-tu.cpp +++ b/source/slang/slang-compiler-tu.cpp @@ -210,7 +210,87 @@ namespace Slang builder.setInsertInto(module); builder.emitEmbeddedDownstreamIR(targetReq->getTarget(), blob); + return SLANG_OK; + } + + SLANG_NO_THROW SlangResult SLANG_MCALL Module::getPrecompiledTargetCode( + SlangCompileTarget target, + slang::IBlob** outCode, + slang::IBlob** outDiagnostics) + { + SLANG_UNUSED(outDiagnostics); + for (auto globalInst : getIRModule()->getModuleInst()->getChildren()) + { + if (auto inst = as<IREmbeddedDownstreamIR>(globalInst)) + { + static_assert(CodeGenTarget::DXIL == static_cast<CodeGenTarget>(SLANG_DXIL)); + static_assert(CodeGenTarget::SPIRV == static_cast<CodeGenTarget>(SLANG_SPIRV)); + if (inst->getTarget() == static_cast<CodeGenTarget>(target)) + { + auto slice = inst->getBlob()->getStringSlice(); + auto blob = StringBlob::create(slice); + *outCode = blob.detach(); + return SLANG_OK; + } + } + } + return SLANG_FAIL; + } + + SLANG_NO_THROW SlangInt SLANG_MCALL Module::getModuleDependencyCount() + { + return 0; + } + + SLANG_NO_THROW SlangResult SLANG_MCALL Module::getModuleDependency( + SlangInt dependencyIndex, + IModule** outModule, + slang::IBlob** outDiagnostics) + { + SLANG_UNUSED(dependencyIndex); + SLANG_UNUSED(outModule); + SLANG_UNUSED(outDiagnostics); + return SLANG_OK; + } + // ComponentType + + SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::precompileForTarget( + SlangCompileTarget target, + slang::IBlob** outDiagnostics) + { + SLANG_UNUSED(target); + SLANG_UNUSED(outDiagnostics); + return SLANG_FAIL; + } + + SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getPrecompiledTargetCode( + SlangCompileTarget target, + slang::IBlob** outCode, + slang::IBlob** outDiagnostics) + { + SLANG_UNUSED(target); + SLANG_UNUSED(outCode); + SLANG_UNUSED(outDiagnostics); + return SLANG_FAIL; + } + + SLANG_NO_THROW SlangInt SLANG_MCALL ComponentType::getModuleDependencyCount() + { + return getModuleDependencies().getCount(); + } + + SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getModuleDependency( + SlangInt dependencyIndex, + slang::IModule** outModule, + slang::IBlob** outDiagnostics) + { + SLANG_UNUSED(outDiagnostics); + if (dependencyIndex < 0 || dependencyIndex >= getModuleDependencies().getCount()) + { + return SLANG_E_INVALID_ARG; + } + *outModule = getModuleDependencies()[dependencyIndex]; return SLANG_OK; } } diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 17501163f..7271c2e19 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -294,7 +294,7 @@ namespace Slang /// Base class for "component types" that represent the pieces a final /// shader program gets linked together from. /// - class ComponentType : public RefObject, public slang::IComponentType + class ComponentType : public RefObject, public slang::IComponentType, public slang::IModulePrecompileService_Experimental { public: // @@ -370,6 +370,27 @@ namespace Slang slang::CompilerOptionEntry* entries, ISlangBlob** outDiagnostics) override; + + // + // slang::IModulePrecompileService interface + // + SLANG_NO_THROW SlangResult SLANG_MCALL precompileForTarget( + SlangCompileTarget target, + slang::IBlob** outDiagnostics) SLANG_OVERRIDE; + + SLANG_NO_THROW SlangResult SLANG_MCALL getPrecompiledTargetCode( + SlangCompileTarget target, + slang::IBlob** outCode, + slang::IBlob** outDiagnostics = nullptr) SLANG_OVERRIDE; + + SLANG_NO_THROW SlangInt SLANG_MCALL getModuleDependencyCount() + SLANG_OVERRIDE; + + SLANG_NO_THROW SlangResult SLANG_MCALL getModuleDependency( + SlangInt dependencyIndex, + slang::IModule** outModule, + slang::IBlob** outDiagnostics = nullptr) SLANG_OVERRIDE; + CompilerOptionSet& getOptionSet() { return m_optionSet; } /// Get the linkage (aka "session" in the public API) for this component type. @@ -1550,11 +1571,26 @@ namespace Slang virtual SLANG_NO_THROW char const* SLANG_MCALL getDependencyFilePath( SlangInt32 index) override; + + // IModulePrecompileService_Experimental /// Precompile TU to target language virtual SLANG_NO_THROW SlangResult SLANG_MCALL precompileForTarget( SlangCompileTarget target, slang::IBlob** outDiagnostics) override; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPrecompiledTargetCode( + SlangCompileTarget target, + slang::IBlob** outCode, + slang::IBlob** outDiagnostics = nullptr) override; + + virtual SLANG_NO_THROW SlangInt SLANG_MCALL getModuleDependencyCount() + SLANG_OVERRIDE; + + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getModuleDependency( + SlangInt dependencyIndex, + slang::IModule** outModule, + slang::IBlob** outDiagnostics = nullptr) SLANG_OVERRIDE; + virtual void buildHash(DigestBuilder<SHA1>& builder) SLANG_OVERRIDE; virtual slang::DeclReflection* getModuleReflection() SLANG_OVERRIDE; diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index c9717272b..d0fe28185 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -4284,6 +4284,8 @@ ISlangUnknown* Module::getInterface(const Guid& guid) { if(guid == IModule::getTypeGuid()) return asExternal(this); + if (guid == IModulePrecompileService_Experimental::getTypeGuid()) + return static_cast<slang::IModulePrecompileService_Experimental*>(this); return Super::getInterface(guid); } @@ -4500,6 +4502,8 @@ ISlangUnknown* ComponentType::getInterface(Guid const& guid) { return static_cast<slang::IComponentType*>(this); } + if(guid == IModulePrecompileService_Experimental::getTypeGuid()) + return static_cast<slang::IModulePrecompileService_Experimental*>(this); return nullptr; } diff --git a/tests/library/linked.spirv b/tests/library/linked.spirv Binary files differnew file mode 100644 index 000000000..7ea385e71 --- /dev/null +++ b/tests/library/linked.spirv diff --git a/tools/gfx-unit-test/precompiled-module-2.cpp b/tools/gfx-unit-test/precompiled-module-2.cpp index e8ceb6f45..f997b2a7b 100644 --- a/tools/gfx-unit-test/precompiled-module-2.cpp +++ b/tools/gfx-unit-test/precompiled-module-2.cpp @@ -29,9 +29,12 @@ namespace gfx_test auto globalSession = slangSession->getGlobalSession(); globalSession->createSession(sessionDesc, slangSession.writeRef()); - Slang::ComPtr<slang::IBlob> diagnosticsBlob; - slang::IModule* module = slangSession->loadModule(shaderModuleName, diagnosticsBlob.writeRef()); - diagnoseIfNeeded(diagnosticsBlob); + slang::IModule* module; + { + Slang::ComPtr<slang::IBlob> diagnosticsBlob; + module = slangSession->loadModule(shaderModuleName, diagnosticsBlob.writeRef()); + diagnoseIfNeeded(diagnosticsBlob); + } if (!module) return SLANG_FAIL; @@ -49,7 +52,14 @@ namespace gfx_test default: return SLANG_FAIL; } - module->precompileForTarget(target, diagnosticsBlob.writeRef()); + + ComPtr<slang::IModulePrecompileService_Experimental> precompileService; + if (module->queryInterface(slang::SLANG_UUID_IModulePrecompileService_Experimental, (void**)precompileService.writeRef()) == SLANG_OK) + { + Slang::ComPtr<slang::IBlob> diagnosticsBlob; + precompileService->precompileForTarget(target, diagnosticsBlob.writeRef()); + diagnoseIfNeeded(diagnosticsBlob); + } } // Write loaded modules to memory file system. |
