summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorlucy96chen <47800040+lucy96chen@users.noreply.github.com>2022-10-13 17:07:54 -0700
committerGitHub <noreply@github.com>2022-10-13 17:07:54 -0700
commit27d7961db15ed5890d2ad0eff1218e26dcdaf82c (patch)
treedea259ca9768bb94f8371f0bd113c0341eb01b6b /source
parente03026a07c4aa32c1a2de5ce199d910d74511c27 (diff)
Shader cache index header (#2448)
* checkpoint * Added shaderCachePath field to IDevice desc in gfx.slang, gfx-smoke.slang should be functional * ran premake * Revert erroneous commits from rebasing * Added ShaderCacheIndex class header with design details * Header edits * more header edits * Post-rebase premake.bat run to fix solution weirdness; Initialize commitHash to nullptr and check that a commitHash is successfully returned
Diffstat (limited to 'source')
-rw-r--r--source/compiler-core/slang-dxc-compiler.cpp17
-rw-r--r--source/slang/slang-shader-cache-index.h60
2 files changed, 70 insertions, 7 deletions
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;
+ }
+}