Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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};
143
144/*
145 * Depth and stencil settings
146 */
147enum class CompareOp : uint8_t {
148 kAlways,
149 kNever,
150 kGreater,
151 kGEqual,
152 kLess,
153 kLEqual,
154 kEqual,
156};
157static constexpr int kCompareOpCount = 1 + (int)CompareOp::kNotEqual;
158
159enum class StencilOp : uint8_t {
160 kKeep,
161 kZero,
162 kReplace, // Replace stencil value with reference (only the bits enabled in fWriteMask).
163 kInvert,
164 kIncWrap,
165 kDecWrap,
166 // NOTE: clamping occurs before the write mask. So if the MSB is zero and masked out, stencil
167 // values will still wrap when using clamping ops.
168 kIncClamp,
170};
171static constexpr int kStencilOpCount = 1 + (int)StencilOp::kDecClamp;
172
174 // Per-face settings for stencil
175 struct Face {
176 constexpr Face() = default;
177 constexpr Face(StencilOp stencilFail,
178 StencilOp depthFail,
179 StencilOp dsPass,
181 uint32_t readMask,
182 uint32_t writeMask)
183 : fStencilFailOp(stencilFail)
184 , fDepthFailOp(depthFail)
185 , fDepthStencilPassOp(dsPass)
187 , fReadMask(readMask)
188 , fWriteMask(writeMask) {}
189
194 uint32_t fReadMask = 0xffffffff;
195 uint32_t fWriteMask = 0xffffffff;
196
197 constexpr bool operator==(const Face& that) const {
198 return this->fStencilFailOp == that.fStencilFailOp &&
199 this->fDepthFailOp == that.fDepthFailOp &&
200 this->fDepthStencilPassOp == that.fDepthStencilPassOp &&
201 this->fCompareOp == that.fCompareOp &&
202 this->fReadMask == that.fReadMask &&
203 this->fWriteMask == that.fWriteMask;
204 }
205 };
206
207 constexpr DepthStencilSettings() = default;
208 constexpr DepthStencilSettings(Face front,
209 Face back,
210 uint32_t stencilRef,
211 bool stencilTest,
212 CompareOp depthCompare,
213 bool depthTest,
214 bool depthWrite)
215 : fFrontStencil(front)
216 , fBackStencil(back)
217 , fStencilReferenceValue(stencilRef)
218 , fDepthCompareOp(depthCompare)
219 , fStencilTestEnabled(stencilTest)
220 , fDepthTestEnabled(depthTest)
221 , fDepthWriteEnabled(depthWrite) {}
222
223 constexpr bool operator==(const DepthStencilSettings& that) const {
224 return this->fFrontStencil == that.fFrontStencil &&
225 this->fBackStencil == that.fBackStencil &&
227 this->fDepthCompareOp == that.fDepthCompareOp &&
229 this->fDepthTestEnabled == that.fDepthTestEnabled &&
231 }
232
238 bool fDepthTestEnabled = false;
239 bool fDepthWriteEnabled = false;
240};
241
242}; // namespace skgpu::graphite
243
244#endif // skgpu_graphite_DrawTypes_DEFINED
static bool compare(const SkBitmap &ref, const SkIRect &iref, const SkBitmap &test, const SkIRect &itest)
Definition BlurTest.cpp:100
#define SkUNREACHABLE
Definition SkAssert.h:135
Type::kYUV Type::kRGBA() int(0.7 *637)
static constexpr int kCompareOpCount
Definition DrawTypes.h:157
static constexpr size_t VertexAttribTypeSize(VertexAttribType type)
Definition DrawTypes.h:77
static constexpr int kStencilOpCount
Definition DrawTypes.h:171
static const int kVertexAttribTypeCount
Definition DrawTypes.h:71
constexpr Face(StencilOp stencilFail, StencilOp depthFail, StencilOp dsPass, CompareOp compare, uint32_t readMask, uint32_t writeMask)
Definition DrawTypes.h:177
constexpr bool operator==(const Face &that) const
Definition DrawTypes.h:197
constexpr bool operator==(const DepthStencilSettings &that) const
Definition DrawTypes.h:223
constexpr DepthStencilSettings(Face front, Face back, uint32_t stencilRef, bool stencilTest, CompareOp depthCompare, bool depthTest, bool depthWrite)
Definition DrawTypes.h:208
constexpr DepthStencilSettings()=default