summaryrefslogtreecommitdiff
path: root/tools/gfx/persistent-shader-cache.h
diff options
context:
space:
mode:
authorskallweitNV <64953474+skallweitNV@users.noreply.github.com>2022-12-12 19:25:48 +0100
committerGitHub <noreply@github.com>2022-12-12 10:25:48 -0800
commitc2dc1a86ed2f5e160749fe9f99b70db6c3e4d7a6 (patch)
treeea65b9635d892917a2420688a27c38537c4758be /tools/gfx/persistent-shader-cache.h
parent8d359fc6133fa49d2d3b7f8bb4b37916e719c344 (diff)
Refactor shader cache (#2558)
* Fix a bug in Path::find * Fix code formatting * Fix LockFile and add LockFileGuard * Add PersistentCache and unit test * Replace file path dependency list with source file dependency list * Add note on ordering in Module/FileDependencyList * Remove old shader cache code * Refactor shader cache implementation * Temporarily skip unit tests reading/writing files * Fix warning * Reenable lock file test * Rename shader cache tests and disable crashing test * Testing * Stop using Path::getCanonical * Fix persistent cache lock and test * Fix threading issues * Move adding file dependency hashes to getEntryPointHash() * Fix handling of #include files * Allow specifying additional search paths for gfx testing device * Work on shader cache tests * Update project files * Revive shader cache graphics tests * Split graphics pipeline test * Fix compilation
Diffstat (limited to 'tools/gfx/persistent-shader-cache.h')
-rw-r--r--tools/gfx/persistent-shader-cache.h99
1 files changed, 0 insertions, 99 deletions
diff --git a/tools/gfx/persistent-shader-cache.h b/tools/gfx/persistent-shader-cache.h
deleted file mode 100644
index 530d50a58..000000000
--- a/tools/gfx/persistent-shader-cache.h
+++ /dev/null
@@ -1,99 +0,0 @@
-// slang-shader-cache-index.h
-#pragma once
-#include "../../slang.h"
-#include "../../slang-gfx.h"
-#include "../../slang-com-ptr.h"
-
-#include "../../source/core/slang-string.h"
-#include "../../source/core/slang-dictionary.h"
-#include "../../source/core/slang-linked-list.h"
-#include "../../source/core/slang-stream.h"
-#include "../../source/core/slang-crypto.h"
-
-namespace gfx
-{
-
-using namespace Slang;
-
-using DigestType = MD5::Digest;
-
-struct ShaderCacheEntry
-{
- DigestType dependencyBasedDigest;
- DigestType contentsBasedDigest;
- double lastAccessedTime;
-
- bool operator==(const ShaderCacheEntry& rhs)
- {
- return dependencyBasedDigest == rhs.dependencyBasedDigest
- && contentsBasedDigest == rhs.contentsBasedDigest
- && lastAccessedTime == rhs.lastAccessedTime;
- }
-
- uint32_t getHashCode()
- {
- return dependencyBasedDigest.getHashCode();
- }
-};
-
-class PersistentShaderCache : public RefObject
-{
-public:
- PersistentShaderCache(const IDevice::ShaderCacheDesc& inDesc);
- ~PersistentShaderCache();
-
- // Fetch the cache entry corresponding to the provided key. If found, move the entry to
- // the front of entries and return the entry and the corresponding compiled code in
- // outCompiledCode. Else, return nullptr.
- ShaderCacheEntry* findEntry(const DigestType& key, ISlangBlob** outCompiledCode);
-
- // 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 DigestType& dependencyDigest, const DigestType& contentsDigest, ISlangBlob* compiledCode);
-
- // Update the contents hash for the specified entry in the cache and update the
- // corresponding file on disk.
- void updateEntry(const DigestType& dependencyDigest, const DigestType& contentsDigest, ISlangBlob* updatedCode);
-
-private:
- // Load a previous cache index saved to disk. If not found, create a new cache index
- // and save it to disk as filename.
- void loadCacheFromFile();
-
- // Delete the last entry (the least recently used) from entries, remove its key/value pair
- // from keyToEntry, and remove the corresponding file on disk. Returns the index in 'entries'
- // of the removed entry so addEntry() can overwrite the corresponding entry in 'entries'
- // with the new entry. This should only be called by addEntry() when the cache reaches maximum capacity.
- Index deleteLRUEntry();
-
- // Without access to a physical file path, in-memory file systems cannot leverage file streams and
- // need to fall back on a different implementation for loading and saving the cache to memory.
- void loadCacheFromMemory();
- void saveCacheToMemory();
-
- // The shader cache's description.
- IDevice::ShaderCacheDesc desc;
-
- // The underlying file system used for the shader cache.
- ComPtr<ISlangMutableFileSystem> mutableShaderCacheFileSystem = nullptr;
- bool isMemoryFileSystem = false;
-
- // A file stream to the index file opened during cache load. This will only
- // exist for a cache that exists on-disk.
- FileStream indexStream;
-
- // Dictionary mapping each shader's key to its corresponding node (entry) in the
- // linked list 'orderedEntries'.
- Dictionary<DigestType, LinkedNode<Index>*> keyToEntry;
-
- // Linked list containing the corresponding indices in 'entries' for entries in the
- // shader cache ordered from most to least recently used.
- LinkedList<Index> orderedEntries;
-
- // List of entries in the shader cache. This list is not guaranteed to be in order of recency
- // as the main and fall back implementations handle outputting to the file differently.
- List<ShaderCacheEntry> entries;
-};
-
-}