summaryrefslogtreecommitdiff
path: root/source/slang/slang-state-serialize.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-10-23 09:28:58 -0400
committerGitHub <noreply@github.com>2019-10-23 09:28:58 -0400
commit9c2d1766ea33101b551ac521ddc39516b98b6641 (patch)
treefeee466c977575ebcb15b9057a59c2efce5d9ae1 /source/slang/slang-state-serialize.cpp
parent6a7f4c9cef766e538a808a8f03411af2f10106e1 (diff)
Expose more repro in API, support output params. (#1087)
* Added spEnableReproCapture to the API. * Added MemoryStreamBase - which can be used to read from without copyin the data. Added the missing Repro API functions - spEnableReproCapture and spExtractRepro. Added support for serializing output filenames. * Improved naming around Stream. Brought Stream and sub types closer to code conventions. * Renamed content -> contents in Stream.
Diffstat (limited to 'source/slang/slang-state-serialize.cpp')
-rw-r--r--source/slang/slang-state-serialize.cpp102
1 files changed, 85 insertions, 17 deletions
diff --git a/source/slang/slang-state-serialize.cpp b/source/slang/slang-state-serialize.cpp
index b37529121..110ea52b2 100644
--- a/source/slang/slang-state-serialize.cpp
+++ b/source/slang/slang-state-serialize.cpp
@@ -318,15 +318,49 @@ static bool _isStorable(const PathInfo::Type type)
for (Index i = 0; i < linkage->targets.getCount(); ++i)
{
- auto& dst = dstTargets[i];
- TargetRequest* targetRequest = linkage->targets[i];
+ TargetRequest* srcTargetRequest = linkage->targets[i];
- dst.target = targetRequest->getTarget();
- dst.profile = targetRequest->getTargetProfile();
- dst.targetFlags = targetRequest->targetFlags;
- dst.floatingPointMode = targetRequest->floatingPointMode;
- }
+ // Copy the simple stuff
+ {
+ auto& dst = dstTargets[i];
+ dst.target = srcTargetRequest->getTarget();
+ dst.profile = srcTargetRequest->getTargetProfile();
+ dst.targetFlags = srcTargetRequest->targetFlags;
+ dst.floatingPointMode = srcTargetRequest->floatingPointMode;
+ }
+
+ // Copy the entry point/target output names
+ {
+ const auto& srcTargetInfos = request->targetInfos;
+
+ if (RefPtr<EndToEndCompileRequest::TargetInfo>* infosPtr = srcTargetInfos.TryGetValue(srcTargetRequest))
+ {
+ EndToEndCompileRequest::TargetInfo* infos = *infosPtr;
+
+ const auto& entryPointOutputPaths = infos->entryPointOutputPaths;
+
+ Safe32Array<OutputState> dstOutputStates;
+ dstOutputStates = inOutContainer.allocateArray<OutputState>(entryPointOutputPaths.Count());
+ Index index = 0;
+ for (const auto& pair : entryPointOutputPaths)
+ {
+ Safe32Ptr<RelativeString> outputPath = inOutContainer.newString(pair.Value.getUnownedSlice());
+
+ auto& dstOutputState = dstOutputStates[index];
+
+ dstOutputState.entryPointIndex = int32_t(pair.Key);
+ dstOutputState.outputPath = outputPath;
+
+ index++;
+ }
+
+ dstTargets[i].outputStates = dstOutputStates;
+ }
+ }
+ }
+
+ // Save the result
requestState->targetRequests = dstTargets;
}
@@ -383,7 +417,12 @@ static bool _isStorable(const PathInfo::Type type)
// Find files from the file system, and mapping paths to files
{
- CacheFileSystem* cacheFileSystem = linkage->cacheFileSystem;
+ CacheFileSystem* cacheFileSystem = linkage->getCacheFileSystem();
+ if (!cacheFileSystem)
+ {
+ return SLANG_FAIL;
+ }
+
// Traverse the references (in process we will construct the map from PathInfo)
{
const auto& srcFiles = cacheFileSystem->getPathMap();
@@ -651,8 +690,17 @@ static void _loadDefines(const Relative32Array<StateSerializeUtil::StringPair>&
{
auto externalRequest = asExternal(request);
+
auto linkage = request->getLinkage();
+ // TODO(JS): Really should be more exhaustive here, and set up to initial state ideally
+ // Reset state
+ {
+ request->targetInfos.Clear();
+ // Remove any requests
+ linkage->targets.clear();
+ }
+
LoadContext context(linkage->getSourceManager(), fileSystem);
// Try to set state through API - as doing so means if state stored in multiple places it will be ok
@@ -671,20 +719,41 @@ static void _loadDefines(const Relative32Array<StateSerializeUtil::StringPair>&
linkage->setMatrixLayoutMode(requestState->defaultMatrixLayoutMode);
}
+
+ // Add the target requests
{
for (Index i = 0; i < requestState->targetRequests.getCount(); ++i)
{
TargetRequestState& src = requestState->targetRequests[i];
int index = spAddCodeGenTarget(externalRequest, SlangCompileTarget(src.target));
- SLANG_UNUSED(index);
SLANG_ASSERT(index == i);
- auto dstTarget = linkage->targets[i];
+ auto dstTarget = linkage->targets[index];
SLANG_ASSERT(dstTarget->getTarget() == src.target);
dstTarget->targetProfile = src.profile;
dstTarget->targetFlags = src.targetFlags;
dstTarget->floatingPointMode = src.floatingPointMode;
+
+ // If there is output state (like output filenames) add here
+ if (src.outputStates.getCount())
+ {
+ RefPtr<EndToEndCompileRequest::TargetInfo> dstTargetInfo(new EndToEndCompileRequest::TargetInfo);
+ request->targetInfos[dstTarget] = dstTargetInfo;
+
+ for (const auto& srcOutputState : src.outputStates)
+ {
+ SLANG_ASSERT(srcOutputState.entryPointIndex < requestState->entryPoints.getCount());
+
+ String entryPointPath;
+ if (srcOutputState.outputPath)
+ {
+ entryPointPath = srcOutputState.outputPath->getSlice();
+ }
+
+ dstTargetInfo->entryPointOutputPaths.Add(srcOutputState.entryPointIndex, entryPointPath);
+ }
+ }
}
}
@@ -744,6 +813,9 @@ static void _loadDefines(const Relative32Array<StateSerializeUtil::StringPair>&
// Entry points
{
+ // Check there aren't any set entry point
+ SLANG_ASSERT(request->getFrontEndReq()->m_entryPointReqs.getCount() == 0);
+
for (const auto& srcEntryPoint : requestState->entryPoints)
{
const char* name = srcEntryPoint.name ? srcEntryPoint.name->getCstr() : nullptr;
@@ -782,8 +854,8 @@ static void _loadDefines(const Relative32Array<StateSerializeUtil::StringPair>&
// This is a bit of a hack, we are going to replace the file system, with our one which is filled in
// with what was read from the file.
- linkage->fileSystemExt = cacheFileSystem;
- linkage->cacheFileSystem = cacheFileSystem;
+ linkage->m_fileSystemExt = cacheFileSystem;
+ linkage->m_cacheFileSystem = cacheFileSystem;
}
return SLANG_OK;
@@ -834,11 +906,7 @@ static void _loadDefines(const Relative32Array<StateSerializeUtil::StringPair>&
/* static */SlangResult StateSerializeUtil::loadState(const uint8_t* data, size_t size, List<uint8_t>& outBuffer)
{
- MemoryStream stream(FileAccess::Read);
-
- stream.m_contents.setCount(size);
- ::memcpy(stream.m_contents.getBuffer(), data, size);
-
+ MemoryStreamBase stream(FileAccess::Read, data, size);
return loadState(&stream, outBuffer);
}