Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ResourceTypes.h
Go to the documentation of this file.
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
16#include "src/base/SkMathPriv.h"
17
18namespace skgpu::graphite {
19
20class Buffer;
21
22enum class DepthStencilFlags : int {
23 kNone = 0b000,
24 kDepth = 0b001,
25 kStencil = 0b010,
27};
29
30/**
31 * This enum is used to specify the load operation to be used when a RenderPass begins execution
32 */
33enum class LoadOp : uint8_t {
34 kLoad,
35 kClear,
37
39};
40inline static constexpr int kLoadOpCount = (int)(LoadOp::kLast) + 1;
41
42/**
43 * This enum is used to specify the store operation to be used when a RenderPass ends execution.
44 */
45enum class StoreOp : uint8_t {
46 kStore,
48
50};
51inline static constexpr int kStoreOpCount = (int)(StoreOp::kLast) + 1;
52
53/**
54 * What a GPU buffer will be used for
55 */
56enum class BufferType : int {
57 kVertex,
58 kIndex,
63
64 // GPU-only buffer types
68
70};
71static const int kBufferTypeCount = static_cast<int>(BufferType::kLast) + 1;
72
73/**
74 * Data layout requirements on host-shareable buffer contents.
75 */
76enum class Layout {
77 kInvalid = 0,
78 kStd140,
79 kStd430,
80 kMetal,
81};
82
83static constexpr const char* LayoutString(Layout layout) {
84 switch(layout) {
85 case Layout::kStd140: return "std140";
86 case Layout::kStd430: return "std430";
87 case Layout::kMetal: return "metal";
88 case Layout::kInvalid: return "invalid";
89 }
91}
92
93/**
94 * Indicates the intended access pattern over resource memory. This is used to select the most
95 * efficient memory type during resource creation based on the capabilities of the platform.
96 *
97 * This is only a hint and the actual memory type will be determined based on the resource type and
98 * backend capabilities.
99 */
100enum class AccessPattern : int {
101 // GPU-only memory does not need to support reads/writes from the CPU. GPU-private memory will
102 // be preferred if the backend supports an efficient private memory type.
103 kGpuOnly,
104
105 // The resource needs to be CPU visible, e.g. for read-back or as a copy/upload source.
107};
108
109/**
110 * Determines whether the contents of a GPU buffer sub-allocation gets cleared to 0 before being
111 * used in a GPU command submission.
112 */
113enum class ClearBuffer : bool {
114 kNo = false,
115 kYes = true,
116};
117
118/**
119 * Must the contents of the Resource be preserved af a render pass or can a more efficient
120 * representation be chosen when supported by hardware.
121 */
122enum class Discardable : bool {
123 kNo = false,
124 kYes = true
125};
126
127enum class Ownership {
128 kOwned,
129 kWrapped,
130};
131
132/** Uniquely identifies the type of resource that is cached with a GraphiteResourceKey. */
133using ResourceType = uint32_t;
134
135/**
136 * Can the resource be held by multiple users at the same time?
137 * For example, stencil buffers, pipelines, etc.
138 */
139enum class Shareable : bool {
140 kNo = false,
141 kYes = true,
142};
143
144/**
145 * This enum is used to notify the ResourceCache which type of ref just dropped to zero on a
146 * Resource.
147 */
148enum class LastRemovedRef {
149 kUsage,
151 kCache,
152};
153
154/*
155 * Struct that can be passed into bind buffer calls on the CommandBuffer. The ownership of the
156 * buffer and its usage in command submission must be tracked by the caller (e.g. as with
157 * buffers created by DrawBufferManager).
158 */
160 const Buffer* fBuffer = nullptr;
161 size_t fOffset = 0;
162
163 operator bool() const { return SkToBool(fBuffer); }
164
165 bool operator==(const BindBufferInfo& o) const {
166 return fBuffer == o.fBuffer && (!fBuffer || fOffset == o.fOffset);
167 }
168 bool operator!=(const BindBufferInfo& o) const { return !(*this == o); }
169};
170
171/*
172 * Struct that can be passed into bind uniform buffer calls on the CommandBuffer.
173 * It is similar to BindBufferInfo with additional fBindingSize member.
174 */
176 // TODO(b/308933713): Add size to BindBufferInfo instead
177 uint32_t fBindingSize = 0;
178
179 bool operator==(const BindUniformBufferInfo& o) const {
181 }
182 bool operator!=(const BindUniformBufferInfo& o) const { return !(*this == o); }
183};
184
185/**
186 * Represents a buffer region that should be cleared to 0. A ClearBuffersTask does not take an
187 * owning reference to the buffer it clears. A higher layer is responsible for managing the lifetime
188 * and usage refs of the buffer.
189 */
191 const Buffer* fBuffer = nullptr;
192 size_t fOffset = 0;
193 size_t fSize = 0;
194
195 operator bool() const { return SkToBool(fBuffer); }
196};
197
198/**
199 * Struct used to describe how a Texture/TextureProxy/TextureProxyView is sampled.
200 */
202 static_assert(kSkTileModeCount <= 4 && kSkFilterModeCount <= 2 && kSkMipmapModeCount <= 4);
204 : fDesc((static_cast<int>(tileModes[0]) << kTileModeXShift) |
205 (static_cast<int>(tileModes[1]) << kTileModeYShift) |
206 (static_cast<int>(samplingOptions.filter) << kFilterModeShift) |
207 (static_cast<int>(samplingOptions.mipmap) << kMipmapModeShift) ) {
208 // Cubic sampling is handled in a shader, with the actual texture sampled by with NN,
209 // but that is what a cubic SkSamplingOptions is set to if you ignore 'cubic', which let's
210 // us simplify how we construct SamplerDec's from the options passed to high-level draws.
213 static_assert(kMipmapModeShift + kNumMipmapModeBits <= 32);
214 // Backend-agnostic sampler information can fit within one uint32_t.
215 // TODO: Add aniso value when used.
216 static_assert(sizeof(uint32_t) == 4);
217 }
218
219 SamplerDesc(const SamplerDesc&) = default;
220
221 bool operator==(const SamplerDesc& o) const { return o.fDesc == fDesc; }
222 bool operator!=(const SamplerDesc& o) const { return o.fDesc != fDesc; }
223
224 SkTileMode tileModeX() const { return static_cast<SkTileMode>((fDesc >> 0) & 0b11); }
225 SkTileMode tileModeY() const { return static_cast<SkTileMode>((fDesc >> 2) & 0b11); }
226 uint32_t desc() const { return fDesc; }
227
228 // NOTE: returns the HW sampling options to use, so a bicubic SkSamplingOptions will become
229 // nearest-neighbor sampling in HW.
231 // TODO: Add support for anisotropic filtering
232 SkFilterMode filter = static_cast<SkFilterMode>((fDesc >> 4) & 0b01);
233 SkMipmapMode mipmap = static_cast<SkMipmapMode>((fDesc >> 5) & 0b11);
234 return SkSamplingOptions(filter, mipmap);
235 }
236
237private:
238 uint32_t fDesc;
239
240 static constexpr int kNumTileModeBits = SkNextLog2_portable(int(SkTileMode::kLastTileMode)+1);
241 static constexpr int kNumFilterModeBits = SkNextLog2_portable(int(SkFilterMode::kLast)+1);
242 static constexpr int kNumMipmapModeBits = SkNextLog2_portable(int(SkMipmapMode::kLast)+1);
243
244 static constexpr int kTileModeXShift = 0;
245 static constexpr int kTileModeYShift = kTileModeXShift + kNumTileModeBits;
246 static constexpr int kFilterModeShift = kTileModeYShift + kNumTileModeBits;
247 static constexpr int kMipmapModeShift = kFilterModeShift + kNumFilterModeBits;
248};
249
250}; // namespace skgpu::graphite
251
252#endif // skgpu_graphite_ResourceTypes_DEFINED
#define SkUNREACHABLE
Definition SkAssert.h:135
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SK_MAKE_BITMASK_OPS(E)
constexpr int SkNextLog2_portable(uint32_t value)
Definition SkMathPriv.h:243
SkFilterMode
SkMipmapMode
static constexpr int kSkFilterModeCount
static constexpr int kSkMipmapModeCount
SkTileMode
Definition SkTileMode.h:13
static constexpr int kSkTileModeCount
Definition SkTileMode.h:39
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
Type::kYUV Type::kRGBA() int(0.7 *637)
uint32_t ResourceType
static constexpr const char * LayoutString(Layout layout)
static constexpr int kLoadOpCount
static constexpr int kStoreOpCount
static const int kBufferTypeCount
const SkFilterMode filter
const SkMipmapMode mipmap
bool operator!=(const BindBufferInfo &o) const
bool operator==(const BindBufferInfo &o) const
bool operator==(const BindUniformBufferInfo &o) const
bool operator!=(const BindUniformBufferInfo &o) const
SkTileMode tileModeX() const
bool operator==(const SamplerDesc &o) const
SkSamplingOptions samplingOptions() const
bool operator!=(const SamplerDesc &o) const
SkTileMode tileModeY() const
SamplerDesc(const SkSamplingOptions &samplingOptions, const SkTileMode tileModes[2])
SamplerDesc(const SamplerDesc &)=default