summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-compiler-tu.cpp
diff options
context:
space:
mode:
authorcheneym2 <acheney@nvidia.com>2024-10-04 10:20:57 -0400
committerGitHub <noreply@github.com>2024-10-04 10:20:57 -0400
commitf521c2002e6b664944c6c39bab767dca1802887a (patch)
tree7fb24ff7940a4cdee91f661e607278b4ba530944 /source/slang/slang-compiler-tu.cpp
parent25c17b9fcbf7a21e9fa19c4a8f08b0406437be24 (diff)
Add interfaces for retrieving separate linkable downstream binaries (#5128)
* Implement separate downstream library interface Create a new com interface to house the methods for precompiling slang modules to target code. Add methods to count dependent modules and scrape them for downstream target binaries such that the downstream target binaries are linkabe outside of slang, e.g. via spirv-link or dxc. Fixes #5147 * Rename to _Experimental Clearly identify this as an interface subject to change.
Diffstat (limited to 'source/slang/slang-compiler-tu.cpp')
-rw-r--r--source/slang/slang-compiler-tu.cpp80
1 files changed, 80 insertions, 0 deletions
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;
}
}