• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 skgpu_graphite_ResourceTypes_DEFINED
9 #define skgpu_graphite_ResourceTypes_DEFINED
10 
11 #include "include/gpu/graphite/GraphiteTypes.h"
12 #include "include/private/base/SkTo.h"
13 #include "src/core/SkEnumBitMask.h"
14 
15 namespace skgpu::graphite {
16 
17 class Buffer;
18 
19 /**
20  * Is the Texture renderable or not
21  */
22 enum class Renderable : bool {
23     kNo = false,
24     kYes = true,
25 };
26 
27 enum class DepthStencilFlags : int {
28     kNone = 0b000,
29     kDepth = 0b001,
30     kStencil = 0b010,
31     kDepthStencil = kDepth | kStencil,
32 };
33 SK_MAKE_BITMASK_OPS(DepthStencilFlags);
34 
35 /**
36  * What a GPU buffer will be used for
37  */
38 enum class BufferType : int {
39     kVertex,
40     kIndex,
41     kXferCpuToGpu,
42     kXferGpuToCpu,
43     kUniform,
44     kStorage,
45 
46     // GPU-only buffer types
47     kIndirect,
48     kVertexStorage,
49     kIndexStorage,
50 
51     kLast = kIndexStorage,
52 };
53 static const int kBufferTypeCount = static_cast<int>(BufferType::kLast) + 1;
54 
55 /**
56  * Data layout requirements on host-shareable buffer contents.
57  */
58 enum class Layout {
59     kInvalid = 0,
60     kStd140,
61     kStd430,
62     kMetal,
63 };
64 
65 /**
66  * When creating the memory for a resource should we use a memory type that prioritizes the
67  * effeciency of GPU reads even if it involves extra work to write CPU data to it. For example, we
68  * would want this for buffers that we cache to read the same data many times on the GPU.
69  */
70 enum class PrioritizeGpuReads : bool {
71     kNo = false,
72     kYes = true,
73 };
74 
75 /**
76  * Must the contents of the Resource be preserved af a render pass or can a more efficient
77  * representation be chosen when supported by hardware.
78  */
79 enum class Discardable : bool {
80     kNo = false,
81     kYes = true
82 };
83 
84 enum class Ownership {
85     kOwned,
86     kWrapped,
87 };
88 
89 /** Uniquely identifies the type of resource that is cached with a GraphiteResourceKey. */
90 using ResourceType = uint32_t;
91 
92 /**
93  * Can the resource be held by multiple users at the same time?
94  * For example, stencil buffers, pipelines, etc.
95  */
96 enum class Shareable : bool {
97     kNo = false,
98     kYes = true,
99 };
100 
101 /**
102  * This enum is used to notify the ResourceCache which type of ref just dropped to zero on a
103  * Resource.
104  */
105 enum class LastRemovedRef {
106     kUsage,
107     kCommandBuffer,
108     kCache,
109 };
110 
111 /*
112  * Struct that can be passed into bind buffer calls on the CommandBuffer. The ownership of the
113  * buffer and its usage in command submission must be tracked by the caller (e.g. as with
114  * buffers created by DrawBufferManager).
115  */
116 struct BindBufferInfo {
117     const Buffer* fBuffer = nullptr;
118     size_t fOffset = 0;
119 
120     operator bool() const { return SkToBool(fBuffer); }
121 
122     bool operator==(const BindBufferInfo& o) const {
123         return fBuffer == o.fBuffer && (!fBuffer || fOffset == o.fOffset);
124     }
125     bool operator!=(const BindBufferInfo& o) const { return !(*this == o); }
126 };
127 
128 };  // namespace skgpu::graphite
129 
130 #endif // skgpu_graphite_ResourceTypes_DEFINED
131