Hash :
ba4b6913
Author :
Date :
2022-08-23T09:34:27
Fix data race in BlobCache * Re-enable shader cache feature * Improve BlobCache thread-safety test * Improve EGLProgramCacheControlTest to not check the size of the BlobCache, since the shader cache interferes with this. * Include the arguments to ConstructCompiler() and Compile() in the key hash for the shader cache. Bug: angleproject:7036 Change-Id: Ied4e11f9160552f2f9358d99b5656315239ba856 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3851161 Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Eddie Hatfield <eddiehatfield@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
//
// Copyright 2022 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// MemoryShaderCache: Stores compiled shaders in memory so they don't
// always have to be re-compiled. Can be used in conjunction with the platform
// layer to warm up the cache from disk.
#ifndef LIBANGLE_MEMORY_SHADER_CACHE_H_
#define LIBANGLE_MEMORY_SHADER_CACHE_H_
#include <array>
#include "GLSLANG/ShaderLang.h"
#include "common/MemoryBuffer.h"
#include "libANGLE/BlobCache.h"
#include "libANGLE/Error.h"
namespace gl
{
class Context;
class Shader;
class ShaderState;
class ShCompilerInstance;
class MemoryShaderCache final : angle::NonCopyable
{
public:
explicit MemoryShaderCache(egl::BlobCache &blobCache);
~MemoryShaderCache();
// Helper method that serializes a shader.
angle::Result putShader(const Context *context,
const egl::BlobCache::Key &shaderHash,
const Shader *shader);
// Check the cache, and deserialize and load the shader if found. Evict existing hash if load
// fails.
angle::Result getShader(const Context *context,
Shader *shader,
const ShCompileOptions &compileOptions,
const ShCompilerInstance &compilerInstance,
egl::BlobCache::Key *hashOut);
// Empty the cache.
void clear();
// Returns the maximum cache size in bytes.
size_t maxSize() const;
private:
egl::BlobCache &mBlobCache;
std::mutex mHistogramMutex;
};
} // namespace gl
#endif // LIBANGLE_MEMORY_SHADER_CACHE_H_