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

Side by Side Diff: src/gpu/gl/GrGLProgramDesc.cpp

Issue 746423007: Draft change to start pulling uniform color into GP (Closed) Base URL: https://skia.googlesource.com/skia.git@no_factories
Patch Set: rebase Created 6 years 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/gl/GrGLProgram.cpp ('k') | src/gpu/gl/builders/GrGLLegacyNvprProgramBuilder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "GrGLProgramDesc.h" 7 #include "GrGLProgramDesc.h"
8 8
9 #include "GrGLProcessor.h" 9 #include "GrGLProcessor.h"
10 #include "GrProcessor.h" 10 #include "GrProcessor.h"
(...skipping 22 matching lines...) Expand all
33 } 33 }
34 if (kRGB_GrColorComponentFlags & swizzleComponentMask) { 34 if (kRGB_GrColorComponentFlags & swizzleComponentMask) {
35 // The 'r', 'g', and/or 'b's must be mapped to 'a' according to our semantics that 35 // The 'r', 'g', and/or 'b's must be mapped to 'a' according to our semantics that
36 // alpha-only textures smear alpha across all four channels when rea d. 36 // alpha-only textures smear alpha across all four channels when rea d.
37 return true; 37 return true;
38 } 38 }
39 } 39 }
40 return false; 40 return false;
41 } 41 }
42 42
43 static uint32_t gen_attrib_key(const GrGeometryProcessor& proc) {
44 uint32_t key = 0;
45
46 const GrGeometryProcessor::VertexAttribArray& vars = proc.getAttribs();
47 int numAttributes = vars.count();
48 SkASSERT(numAttributes <= GrGeometryProcessor::kMaxVertexAttribs);
49 for (int a = 0; a < numAttributes; ++a) {
50 uint32_t value = 1 << a;
51 key |= value;
52 }
53 return key;
54 }
55
56 /** 43 /**
57 * The key for an individual coord transform is made up of a matrix type, a prec ision, and a bit 44 * The key for an individual coord transform is made up of a matrix type, a prec ision, and a bit
58 * that indicates the source of the input coords. 45 * that indicates the source of the input coords.
59 */ 46 */
60 enum { 47 enum {
61 kMatrixTypeKeyBits = 1, 48 kMatrixTypeKeyBits = 1,
62 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1, 49 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1,
63 50
64 kPrecisionBits = 2, 51 kPrecisionBits = 2,
65 kPrecisionShift = kMatrixTypeKeyBits, 52 kPrecisionShift = kMatrixTypeKeyBits,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 * be dependent on properties of the effect that the effect itself doesn't use 111 * be dependent on properties of the effect that the effect itself doesn't use
125 * in its key (e.g. the pixel format of textures used). So we create a meta-key for 112 * in its key (e.g. the pixel format of textures used). So we create a meta-key for
126 * every effect using this function. It is also responsible for inserting the ef fect's class ID 113 * every effect using this function. It is also responsible for inserting the ef fect's class ID
127 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many 114 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many
128 * textures, transforms, etc, for the space allotted in the meta-key. NOTE, bot h FPs and GPs share 115 * textures, transforms, etc, for the space allotted in the meta-key. NOTE, bot h FPs and GPs share
129 * this function because it is hairy, though FPs do not have attribs, and GPs do not have transforms 116 * this function because it is hairy, though FPs do not have attribs, and GPs do not have transforms
130 */ 117 */
131 static bool get_meta_key(const GrProcessor& proc, 118 static bool get_meta_key(const GrProcessor& proc,
132 const GrGLCaps& caps, 119 const GrGLCaps& caps,
133 uint32_t transformKey, 120 uint32_t transformKey,
134 uint32_t attribKey,
135 GrProcessorKeyBuilder* b) { 121 GrProcessorKeyBuilder* b) {
136 size_t processorKeySize = b->size(); 122 size_t processorKeySize = b->size();
137 uint32_t textureKey = gen_texture_key(proc, caps); 123 uint32_t textureKey = gen_texture_key(proc, caps);
138 uint32_t classID = proc.classID(); 124 uint32_t classID = proc.classID();
139 125
140 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they 126 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they
141 // don't fit. 127 // don't fit.
142 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); 128 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16);
143 if ((textureKey | transformKey | classID) & kMetaKeyInvalidMask) { 129 if ((textureKey | transformKey | classID) & kMetaKeyInvalidMask) {
144 return false; 130 return false;
145 } 131 }
146 if (processorKeySize > SK_MaxU16) { 132 if (processorKeySize > SK_MaxU16) {
147 return false; 133 return false;
148 } 134 }
149 135
150 uint32_t* key = b->add32n(2); 136 uint32_t* key = b->add32n(2);
151 key[0] = (textureKey << 16 | transformKey); 137 key[0] = (textureKey << 16 | transformKey);
152 key[1] = (classID << 16 | SkToU16(processorKeySize)); 138 key[1] = (classID << 16 | SkToU16(processorKeySize));
153 return true; 139 return true;
154 } 140 }
155 141
156 bool GrGLProgramDescBuilder::Build(const GrOptDrawState& optState, 142 bool GrGLProgramDescBuilder::Build(const GrOptDrawState& optState,
157 const GrProgramDesc::DescInfo& descInfo, 143 const GrProgramDesc::DescInfo& descInfo,
158 GrGpu::DrawType drawType, 144 GrGpu::DrawType drawType,
159 GrGpuGL* gpu, 145 GrGpuGL* gpu,
160 GrProgramDesc* desc) { 146 GrProgramDesc* desc) {
161 bool inputColorIsUsed = descInfo.fInputColorIsUsed;
162 bool inputCoverageIsUsed = descInfo.fInputCoverageIsUsed;
163
164 // The descriptor is used as a cache key. Thus when a field of the 147 // The descriptor is used as a cache key. Thus when a field of the
165 // descriptor will not affect program generation (because of the attribute 148 // descriptor will not affect program generation (because of the attribute
166 // bindings in use or other descriptor field settings) it should be set 149 // bindings in use or other descriptor field settings) it should be set
167 // to a canonical value to avoid duplicate programs with different keys. 150 // to a canonical value to avoid duplicate programs with different keys.
168 151
169 bool requiresLocalCoordAttrib = descInfo.fRequiresLocalCoordAttrib; 152 bool requiresLocalCoordAttrib = descInfo.fRequiresLocalCoordAttrib;
170 153
171 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); 154 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t));
172 // Make room for everything up to the effect keys. 155 // Make room for everything up to the effect keys.
173 desc->fKey.reset(); 156 desc->fKey.reset();
174 desc->fKey.push_back_n(kProcessorKeysOffset); 157 desc->fKey.push_back_n(kProcessorKeysOffset);
175 158
176 // We can only have one effect which touches the vertex shader 159 GrProcessorKeyBuilder b(&desc->fKey);
177 if (optState.hasGeometryProcessor()) { 160
178 const GrGeometryProcessor& gp = *optState.getGeometryProcessor(); 161 const GrPrimitiveProcessor& primProc = *optState.getPrimitiveProcessor();
179 GrProcessorKeyBuilder b(&desc->fKey); 162 primProc.getGLProcessorKey(optState.getBatchTracker(), gpu->glCaps(), &b);
180 gp.getGLProcessorKey(optState.getBatchTracker(), gpu->glCaps(), &b); 163 if (!get_meta_key(primProc, gpu->glCaps(), 0, &b)) {
181 if (!get_meta_key(gp, gpu->glCaps(), 0, gen_attrib_key(gp), &b)) { 164 desc->fKey.reset();
182 desc->fKey.reset(); 165 return false;
183 return false;
184 }
185 } 166 }
186 167
187 for (int s = 0; s < optState.numFragmentStages(); ++s) { 168 for (int s = 0; s < optState.numFragmentStages(); ++s) {
188 const GrPendingFragmentStage& fps = optState.getFragmentStage(s); 169 const GrPendingFragmentStage& fps = optState.getFragmentStage(s);
189 const GrFragmentProcessor& fp = *fps.getProcessor(); 170 const GrFragmentProcessor& fp = *fps.getProcessor();
190 GrProcessorKeyBuilder b(&desc->fKey);
191 fp.getGLProcessorKey(gpu->glCaps(), &b); 171 fp.getGLProcessorKey(gpu->glCaps(), &b);
192 if (!get_meta_key(fp, gpu->glCaps(), 172 if (!get_meta_key(fp, gpu->glCaps(),
193 gen_transform_key(fps, requiresLocalCoordAttrib), 0, & b)) { 173 gen_transform_key(fps, requiresLocalCoordAttrib), &b)) {
194 desc->fKey.reset(); 174 desc->fKey.reset();
195 return false; 175 return false;
196 } 176 }
197 } 177 }
198 178
199 const GrXferProcessor& xp = *optState.getXferProcessor(); 179 const GrXferProcessor& xp = *optState.getXferProcessor();
200 GrProcessorKeyBuilder b(&desc->fKey);
201 xp.getGLProcessorKey(gpu->glCaps(), &b); 180 xp.getGLProcessorKey(gpu->glCaps(), &b);
202 if (!get_meta_key(xp, gpu->glCaps(), 0, 0, &b)) { 181 if (!get_meta_key(xp, gpu->glCaps(), 0, &b)) {
203 desc->fKey.reset(); 182 desc->fKey.reset();
204 return false; 183 return false;
205 } 184 }
206 185
207 // --------DO NOT MOVE HEADER ABOVE THIS LINE------------------------------- ------------------- 186 // --------DO NOT MOVE HEADER ABOVE THIS LINE------------------------------- -------------------
208 // Because header is a pointer into the dynamic array, we can't push any new data into the key 187 // Because header is a pointer into the dynamic array, we can't push any new data into the key
209 // below here. 188 // below here.
210 GLKeyHeader* header = desc->atOffset<GLKeyHeader, kHeaderOffset>(); 189 GLKeyHeader* header = desc->atOffset<GLKeyHeader, kHeaderOffset>();
211 190
212 // make sure any padding in the header is zeroed. 191 // make sure any padding in the header is zeroed.
213 memset(header, 0, kHeaderSize); 192 memset(header, 0, kHeaderSize);
214 193
215 header->fHasGeometryProcessor = optState.hasGeometryProcessor();
216
217 bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); 194 bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType);
218 if (gpu->caps()->pathRenderingSupport() && isPathRendering) { 195 if (gpu->caps()->pathRenderingSupport() && isPathRendering) {
219 header->fUseNvpr = true; 196 header->fUseNvpr = true;
220 SkASSERT(!optState.hasGeometryProcessor()); 197 SkASSERT(!optState.hasGeometryProcessor());
221 } else { 198 } else {
222 header->fUseNvpr = false; 199 header->fUseNvpr = false;
223 } 200 }
224 201
225 bool hasUniformColor = inputColorIsUsed && (isPathRendering || !descInfo.fHa sVertexColor);
226
227 if (!inputColorIsUsed) {
228 header->fColorInput = GrProgramDesc::kAllOnes_ColorInput;
229 } else if (hasUniformColor) {
230 header->fColorInput = GrProgramDesc::kUniform_ColorInput;
231 } else {
232 header->fColorInput = GrProgramDesc::kAttribute_ColorInput;
233 SkASSERT(!header->fUseNvpr);
234 }
235
236 bool hasVertexCoverage = !isPathRendering && descInfo.fHasVertexCoverage;
237
238 bool covIsSolidWhite = !hasVertexCoverage && 0xffffffff == optState.getCover ageColor();
239
240 if (covIsSolidWhite || !inputCoverageIsUsed) {
241 header->fCoverageInput = GrProgramDesc::kAllOnes_ColorInput;
242 } else if (!hasVertexCoverage) {
243 header->fCoverageInput = GrProgramDesc::kUniform_ColorInput;
244 } else {
245 header->fCoverageInput = GrProgramDesc::kAttribute_ColorInput;
246 SkASSERT(!header->fUseNvpr);
247 }
248
249 if (descInfo.fReadsDst) { 202 if (descInfo.fReadsDst) {
250 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); 203 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy();
251 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); 204 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport());
252 const GrTexture* dstCopyTexture = NULL; 205 const GrTexture* dstCopyTexture = NULL;
253 if (dstCopy) { 206 if (dstCopy) {
254 dstCopyTexture = dstCopy->texture(); 207 dstCopyTexture = dstCopy->texture();
255 } 208 }
256 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe xture, 209 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe xture,
257 gpu->glCa ps()); 210 gpu->glCa ps());
258 SkASSERT(0 != header->fDstReadKey); 211 SkASSERT(0 != header->fDstReadKey);
259 } else { 212 } else {
260 header->fDstReadKey = 0; 213 header->fDstReadKey = 0;
261 } 214 }
262 215
263 if (descInfo.fReadsFragPosition) { 216 if (descInfo.fReadsFragPosition) {
264 header->fFragPosKey = 217 header->fFragPosKey =
265 GrGLFragmentShaderBuilder::KeyForFragmentPosition(optState.getRe nderTarget(), 218 GrGLFragmentShaderBuilder::KeyForFragmentPosition(optState.getRe nderTarget(),
266 gpu->glCaps()) ; 219 gpu->glCaps()) ;
267 } else { 220 } else {
268 header->fFragPosKey = 0; 221 header->fFragPosKey = 0;
269 } 222 }
270 223
271 header->fColorEffectCnt = optState.numColorStages(); 224 header->fColorEffectCnt = optState.numColorStages();
272 header->fCoverageEffectCnt = optState.numCoverageStages(); 225 header->fCoverageEffectCnt = optState.numCoverageStages();
273 desc->finalize(); 226 desc->finalize();
274 return true; 227 return true;
275 } 228 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgram.cpp ('k') | src/gpu/gl/builders/GrGLLegacyNvprProgramBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698