diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-10-30 17:28:55 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-30 17:28:55 -0400 |
| commit | 72f86c8273b196d204213f02e73ba772201f903d (patch) | |
| tree | 914f750180e75c6d549bf0be80e9877f4f35c8ed /source/slang/slang-compiler.cpp | |
| parent | 066bc37f34ab4f72edef2b71fab50b45c3bb627e (diff) | |
WIP: Simple separate IR module linkage working (#1100)
* Added RiffReadHelper
* Move type to fourCC in Chunk simplifies some code.
* Make MemoryArena able to track external blocks.
Allow ownership of Data to vary.
Changed IR serialization to use moved allocations to avoid copies.
As it turns out all of the array writes could use unowned data, but doing so requires the IRData to stay in scope longer than IRSerialData, which it does at the moment - but perhaps needs better naming or a control for the feature.
* Write out slang-module container.
* WIP on -r option.
Loading modules - with -r.
* Making the serialized-module run (without using imported module).
* Split compiling module from the test.
* Separate module compilation with a function working.
* Remove serialization test as not used.
* Fix warning on gcc.
* Updated test to have types across module boundary.
Diffstat (limited to 'source/slang/slang-compiler.cpp')
| -rw-r--r-- | source/slang/slang-compiler.cpp | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 87a5e01a8..705b4ed59 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -5,6 +5,7 @@ #include "../core/slang-io.h" #include "../core/slang-string-util.h" #include "../core/slang-hex-dump-util.h" +#include "../core/slang-riff.h" #include "slang-check.h" #include "slang-compiler.h" @@ -18,6 +19,8 @@ #include "slang-reflection.h" #include "slang-emit.h" +#include "slang-ir-serialize.h" + // Enable calling through to `fxc` or `dxc` to // generate code on Windows. #ifdef _WIN32 @@ -2187,38 +2190,64 @@ SlangResult dissassembleDXILUsingDXC( EndToEndCompileRequest* endToEndReq, Stream* stream) { - SLANG_UNUSED(stream); + RiffContainer container; - auto linkage = endToEndReq->getLinkage(); - auto sink = endToEndReq->getSink(); - auto frontEndReq = endToEndReq->getFrontEndReq(); + // TODO(JS): We may want a switch to control is we use compression and/or we may just want compressed by default. + // For now uncompressed is fine. + const auto compressionType = IRSerialBinary::CompressionType::None; - for (auto translationUnit : frontEndReq->translationUnits) { - auto module = translationUnit->module; - auto irModule = module->getIRModule(); + // Module list + RiffContainer::ScopeChunk listScope(&container, RiffContainer::Chunk::Kind::List, IRSerialBinary::kSlangModuleListFourCc); - SLANG_UNUSED(irModule); + auto linkage = endToEndReq->getLinkage(); + auto sink = endToEndReq->getSink(); + auto frontEndReq = endToEndReq->getFrontEndReq(); - // Okay, we need to serialize this module to our container file, - // including both its name and generated IR code. - } + IRSerialWriter::OptionFlags optionFlags = 0; - auto program = endToEndReq->getSpecializedGlobalAndEntryPointsComponentType(); + if (linkage->debugInfoLevel != DebugInfoLevel::None) + { + optionFlags |= IRSerialWriter::OptionFlag::DebugInfo; + } - + SourceManager* sourceManager = frontEndReq->getSourceManager(); - // TODO: in the case where we have specialization, we might need - // to serialize IR related to `program`... + for (auto translationUnit : frontEndReq->translationUnits) + { + auto module = translationUnit->module; + auto irModule = module->getIRModule(); - for (auto target : linkage->targets) - { - auto targetProgram = program->getTargetProgram(target); - auto irModule = targetProgram->getOrCreateIRModuleForLayout(sink); + // Okay, we need to serialize this module to our container file. + // We currently don't serialize it's name..., but support for that could be added. - // Okay, we need to serialize this target program and its IR too... + IRSerialData serialData; + IRSerialWriter writer; + SLANG_RETURN_ON_FAIL(writer.write(irModule, sourceManager, optionFlags, &serialData)); + SLANG_RETURN_ON_FAIL(IRSerialWriter::writeContainer(serialData, compressionType, &container)); + } + + auto program = endToEndReq->getSpecializedGlobalAndEntryPointsComponentType(); + + // TODO: in the case where we have specialization, we might need + // to serialize IR related to `program`... + + for (auto target : linkage->targets) + { + auto targetProgram = program->getTargetProgram(target); + auto irModule = targetProgram->getOrCreateIRModuleForLayout(sink); + + // Okay, we need to serialize this target program and its IR too... + IRSerialData serialData; + IRSerialWriter writer; + SLANG_RETURN_ON_FAIL(writer.write(irModule, sourceManager, optionFlags, &serialData)); + SLANG_RETURN_ON_FAIL(IRSerialWriter::writeContainer(serialData, compressionType, &container)); + } } + // We now write the RiffContainer to the stream + SLANG_RETURN_ON_FAIL(RiffUtil::write(container.getRoot(), true, stream)); + return SLANG_OK; } |
