xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrPersistentCacheUtils.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2019 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef GrPersistentCacheEntry_DEFINED
9 #define GrPersistentCacheEntry_DEFINED
10 
11 #include "include/core/SkData.h"
12 #include "include/core/SkFourByteTag.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkTypes.h"
15 #include "include/private/base/SkTArray.h"
16 #include "src/sksl/ir/SkSLProgram.h"
17 
18 #include <string>
19 
20 class SkReadBuffer;
21 namespace SkSL { struct ProgramSettings; }
22 
23 // The GrPersistentCache stores opaque blobs, as far as clients are concerned. It's helpful to
24 // inspect certain kinds of cached data within our tools, so for those cases (GLSL, SPIR-V), we
25 // put the serialization logic here, to be shared by the backend code and the tool code.
26 namespace GrPersistentCacheUtils {
27 
28 struct ShaderMetadata {
29     SkSL::ProgramSettings* fSettings = nullptr;
30     skia_private::TArray<std::string> fAttributeNames;
31     bool fHasSecondaryColorOutput = false;
32     sk_sp<SkData> fPlatformData;
33 };
34 
35 int GetCurrentVersion();
36 
37 sk_sp<SkData> PackCachedShaders(SkFourByteTag shaderType,
38                                 const std::string shaders[],
39                                 const SkSL::Program::Interface[],
40                                 int numInterfaces,
41                                 const ShaderMetadata* meta = nullptr);
42 
43 SkFourByteTag GetType(SkReadBuffer* reader);
44 
45 bool UnpackCachedShaders(SkReadBuffer* reader,
46                          std::string shaders[],
47                          SkSL::Program::Interface[],
48                          int numInterfaces,
49                          ShaderMetadata* meta = nullptr);
50 
51 }  // namespace GrPersistentCacheUtils
52 
53 #endif
54