Flutter Engine
The Flutter Engine
GrProgramDesc.h
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
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 GrProgramDesc_DEFINED
9#define GrProgramDesc_DEFINED
10
16
17#include <limits.h>
18
19class GrCaps;
20class GrProgramInfo;
21class GrRenderTarget;
22
23/** This class is used to generate a generic program cache key. The Dawn, Metal and Vulkan
24 * backends derive backend-specific versions which add additional information.
25 */
27public:
28 GrProgramDesc(const GrProgramDesc& other) = default;
29 GrProgramDesc& operator=(const GrProgramDesc &other) = default;
30
31 bool isValid() const { return !fKey.empty(); }
32 void reset() { *this = GrProgramDesc{}; }
33
34 // Returns this as a uint32_t array to be used as a key in the program cache.
35 const uint32_t* asKey() const {
36 return fKey.data();
37 }
38
39 // Gets the number of bytes in asKey(). It will be a 4-byte aligned value.
40 uint32_t keyLength() const {
41 return SkToU32(fKey.size() * sizeof(uint32_t));
42 }
43
44 bool operator== (const GrProgramDesc& that) const {
45 return this->fKey == that.fKey;
46 }
47
48 bool operator!= (const GrProgramDesc& other) const {
49 return !(*this == other);
50 }
51
52 uint32_t initialKeyLength() const { return fInitialKeyLength; }
53
54 // TODO(skia:11372): Incorporate this into caps interface (part of makeDesc, or a parallel
55 // function), so other backends can include their information in the description.
56 static SkString Describe(const GrProgramInfo&, const GrCaps&);
57
58protected:
59 friend class GrDawnCaps;
60 friend class GrD3DCaps;
61 friend class GrGLCaps;
62 friend class GrMockCaps;
63 friend class GrMtlCaps;
64 friend class GrVkCaps;
65
66 friend class GrGLGpu; // for ProgramCache to access BuildFromData
67 friend class GrMtlResourceProvider; // for PipelineStateCache to access BuildFromData
68
69 // Creates an uninitialized key that must be populated by Build
71
72 /**
73 * Builds a program descriptor.
74 *
75 * @param desc The built descriptor
76 * @param programInfo Program information need to build the key
77 * @param caps the caps
78 **/
79 static void Build(GrProgramDesc*, const GrProgramInfo&, const GrCaps&);
80
81 // This is strictly an OpenGL call since the other backends have additional data in their keys.
82 static bool BuildFromData(GrProgramDesc* desc, const void* keyData, size_t keyLength) {
83 if (!SkTFitsIn<int>(keyLength) || !SkIsAlign4(keyLength)) {
84 return false;
85 }
86 desc->fKey.reset(SkToInt(keyLength / 4));
87 memcpy(desc->fKey.begin(), keyData, keyLength);
88 return true;
89 }
90
91 enum {
92 kHeaderSize = 1, // "header" in ::Build
94 kIntsPerProcessor = 4, // This is an overestimate of the average effect key size.
97 };
98
100
101 KeyType* key() { return &fKey; }
102
103private:
105 uint32_t fInitialKeyLength = 0;
106};
107
108#endif
static constexpr bool SkIsAlign4(T x)
Definition: SkAlign.h:20
constexpr int SkToInt(S x)
Definition: SkTo.h:29
constexpr uint32_t SkToU32(S x)
Definition: SkTo.h:26
Definition: GrCaps.h:57
static bool BuildFromData(GrProgramDesc *desc, const void *keyData, size_t keyLength)
Definition: GrProgramDesc.h:82
uint32_t keyLength() const
Definition: GrProgramDesc.h:40
bool operator==(const GrProgramDesc &that) const
Definition: GrProgramDesc.h:44
friend class GrDawnCaps
Definition: GrProgramDesc.h:59
GrProgramDesc(const GrProgramDesc &other)=default
GrProgramDesc & operator=(const GrProgramDesc &other)=default
uint32_t initialKeyLength() const
Definition: GrProgramDesc.h:52
const uint32_t * asKey() const
Definition: GrProgramDesc.h:35
static void Build(GrProgramDesc *, const GrProgramInfo &, const GrCaps &)
KeyType * key()
bool isValid() const
Definition: GrProgramDesc.h:31
bool operator!=(const GrProgramDesc &other) const
Definition: GrProgramDesc.h:48
static SkString Describe(const GrProgramInfo &, const GrCaps &)
bool empty() const
Definition: SkTArray.h:199
int size() const
Definition: SkTArray.h:421