Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Side by Side Diff: src/gpu/instanced/InstancedRenderingTypes.h

Issue 2123693002: Revert of Begin instanced rendering for simple shapes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/instanced/InstancedRendering.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 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 gr_instanced_InstancedRenderingTypes_DEFINED
9 #define gr_instanced_InstancedRenderingTypes_DEFINED
10
11 #include "GrTypes.h"
12 #include "SkRRect.h"
13
14 namespace gr_instanced {
15
16 /**
17 * Per-vertex data. These values get fed into normal vertex attribs.
18 */
19 struct ShapeVertex {
20 float fX, fY; //!< Shape coordinates.
21 int32_t fAttrs; //!< Shape-specific vertex attributes, if needed.
22 };
23
24 /**
25 * Per-instance data. These values get fed into instanced vertex attribs.
26 */
27 struct Instance {
28 uint32_t fInfo; //!< Packed info about the instance. See Inf oBits.
29 float fShapeMatrix2x3[6]; //!< Maps canonical shape coords -> device s pace coords.
30 uint32_t fColor; //!< Color to be written out by the primitiv e processor.
31 float fLocalRect[4]; //!< Local coords rect that spans [-1, +1] i n shape coords.
32 };
33
34 enum class Attrib : uint8_t {
35 kShapeCoords,
36 kVertexAttrs,
37 kInstanceInfo,
38 kShapeMatrixX,
39 kShapeMatrixY,
40 kColor,
41 kLocalRect
42 };
43 constexpr int kNumAttribs = 1 + (int)Attrib::kLocalRect;
44
45 enum class AntialiasMode : uint8_t {
46 kNone,
47 kCoverage,
48 kMSAA,
49 kMixedSamples
50 };
51 constexpr int kNumAntialiasModes = 1 + (int)AntialiasMode::kMixedSamples;
52
53 enum class ShapeType : uint8_t {
54 kRect,
55 kOval,
56 kSimpleRRect,
57 kNinePatch,
58 kComplexRRect
59 };
60 constexpr int kNumShapeTypes = 1 + (int)ShapeType::kComplexRRect;
61
62 inline static ShapeType GetRRectShapeType(const SkRRect& rrect) {
63 SkASSERT(rrect.getType() >= SkRRect::kRect_Type &&
64 rrect.getType() <= SkRRect::kComplex_Type);
65 return static_cast<ShapeType>(rrect.getType() - 1);
66
67 GR_STATIC_ASSERT((int)ShapeType::kRect == SkRRect::kRect_Type - 1);
68 GR_STATIC_ASSERT((int)ShapeType::kOval == SkRRect::kOval_Type - 1);
69 GR_STATIC_ASSERT((int)ShapeType::kSimpleRRect == SkRRect::kSimple_Type - 1);
70 GR_STATIC_ASSERT((int)ShapeType::kNinePatch == SkRRect::kNinePatch_Type - 1) ;
71 GR_STATIC_ASSERT((int)ShapeType::kComplexRRect == SkRRect::kComplex_Type - 1 );
72 GR_STATIC_ASSERT(kNumShapeTypes == SkRRect::kComplex_Type);
73 }
74
75 enum ShapeFlag {
76 kRect_ShapeFlag = (1 << (int)ShapeType::kRect),
77 kOval_ShapeFlag = (1 << (int)ShapeType::kOval),
78 kSimpleRRect_ShapeFlag = (1 << (int)ShapeType::kSimpleRRect),
79 kNinePatch_ShapeFlag = (1 << (int)ShapeType::kNinePatch),
80 kComplexRRect_ShapeFlag = (1 << (int)ShapeType::kComplexRRect),
81
82 kRRect_ShapesMask = kSimpleRRect_ShapeFlag | kNinePatch_ShapeFlag | kComplex RRect_ShapeFlag
83 };
84
85 constexpr uint8_t GetShapeFlag(ShapeType type) { return 1 << (int)type; }
86
87 /**
88 * Defines what data is stored at which bits in the fInfo field of the instanced data.
89 */
90 enum InfoBits {
91 kShapeType_InfoBit = 29,
92 kInnerShapeType_InfoBit = 27,
93 kPerspective_InfoBit = 26,
94 kLocalMatrix_InfoBit = 25,
95 kParamsIdx_InfoBit = 0
96 };
97
98 enum InfoMasks {
99 kShapeType_InfoMask = 0u - (1 << kShapeType_InfoBit),
100 kInnerShapeType_InfoMask = (1 << kShapeType_InfoBit) - (1 << kInnerShapeTyp e_InfoBit),
101 kPerspective_InfoFlag = (1 << kPerspective_InfoBit),
102 kLocalMatrix_InfoFlag = (1 << kLocalMatrix_InfoBit),
103 kParamsIdx_InfoMask = (1 << kLocalMatrix_InfoBit) - 1
104 };
105
106 GR_STATIC_ASSERT((kNumShapeTypes - 1) <= (uint32_t)kShapeType_InfoMask >> kShape Type_InfoBit);
107 GR_STATIC_ASSERT((int)ShapeType::kSimpleRRect <=
108 kInnerShapeType_InfoMask >> kInnerShapeType_InfoBit);
109
110 /**
111 * Additional parameters required by some instances (e.g. round rect radii, pers pective column,
112 * local matrix). These are accessed via texel buffer.
113 */
114 struct ParamsTexel {
115 float fX, fY, fZ, fW;
116 };
117
118 GR_STATIC_ASSERT(0 == offsetof(ParamsTexel, fX));
119 GR_STATIC_ASSERT(4 * 4 == sizeof(ParamsTexel));
120
121 /**
122 * Tracks all information needed in order to draw a batch of instances. This str uct also serves
123 * as an all-in-one shader key for the batch.
124 */
125 struct BatchInfo {
126 BatchInfo() : fData(0) {}
127
128 bool isSimpleRects() const {
129 return !((fShapeTypes & ~kRect_ShapeFlag) | fInnerShapeTypes);
130 }
131
132 bool canJoin(BatchInfo that) const {
133 if (fAntialiasMode != that.fAntialiasMode) {
134 return false;
135 }
136 if (SkToBool(fInnerShapeTypes) != SkToBool(that.fInnerShapeTypes)) {
137 // GrInstanceProcessor can't currently combine draws with and withou t inner shapes.
138 return false;
139 }
140 if (fCannotDiscard != that.fCannotDiscard) {
141 // For stencil draws, the use of discard can be a requirement.
142 return false;
143 }
144 return true;
145 }
146
147 void join(BatchInfo that) {
148 SkASSERT(this->canJoin(that));
149 fData |= that.fData;
150 }
151
152 union {
153 struct {
154 AntialiasMode fAntialiasMode;
155 uint8_t fShapeTypes;
156 uint8_t fInnerShapeTypes;
157 bool fHasPerspective : 1;
158 bool fHasLocalMatrix : 1;
159 bool fHasParams : 1;
160 bool fNonSquare : 1;
161 bool fUsesLocalCoords : 1;
162 bool fCannotTweakAlphaForCoverage : 1;
163 bool fCannotDiscard : 1;
164 };
165 uint32_t fData;
166 };
167 };
168
169 // This is required since all the data must fit into 32 bits of a shader key.
170 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(BatchInfo));
171 GR_STATIC_ASSERT(kNumShapeTypes <= 8);
172
173 template<typename T> struct TRange {
174 bool operator ==(const TRange& that) const {
175 return fStart == that.fStart && fCount == that.fCount;
176 }
177 bool operator !=(const TRange& that) const { return !(*this == that); }
178
179 bool isEmpty() const { return fCount <= 0; }
180 T end() { return fStart + fCount; }
181
182 T fStart;
183 T fCount;
184 };
185
186 typedef TRange<int16_t> IndexRange;
187 typedef TRange<int> InstanceRange;
188
189 }
190
191 #endif
OLDNEW
« no previous file with comments | « src/gpu/instanced/InstancedRendering.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698