Hash :
91c981c5
Author :
Date :
2024-01-11T22:37:48
Robust shader compile after shader binary is rejected If ANGLE finds a shader binary in the cache, it populates the compiled shader state. If the deserialization rejects the blob, the compiled shader state was not reset. After the rejection, ANGLE proceeds to redo the shader compilation, in which case it risks bugs as it tries to accumulate info on top of the previous half-complete shader state. Note that currently there are no errors if the shader state is not reset before compilation, so this change is merely a precaution. Bug: angleproject:8471 Change-Id: I2e08ecc2e5d940c88a32b5a05dca8afe8d8d897c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5189154 Reviewed-by: mohan maiya <m.maiya@samsung.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Charlie Lao <cclao@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
//
// 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.
egl::CacheGetResult getShader(const Context *context,
Shader *shader,
const egl::BlobCache::Key &shaderHash);
// Empty the cache.
void clear();
// Returns the maximum cache size in bytes.
size_t maxSize() const;
private:
egl::BlobCache &mBlobCache;
};
} // namespace gl
#endif // LIBANGLE_MEMORY_SHADER_CACHE_H_