tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MemoryShaderCache.h (1724B)


      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    angle::Result getShader(const Context *context,
     41                            Shader *shader,
     42                            const ShCompileOptions &compileOptions,
     43                            const ShCompilerInstance &compilerInstance,
     44                            egl::BlobCache::Key *hashOut);
     45 
     46    // Empty the cache.
     47    void clear();
     48 
     49    // Returns the maximum cache size in bytes.
     50    size_t maxSize() const;
     51 
     52  private:
     53    egl::BlobCache &mBlobCache;
     54 
     55    std::mutex mHistogramMutex;
     56 };
     57 
     58 }  // namespace gl
     59 
     60 #endif  // LIBANGLE_MEMORY_SHADER_CACHE_H_