diff options
| -rw-r--r-- | build/visual-studio/slang/slang.vcxproj | 1 | ||||
| -rw-r--r-- | build/visual-studio/slang/slang.vcxproj.filters | 3 | ||||
| -rw-r--r-- | source/compiler-core/slang-dxc-compiler.cpp | 17 | ||||
| -rw-r--r-- | source/slang/slang-shader-cache-index.h | 60 |
4 files changed, 74 insertions, 7 deletions
diff --git a/build/visual-studio/slang/slang.vcxproj b/build/visual-studio/slang/slang.vcxproj index 4e8a9e70a..a6cf0846d 100644 --- a/build/visual-studio/slang/slang.vcxproj +++ b/build/visual-studio/slang/slang.vcxproj @@ -446,6 +446,7 @@ IF EXIST ..\..\..\external\slang-glslang\bin\windows-aarch64\release\slang-glsla <ClInclude Include="..\..\..\source\slang\slang-serialize-types.h" />
<ClInclude Include="..\..\..\source\slang\slang-serialize-value-type-info.h" />
<ClInclude Include="..\..\..\source\slang\slang-serialize.h" />
+ <ClInclude Include="..\..\..\source\slang\slang-shader-cache-index.h" />
<ClInclude Include="..\..\..\source\slang\slang-syntax.h" />
<ClInclude Include="..\..\..\source\slang\slang-type-layout.h" />
<ClInclude Include="..\..\..\source\slang\slang-type-system-shared.h" />
diff --git a/build/visual-studio/slang/slang.vcxproj.filters b/build/visual-studio/slang/slang.vcxproj.filters index 8e6763e15..ff315e0a7 100644 --- a/build/visual-studio/slang/slang.vcxproj.filters +++ b/build/visual-studio/slang/slang.vcxproj.filters @@ -471,6 +471,9 @@ <ClInclude Include="..\..\..\source\slang\slang-serialize.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\source\slang\slang-shader-cache-index.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="..\..\..\source\slang\slang-syntax.h">
<Filter>Header Files</Filter>
</ClInclude>
diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp index 6619d000c..52933eaa7 100644 --- a/source/compiler-core/slang-dxc-compiler.cpp +++ b/source/compiler-core/slang-dxc-compiler.cpp @@ -599,16 +599,19 @@ SlangResult DXCDownstreamCompiler::getVersionString(slang::IBlob** outVersionStr versionString.append("."); versionString.append(minor); - char* commitHash; + char* commitHash = nullptr; uint32_t unused; versionInfo2->GetCommitInfo(&unused, &commitHash); + if (commitHash) + { + // Successfully queried the commit hash, append to the version and return. + versionString.append(commitHash); + CoTaskMemFree(commitHash); - versionString.append(commitHash); - CoTaskMemFree(commitHash); - - version = StringBlob::create(versionString.getBuffer()); - *outVersionString = version.detach(); - return SLANG_OK; + version = StringBlob::create(versionString.getBuffer()); + *outVersionString = version.detach(); + return SLANG_OK; + } } } diff --git a/source/slang/slang-shader-cache-index.h b/source/slang/slang-shader-cache-index.h new file mode 100644 index 000000000..530aacf11 --- /dev/null +++ b/source/slang/slang-shader-cache-index.h @@ -0,0 +1,60 @@ +#pragma once +#include "../../slang.h" + +#include "../core/slang-string.h" +#include "../core/slang-linked-list.h" +#include "../core/slang-dictionary.h" + +namespace Slang +{ + class ShaderCacheIndex + { + public: + struct ShaderCacheEntry + { + slang::Digest dependencyBasedDigest; + slang::Digest astBasedDigest; + }; + + ShaderCacheIndex(SlangInt size) + : entryCountLimit(size) + {} + + // Load a previous cache index saved to disk. If not found, create a new cache index + // and save it to disk as filename. + SlangResult loadCacheIndexFromFile(String filename); + + // Fetch the cache entry corresponding to the provided key. If found, move the entry to + // the front of entries and return the entry. Else, return nullptr. + ShaderCacheEntry* findEntry(const slang::Digest& key); + + // Add an entry to the cache with the provided key and contents hashes. If + // adding an entry causes the cache to exceed size limitations, this will also + // delete the least recently used entry. + void addEntry(const slang::Digest& dependencyDigest, const slang::Digest& astDigest); + + // Update the contents hash for the specified entry in the cache and update the + // corresponding file on disk. + void updateEntry(const slang::Digest& dependencyDigest, const slang::Digest& astDigest); + + private: + // Update the cache index on disk. This should be called any time an entry changes. + SlangResult saveCacheIndexToFile(); + + // Delete the last entry from entries and remove its key/value pair from keyToContents + // as well as remove the corresponding file on disk. This should only be used when the + // cache has reached the size limit specified by entryLimit to create space for a new entry. + void deleteEntry(); + + // Dictionary mapping each shader's key to its corresponding node (entry) in the list + // of entries. + Dictionary<slang::Digest, LinkedNode<ShaderCacheEntry>*> keyToEntry; + + // Linked list containing the entries stored in the shader cache in order + // of most to least recently used. + LinkedList<ShaderCacheEntry> entries; + + // The maximum number of cache entries allowed. + SlangInt entryCountLimit = -1; + } +} |
