summaryrefslogtreecommitdiffstats
path: root/tools/gfx/persistent-shader-cache.cpp
diff options
context:
space:
mode:
authorlucy96chen <47800040+lucy96chen@users.noreply.github.com>2022-10-19 09:36:41 -0700
committerGitHub <noreply@github.com>2022-10-19 09:36:41 -0700
commitdec930150f42a22892e567c769a1c9e24e761fde (patch)
tree92eea81e0c5d08c2c5ff090e7ebb0c2030648912 /tools/gfx/persistent-shader-cache.cpp
parent8add41a6e37994577d928bc312801ddfa1c33173 (diff)
PersistentShaderCache integration (#2453)
* Shader cache index integrated into RendererBase; Added test for cache eviction policy (which currently does not pass) * Restructured main if block in getEntryPointCodeFromShaderCache; Post-rebase cleanup * undo local testing only change * Fixed issues causing shader cache tests to fail * Edited gfx.slang to reflect structural changes to IDevice::Desc and to include ShaderCacheDesc; Modified how the cache is reading in the file from disk; Added a check to the cache eviction policy test that checks for correct order of entries in the cache as well as eight total expected output files for D3D12 and Vulkan * Removed line in gfx-unit-test.cpp for local testing * Edited .gitignore to ignore all shaders automatically generated by the shader cache tests and removed the test shaders that were previously added; Review changes, most notably with an overhaul of how the cache eviction policy test handles checking order of entries * Ran premake; Removed local testing specific line (again) * Removed expected comparison files from earlier commit; Ran premake * Edited premake5.lua to also ignore the auto-generated shader files from specific shader cache tests * Fixed weird indent in premake5.lua
Diffstat (limited to 'tools/gfx/persistent-shader-cache.cpp')
-rw-r--r--tools/gfx/persistent-shader-cache.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/tools/gfx/persistent-shader-cache.cpp b/tools/gfx/persistent-shader-cache.cpp
index a378e0f4f..55a95a257 100644
--- a/tools/gfx/persistent-shader-cache.cpp
+++ b/tools/gfx/persistent-shader-cache.cpp
@@ -6,14 +6,15 @@
#include "../../source/core/slang-string-util.h"
#include "../../source/core/slang-file-system.h"
-namespace Slang
+namespace gfx
{
-PersistentShaderCache::PersistentShaderCache(const Desc& inDesc)
+PersistentShaderCache::PersistentShaderCache(const IDevice::ShaderCacheDesc& inDesc)
{
desc = inDesc;
- if (!desc.shaderCachePath.getBuffer())
+ // If a path is provided, we will want our underlying file system to be initialized using that path.
+ if (desc.shaderCachePath)
{
if (!desc.shaderCacheFileSystem)
{
@@ -25,7 +26,7 @@ PersistentShaderCache::PersistentShaderCache(const Desc& inDesc)
}
// If our shader cache has an underlying file system, check if it's mutable. If so, store a pointer
- // to the mutable version in order to save new entries later.
+ // to the mutable version for operations which require writing to disk.
if (desc.shaderCacheFileSystem)
{
desc.shaderCacheFileSystem->queryInterface(ISlangMutableFileSystem::getTypeGuid(), (void**)mutableShaderCacheFileSystem.writeRef());
@@ -39,27 +40,28 @@ PersistentShaderCache::PersistentShaderCache(const Desc& inDesc)
void PersistentShaderCache::loadCacheFromFile()
{
ComPtr<ISlangBlob> indexBlob;
- if (SLANG_FAILED(desc.shaderCacheFileSystem->loadFile(desc.cacheFilename.getBuffer(), indexBlob.writeRef())))
+ if (SLANG_FAILED(desc.shaderCacheFileSystem->loadFile(desc.cacheFilename, indexBlob.writeRef())))
{
// Cache index not found, so we'll create and save a new one.
if (mutableShaderCacheFileSystem)
{
- mutableShaderCacheFileSystem->saveFile(desc.cacheFilename.getBuffer(), nullptr, 0);
+ mutableShaderCacheFileSystem->saveFile(desc.cacheFilename, nullptr, 0);
return;
}
// Cache index not found and we can't save a new one due to the file system being immutable.
return;
}
- String indexString;
- File::readAllText(desc.cacheFilename, indexString);
+ auto indexString = UnownedStringSlice((char*)indexBlob->getBufferPointer());
List<UnownedStringSlice> lines;
- StringUtil::calcLines(indexString.getUnownedSlice(), lines);
+ StringUtil::calcLines(indexString, lines);
for (auto line : lines)
{
List<UnownedStringSlice> digests;
- StringUtil::split(line, ' ', digests); // This will return our two hashes as two elements in digests.
+ StringUtil::split(line, ' ', digests); // This will return our two hashes as two elements in digests, unless we've reached the end.
+ if (digests.getCount() != 2)
+ continue;
auto dependencyDigest = DigestUtil::fromString(digests[0]);
auto astDigest = DigestUtil::fromString(digests[1]);
@@ -158,7 +160,7 @@ void PersistentShaderCache::saveCacheToFile()
indexSb << "\n";
}
- mutableShaderCacheFileSystem->saveFile(desc.cacheFilename.getBuffer(), indexSb.getBuffer(), indexSb.getLength());
+ mutableShaderCacheFileSystem->saveFile(desc.cacheFilename, indexSb.getBuffer(), indexSb.getLength());
}
void PersistentShaderCache::deleteLRUEntry()