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

Side by Side Diff: src/gpu/GrInstancedRenderingTypes.h

Issue 1897203002: Implement instanced rendering for simple shapes (Closed) Base URL: https://skia.googlesource.com/skia.git@upload2_requireHWAA
Patch Set: comments Created 4 years, 8 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/GrInstancedRendering.cpp ('k') | src/gpu/batches/GrBatch.h » ('j') | 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 GrInstancedRenderingTypes_DEFINED
9 #define GrInstancedRenderingTypes_DEFINED
10
11 #include "GrTypes.h"
12 #include "SkRRect.h"
13
14 /**
15 * Internal structs and enums for classes involved in instanced rendering. This class is intended
16 * to be inherited non-publicly.
17 */
18 class GrInstancedRenderingTypes {
19 public:
20 /**
21 * Per-vertex data. These values get fed into normal vertex attribs.
22 */
23 struct ShapeVertex {
24 float fX, fY; //!< Shape coordinates.
25 int32_t fAttrs; //!< Shape-specific vertex attributes, if needed.
26 };
27
28 /**
29 * Per-instance data. These values get fed into instanced vertex attribs.
30 */
31 struct Instance {
32 uint32_t fInfo; //!< Packed info about the instance. See InfoBits.
33 float fShapeMatrix2x3[6]; //!< Maps canonical shape coords -> devi ce space coords.
34 uint32_t fColor; //!< Color to be written out by the prim itive processor.
35 float fLocalRect[4]; //!< Local coords rect that spans [-1, + 1] in shape coords.
36 };
37
38 /**
39 * Additional parameters required by some instances (e.g. round rect radii, perspective column,
40 * local matrix). These are accessed via texel buffer.
41 */
42 struct ParamsTexel {
43 union {
44 struct { float fX, fY, fZ, fW; };
45 float fValues[4];
46 };
47 };
48
49 GR_STATIC_ASSERT(0 == offsetof(ParamsTexel, fX));
50 GR_STATIC_ASSERT(4 * 4 == sizeof(ParamsTexel));
51
52 enum AttribIdx {
53 kShapeCoords_AttribIdx,
54 kVertexAttrs_AttribIdx,
55 kInstanceInfo_AttribIdx,
56 kShapeMatrixX_AttribIdx,
57 kShapeMatrixY_AttribIdx,
58 kColor_AttribIdx,
59 kLocalRect_AttribIdx,
60
61 kNumVertexAttribs
62 };
63
64 enum AntialiasMode {
65 kNone_AntialiasMode,
66 kCoverage_AntialiasMode,
67 kMSAA_AntialiasMode,
68 kMixedSamples_AntialiasMode,
69
70 kLast_AntialiasMode = kMixedSamples_AntialiasMode
71 };
72
73 enum AntialiasFlags {
74 kNone_AntialiasFlag = (1 << kNone_AntialiasMode),
75 kCoverage_AntialiasFlag = (1 << kCoverage_AntialiasMode),
76 kMSAA_AntialiasFlag = (1 << kMSAA_AntialiasMode),
77 kMixedSamples_AntialiasFlag = (1 << kMixedSamples_AntialiasMode)
78 };
79
80 enum ShapeType {
81 kRect_ShapeType,
82 kOval_ShapeType,
83 kSimpleRRect_ShapeType,
84 kNinePatch_ShapeType,
85 kComplexRRect_ShapeType,
86
87 kLast_ShapeType = kComplexRRect_ShapeType
88 };
89
90 static ShapeType RRectShapeType(const SkRRect& rrect) {
91 SkASSERT(rrect.getType() >= SkRRect::kRect_Type &&
92 rrect.getType() <= SkRRect::kComplex_Type);
93 return static_cast<ShapeType>(rrect.getType() - 1);
94
95 GR_STATIC_ASSERT(kRect_ShapeType == SkRRect::kRect_Type - 1);
96 GR_STATIC_ASSERT(kOval_ShapeType == SkRRect::kOval_Type - 1);
97 GR_STATIC_ASSERT(kSimpleRRect_ShapeType == SkRRect::kSimple_Type - 1);
98 GR_STATIC_ASSERT(kNinePatch_ShapeType == SkRRect::kNinePatch_Type - 1);
99 GR_STATIC_ASSERT(kComplexRRect_ShapeType == SkRRect::kComplex_Type - 1);
100 GR_STATIC_ASSERT(kLast_ShapeType == SkRRect::kComplex_Type - 1);
101 }
102
103 enum ShapeFlag {
104 kRect_ShapeFlag = (1 << kRect_ShapeType),
105 kOval_ShapeFlag = (1 << kOval_ShapeType),
106 kSimpleRRect_ShapeFlag = (1 << kSimpleRRect_ShapeType),
107 kNinePatch_ShapeFlag = (1 << kNinePatch_ShapeType),
108 kComplexRRect_ShapeFlag = (1 << kComplexRRect_ShapeType),
109
110 kRRect_ShapesMask = kSimpleRRect_ShapeFlag | kNinePatch_ShapeFlag | kCom plexRRect_ShapeFlag
111 };
112
113 /**
114 * Defines what data is stored at which bits in the fInfo field of the insta nced data.
115 */
116 enum InfoBits {
117 kShapeType_InfoBit = 29,
118 kInnerShapeType_InfoBit = 27,
119 kPerspective_InfoBit = 26,
120 kLocalMatrix_InfoBit = 25,
121 kParamsIdx_InfoBit = 0
122 };
123
124 enum InfoMasks {
125 kShapeType_InfoMask = 0u - (1 << kShapeType_InfoBit),
126 kInnerShapeType_InfoMask = (1 << kShapeType_InfoBit) - (1 << kInnerShap eType_InfoBit),
127 kPerspective_InfoFlag = (1 << kPerspective_InfoBit),
128 kLocalMatrix_InfoFlag = (1 << kLocalMatrix_InfoBit),
129 kParamsIdx_InfoMask = (1 << kLocalMatrix_InfoBit) - 1
130 };
131
132 GR_STATIC_ASSERT(kLast_ShapeType <= (uint32_t)kShapeType_InfoMask >> kShapeT ype_InfoBit);
133 GR_STATIC_ASSERT(kSimpleRRect_ShapeType <= kInnerShapeType_InfoMask >> kInne rShapeType_InfoBit);
134
135 /**
136 * Tracks all information needed in order to draw a batch of instances. This struct also serves
137 * as an all-in-one shader key for the batch.
138 */
139 struct BatchInfo {
140 BatchInfo() : fData(0) {}
141
142 bool isSimpleRects() const {
143 return !((fShapeTypes & ~kRect_ShapeFlag) | fInnerShapeTypes);
144 }
145
146 bool canJoin(BatchInfo that) const {
147 if (fAntialiasMode != that.fAntialiasMode) {
148 return false;
149 }
150 if (SkToBool(fInnerShapeTypes) != SkToBool(that.fInnerShapeTypes)) {
151 // GrInstanceProcessor can't currently combine draws with and wi thout inner shapes.
152 return false;
153 }
154 if (fCannotDiscard != that.fCannotDiscard) {
155 // For stencil draws, the use of discard can be a requirement.
156 return false;
157 }
158 return true;
159 }
160
161 void join(BatchInfo that) {
162 SkASSERT(this->canJoin(that));
163 fData |= that.fData;
164 }
165
166 union {
167 struct {
168 AntialiasMode fAntialiasMode : 8;
169 uint8_t fShapeTypes;
170 uint8_t fInnerShapeTypes;
171 bool fHasPerspective : 1;
172 bool fHasLocalMatrix : 1;
173 bool fHasParams : 1;
174 bool fNonSquare : 1;
175 bool fUsesLocalCoords : 1;
176 bool fCannotTweakAlphaForCoverage : 1;
177 bool fCannotDiscard : 1;
178 };
179 uint32_t fData;
180 };
181 };
182
183 // This is required since all the data must fit into 32 bits of a shader key .
184 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(BatchInfo));
185 GR_STATIC_ASSERT(kLast_ShapeType <= 8);
186 };
187
188 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrInstancedRendering.cpp ('k') | src/gpu/batches/GrBatch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698