diff options
| author | cheneym2 <acheney@nvidia.com> | 2024-08-05 15:37:46 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-05 15:37:46 -0400 |
| commit | d72f9f6f72a7a74d7466a1e301e1853fea5daa25 (patch) | |
| tree | 4ae77e2dd622779b64d063d1f50fc7af8c13a94a /source/slang/slang-compiler.cpp | |
| parent | d63f5e20f1edf7c51ca5c456baceb9eb9a84c95b (diff) | |
Initial support for precompiled DXIL in slang-modules (#4755)
* Add embedded precompiled binary IR ops
Add IR operations to embed precompiled DXIL or SPIR-V blobs
into IR. Adds a BlobLit literal that is mostly identical to
StringLit except for its inability to be displayed, e.g.
in dumped IR. In the future, the blob might be dumped as
hexadecimal, but for now it is summarized as "<binary blob>".
* EmbeddedDXIL and SPIR-V options
The options, '-embed-dxil' and '-embed-spirv' in slangc, will
cause a target dxil or spirv to be compiled and stored in the
translation unit IR when written to a slang-module. Subsequent
changes actually implement the options.
* Per-translation unit DXIL precompilation
When -embed-dxil is specified, perform a precompilation to DXIL of
each TU, linked only with stdlib. Embed the resulting DXIL for
the TU in a IR op. Being part of IR, the precompiled DXIL can be
serialized to disk in a slang-module.
Upon loading slang-modules, the new IR op will be searched for and
the precompiled DXIL blob is saved with the loaded Module. During
linking, if all the Modules have precompiled blobs they will be
sent to the downstream compile commands as libraries instead of
source, skipping the downstream compilation, using DXC only for
linking.
Fixes Issue #4580
* Remove placeholder embedded SPIRV support
Code was added only to sketch out how other precompiled bins
will be supported.
* Remove the rest of the SPIRV placeholder support
* Fix warnings, test error on non-windows
* Remove lib_6_6 hack, add dxil_lib capability
* Allocate blob value from irmodule memarena
* Add null check after memarena allocation
* Restore the request->e2erequest code path for generatewholeprogram
* Update capability handling, move EmbedDXIL enum to end to preserve abi
* Remove lib_6_6 hack
* Move ICompileRequest functions to end
Diffstat (limited to 'source/slang/slang-compiler.cpp')
| -rw-r--r-- | source/slang/slang-compiler.cpp | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 912e42572..1ef17df1d 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -762,6 +762,11 @@ namespace Slang # pragma warning(pop) #endif + SlangResult CodeGenContext::emitTranslationUnit(ComPtr<IArtifact>& outArtifact) + { + return emitWithDownstreamForEntryPoints(outArtifact); + } + String GetHLSLProfileName(Profile profile) { switch( profile.getFamily() ) @@ -1084,6 +1089,23 @@ namespace Slang return SLANG_OK; } + bool CodeGenContext::isPrecompiled() + { + auto program = getProgram(); + + bool allPrecompiled = true; + program->enumerateIRModules([&](IRModule* irModule) + { + // TODO: Conditionalize this on target + if (!irModule->precompiledDXIL) + { + allPrecompiled = false; + } + }); + + return allPrecompiled; + } + SlangResult CodeGenContext::emitWithDownstreamForEntryPoints(ComPtr<IArtifact>& outArtifact) { outArtifact.setNull(); @@ -1245,12 +1267,15 @@ namespace Slang } else { - CodeGenContext sourceCodeGenContext(this, sourceTarget, extensionTracker); + if (!isPrecompiled()) + { + CodeGenContext sourceCodeGenContext(this, sourceTarget, extensionTracker); - SLANG_RETURN_ON_FAIL(sourceCodeGenContext.emitEntryPointsSource(sourceArtifact)); - sourceCodeGenContext.maybeDumpIntermediate(sourceArtifact); + SLANG_RETURN_ON_FAIL(sourceCodeGenContext.emitEntryPointsSource(sourceArtifact)); + sourceCodeGenContext.maybeDumpIntermediate(sourceArtifact); - sourceLanguage = (SourceLanguage)TypeConvertUtil::getSourceLanguageFromTarget((SlangCompileTarget)sourceTarget); + sourceLanguage = (SourceLanguage)TypeConvertUtil::getSourceLanguageFromTarget((SlangCompileTarget)sourceTarget); + } } if (sourceArtifact) @@ -1541,6 +1566,25 @@ namespace Slang libraries.addRange(linkage->m_libModules.getBuffer(), linkage->m_libModules.getCount()); } + if (isPrecompiled()) + { + auto program = getProgram(); + program->enumerateIRModules([&](IRModule* irModule) + { + // TODO: conditionalize on target + if (irModule->precompiledDXIL) + { + ArtifactDesc desc = ArtifactDescUtil::makeDescForCompileTarget(SLANG_DXIL); + desc.kind = ArtifactKind::Library; + + auto library = ArtifactUtil::createArtifact(desc); + + library->addRepresentationUnknown(irModule->precompiledDXIL); + libraries.add(library); + } + }); + } + options.compilerSpecificArguments = allocator.allocate(compilerSpecificArguments); options.requiredCapabilityVersions = SliceUtil::asSlice(requiredCapabilityVersions); options.libraries = SliceUtil::asSlice(libraries); @@ -1991,7 +2035,10 @@ namespace Slang { if (auto artifact = targetProgram->getExistingWholeProgramResult()) { - artifacts.add(ComPtr<IArtifact>(artifact)); + if (!targetProgram->getOptionSet().getBoolOption(CompilerOptionName::EmbedDXIL)) + { + artifacts.add(ComPtr<IArtifact>(artifact)); + } } } else @@ -2251,7 +2298,7 @@ namespace Slang void EndToEndCompileRequest::generateOutput() { generateOutput(getSpecializedGlobalAndEntryPointsComponentType()); - + // If we are in command-line mode, we might be expected to actually // write output to one or more files here. |
