1 // 2 // Copyright 2022 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // MemoryShaderCache: Stores compiled shaders in memory so they don't 7 // always have to be re-compiled. Can be used in conjunction with the platform 8 // layer to warm up the cache from disk. 9 10 #ifndef LIBANGLE_MEMORY_SHADER_CACHE_H_ 11 #define LIBANGLE_MEMORY_SHADER_CACHE_H_ 12 13 #include <array> 14 15 #include "GLSLANG/ShaderLang.h" 16 #include "common/MemoryBuffer.h" 17 #include "libANGLE/BlobCache.h" 18 #include "libANGLE/Error.h" 19 20 namespace gl 21 { 22 class Context; 23 class Shader; 24 class ShaderState; 25 class ShCompilerInstance; 26 27 class MemoryShaderCache final : angle::NonCopyable 28 { 29 public: 30 explicit MemoryShaderCache(egl::BlobCache &blobCache); 31 ~MemoryShaderCache(); 32 33 // Helper method that serializes a shader. 34 angle::Result putShader(const Context *context, 35 const egl::BlobCache::Key &shaderHash, 36 const Shader *shader); 37 38 // Check the cache, and deserialize and load the shader if found. Evict existing hash if load 39 // fails. 40 egl::CacheGetResult getShader(const Context *context, 41 Shader *shader, 42 const egl::BlobCache::Key &shaderHash, 43 angle::JobResultExpectancy resultExpectancy); 44 45 // Empty the cache. 46 void clear(); 47 48 // Returns the maximum cache size in bytes. 49 size_t maxSize() const; 50 51 private: 52 egl::BlobCache &mBlobCache; 53 }; 54 55 } // namespace gl 56 57 #endif // LIBANGLE_MEMORY_SHADER_CACHE_H_ 58