Flutter Engine
The Flutter Engine
DrawTypes.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_DrawTypes_DEFINED
9#define skgpu_graphite_DrawTypes_DEFINED
10
12
14
15#include <array>
16
17namespace skgpu::graphite {
18
19class Buffer;
20
21/**
22 * Geometric primitives used for drawing.
23 */
24enum class PrimitiveType : uint8_t {
27 kPoints,
28};
29
30/**
31 * Types used to describe format of vertices in buffers.
32 */
33enum class VertexAttribType : uint8_t {
34 kFloat = 0,
35 kFloat2,
36 kFloat3,
37 kFloat4,
38 kHalf,
39 kHalf2,
40 kHalf4,
41
42 kInt2, // vector of 2 32-bit ints
43 kInt3, // vector of 3 32-bit ints
44 kInt4, // vector of 4 32-bit ints
45
46 kByte, // signed byte
47 kByte2, // vector of 2 8-bit signed bytes
48 kByte4, // vector of 4 8-bit signed bytes
49 kUByte, // unsigned byte
50 kUByte2, // vector of 2 8-bit unsigned bytes
51 kUByte4, // vector of 4 8-bit unsigned bytes
52
53 kUByte_norm, // unsigned byte, e.g. coverage, 0 -> 0.0f, 255 -> 1.0f.
54 kUByte4_norm, // vector of 4 unsigned bytes, e.g. colors, 0 -> 0.0f, 255 -> 1.0f.
55
56 kShort2, // vector of 2 16-bit shorts.
57 kShort4, // vector of 4 16-bit shorts.
58
59 kUShort2, // vector of 2 unsigned shorts. 0 -> 0, 65535 -> 65535.
60 kUShort2_norm, // vector of 2 unsigned shorts. 0 -> 0.0f, 65535 -> 1.0f.
61
62 kInt,
63 kUInt,
64
65 kUShort_norm, // unsigned short, e.g. depth, 0 -> 0.0f, 65535 -> 1.0f.
66
67 kUShort4_norm, // vector of 4 unsigned shorts. 0 -> 0.0f, 65535 -> 1.0f.
68
70};
72
73
74/**
75 * Returns the size of the attrib type in bytes.
76 */
77static constexpr inline size_t VertexAttribTypeSize(VertexAttribType type) {
78 switch (type) {
80 return sizeof(float);
82 return 2 * sizeof(float);
84 return 3 * sizeof(float);
86 return 4 * sizeof(float);
88 return sizeof(uint16_t);
90 return 2 * sizeof(uint16_t);
92 return 4 * sizeof(uint16_t);
94 return 2 * sizeof(int32_t);
96 return 3 * sizeof(int32_t);
98 return 4 * sizeof(int32_t);
100 return 1 * sizeof(char);
102 return 2 * sizeof(char);
104 return 4 * sizeof(char);
106 return 1 * sizeof(char);
108 return 2 * sizeof(char);
110 return 4 * sizeof(char);
112 return 1 * sizeof(char);
114 return 4 * sizeof(char);
116 return 2 * sizeof(int16_t);
118 return 4 * sizeof(int16_t);
119 case VertexAttribType::kUShort2: [[fallthrough]];
121 return 2 * sizeof(uint16_t);
123 return sizeof(int32_t);
125 return sizeof(uint32_t);
127 return sizeof(uint16_t);
129 return 4 * sizeof(uint16_t);
130 }
132}
133
134enum class UniformSlot {
135 // TODO: Want this?
136 // Meant for uniforms that change rarely to never over the course of a render pass
137 // kStatic,
138 // Meant for uniforms that are defined and used by the RenderStep portion of the pipeline shader
140 // Meant for uniforms that are defined and used by the paint parameters (ie SkPaint subset)
141 kPaint,
142 // Meant for gradient storage buffer.
144};
145
146/*
147 * Depth and stencil settings
148 */
149enum class CompareOp : uint8_t {
150 kAlways,
151 kNever,
152 kGreater,
153 kGEqual,
154 kLess,
155 kLEqual,
156 kEqual,
158};
159static constexpr int kCompareOpCount = 1 + (int)CompareOp::kNotEqual;
160
161enum class StencilOp : uint8_t {
162 kKeep,
163 kZero,
164 kReplace, // Replace stencil value with reference (only the bits enabled in fWriteMask).
165 kInvert,
166 kIncWrap,
167 kDecWrap,
168 // NOTE: clamping occurs before the write mask. So if the MSB is zero and masked out, stencil
169 // values will still wrap when using clamping ops.
170 kIncClamp,
172};
173static constexpr int kStencilOpCount = 1 + (int)StencilOp::kDecClamp;
174
176 // Per-face settings for stencil
177 struct Face {
178 constexpr Face() = default;
179 constexpr Face(StencilOp stencilFail,
180 StencilOp depthFail,
181 StencilOp dsPass,
183 uint32_t readMask,
184 uint32_t writeMask)
185 : fStencilFailOp(stencilFail)
186 , fDepthFailOp(depthFail)
187 , fDepthStencilPassOp(dsPass)
189 , fReadMask(readMask)
190 , fWriteMask(writeMask) {}
191
196 uint32_t fReadMask = 0xffffffff;
197 uint32_t fWriteMask = 0xffffffff;
198
199 constexpr bool operator==(const Face& that) const {
200 return this->fStencilFailOp == that.fStencilFailOp &&
201 this->fDepthFailOp == that.fDepthFailOp &&
202 this->fDepthStencilPassOp == that.fDepthStencilPassOp &&
203 this->fCompareOp == that.fCompareOp &&
204 this->fReadMask == that.fReadMask &&
205 this->fWriteMask == that.fWriteMask;
206 }
207 };
208
209 constexpr DepthStencilSettings() = default;
210 constexpr DepthStencilSettings(Face front,
211 Face back,
212 uint32_t stencilRef,
213 bool stencilTest,
214 CompareOp depthCompare,
215 bool depthTest,
216 bool depthWrite)
217 : fFrontStencil(front)
218 , fBackStencil(back)
219 , fStencilReferenceValue(stencilRef)
220 , fDepthCompareOp(depthCompare)
221 , fStencilTestEnabled(stencilTest)
222 , fDepthTestEnabled(depthTest)
223 , fDepthWriteEnabled(depthWrite) {}
224
225 constexpr bool operator==(const DepthStencilSettings& that) const {
226 return this->fFrontStencil == that.fFrontStencil &&
227 this->fBackStencil == that.fBackStencil &&
229 this->fDepthCompareOp == that.fDepthCompareOp &&
231 this->fDepthTestEnabled == that.fDepthTestEnabled &&
233 }
234
240 bool fDepthTestEnabled = false;
241 bool fDepthWriteEnabled = false;
242};
243
244}; // namespace skgpu::graphite
245
246#endif // skgpu_graphite_DrawTypes_DEFINED
#define SkUNREACHABLE
Definition: SkAssert.h:135
GLenum type
static constexpr int kCompareOpCount
Definition: DrawTypes.h:159
static constexpr size_t VertexAttribTypeSize(VertexAttribType type)
Definition: DrawTypes.h:77
static constexpr int kStencilOpCount
Definition: DrawTypes.h:173
static const int kVertexAttribTypeCount
Definition: DrawTypes.h:71
int compare(const void *untyped_lhs, const void *untyped_rhs)
Definition: skdiff.h:161
constexpr Face(StencilOp stencilFail, StencilOp depthFail, StencilOp dsPass, CompareOp compare, uint32_t readMask, uint32_t writeMask)
Definition: DrawTypes.h:179
constexpr bool operator==(const Face &that) const
Definition: DrawTypes.h:199
constexpr bool operator==(const DepthStencilSettings &that) const
Definition: DrawTypes.h:225
constexpr DepthStencilSettings(Face front, Face back, uint32_t stencilRef, bool stencilTest, CompareOp depthCompare, bool depthTest, bool depthWrite)
Definition: DrawTypes.h:210
constexpr DepthStencilSettings()=default