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

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

Issue 504203004: Attach GrOptDrawState into shader building pipeline (Closed) Base URL: https://skia.googlesource.com/skia.git@opt2
Patch Set: Rebase Created 6 years, 3 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/gl/GrGpuGL.cpp ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.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 2011 Google Inc. 2 * Copyright 2011 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 7
8 #include "GrGpuGL.h" 8 #include "GrGpuGL.h"
9 9
10 #include "GrEffect.h" 10 #include "GrEffect.h"
11 #include "GrGLEffect.h" 11 #include "GrGLEffect.h"
12 #include "GrGLPathRendering.h"
13 #include "GrOptDrawState.h"
12 #include "SkRTConf.h" 14 #include "SkRTConf.h"
13 #include "GrGLPathRendering.h"
14 #include "SkTSearch.h" 15 #include "SkTSearch.h"
15 16
16 #ifdef PROGRAM_CACHE_STATS 17 #ifdef PROGRAM_CACHE_STATS
17 SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false, 18 SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false,
18 "Display program cache usage."); 19 "Display program cache usage.");
19 #endif 20 #endif
20 21
21 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 22 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
22 23
23 struct GrGpuGL::ProgramCache::Entry { 24 struct GrGpuGL::ProgramCache::Entry {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 198 }
198 ++fCurrLRUStamp; 199 ++fCurrLRUStamp;
199 return entry->fProgram; 200 return entry->fProgram;
200 } 201 }
201 202
202 //////////////////////////////////////////////////////////////////////////////// 203 ////////////////////////////////////////////////////////////////////////////////
203 204
204 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) 205 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
205 206
206 bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC opy) { 207 bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC opy) {
207 const GrDrawState& drawState = this->getDrawState(); 208 SkAutoTUnref<GrOptDrawState> optState(this->getDrawState().createOptState()) ;
208 209
209 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true. 210 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
210 SkASSERT(drawState.getRenderTarget()); 211 SkASSERT(optState->getRenderTarget());
211 212
212 if (kStencilPath_DrawType == type) { 213 if (kStencilPath_DrawType == type) {
213 const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); 214 const GrRenderTarget* rt = optState->getRenderTarget();
214 SkISize size; 215 SkISize size;
215 size.set(rt->width(), rt->height()); 216 size.set(rt->width(), rt->height());
216 this->glPathRendering()->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()); 217 this->glPathRendering()->setProjectionMatrix(optState->getViewMatrix(), size, rt->origin());
217 } else { 218 } else {
218 this->flushMiscFixedFunctionState(); 219 this->flushMiscFixedFunctionState();
219 220
220 GrBlendCoeff srcCoeff; 221 GrBlendCoeff srcCoeff = optState->getSrcBlendCoeff();
221 GrBlendCoeff dstCoeff; 222 GrBlendCoeff dstCoeff = optState->getDstBlendCoeff();
222 GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &sr cCoeff, &dstCoeff); 223
223 if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) { 224 // In these blend coeff's we end up drawing nothing so we can skip draw all together
225 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
226 !optState->getStencil().doesWrite()) {
224 return false; 227 return false;
225 } 228 }
226 229
227 const GrEffectStage* geometryProcessor = NULL; 230 const GrEffectStage* geometryProcessor = NULL;
228 SkSTArray<8, const GrEffectStage*, true> colorStages; 231 SkSTArray<8, const GrEffectStage*, true> colorStages;
229 SkSTArray<8, const GrEffectStage*, true> coverageStages; 232 SkSTArray<8, const GrEffectStage*, true> coverageStages;
230 GrGLProgramDesc desc; 233 GrGLProgramDesc desc;
231 if (!GrGLProgramDesc::Build(this->getDrawState(), 234 if (!GrGLProgramDesc::Build(*optState.get(),
232 type, 235 type,
233 blendOpts,
234 srcCoeff, 236 srcCoeff,
235 dstCoeff, 237 dstCoeff,
236 this, 238 this,
237 dstCopy, 239 dstCopy,
238 &geometryProcessor, 240 &geometryProcessor,
239 &colorStages, 241 &colorStages,
240 &coverageStages, 242 &coverageStages,
241 &desc)) { 243 &desc)) {
242 SkDEBUGFAIL("Failed to generate GL program descriptor"); 244 SkDEBUGFAIL("Failed to generate GL program descriptor");
243 return false; 245 return false;
(...skipping 12 matching lines...) Expand all
256 258
257 GrGLuint programID = fCurrentProgram->programID(); 259 GrGLuint programID = fCurrentProgram->programID();
258 if (fHWProgramID != programID) { 260 if (fHWProgramID != programID) {
259 GL_CALL(UseProgram(programID)); 261 GL_CALL(UseProgram(programID));
260 fHWProgramID = programID; 262 fHWProgramID = programID;
261 } 263 }
262 264
263 fCurrentProgram->overrideBlend(&srcCoeff, &dstCoeff); 265 fCurrentProgram->overrideBlend(&srcCoeff, &dstCoeff);
264 this->flushBlend(kDrawLines_DrawType == type, srcCoeff, dstCoeff); 266 this->flushBlend(kDrawLines_DrawType == type, srcCoeff, dstCoeff);
265 267
266 fCurrentProgram->setData(type, 268 fCurrentProgram->setData(*optState.get(),
267 blendOpts, 269 type,
268 geometryProcessor, 270 geometryProcessor,
269 colorStages.begin(), 271 colorStages.begin(),
270 coverageStages.begin(), 272 coverageStages.begin(),
271 dstCopy, 273 dstCopy,
272 &fSharedGLProgramState); 274 &fSharedGLProgramState);
273 } 275 }
274 276
275 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(drawState.getRenderT arget()); 277 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState->getRenderT arget());
276 this->flushStencil(type); 278 this->flushStencil(type);
277 this->flushScissor(glRT->getViewport(), glRT->origin()); 279 this->flushScissor(glRT->getViewport(), glRT->origin());
278 this->flushAAState(type); 280 this->flushAAState(type);
279 281
280 SkIRect* devRect = NULL; 282 SkIRect* devRect = NULL;
281 SkIRect devClipBounds; 283 SkIRect devClipBounds;
282 if (drawState.isClipState()) { 284 if (optState->isClipState()) {
283 this->getClip()->getConservativeBounds(drawState.getRenderTarget(), &dev ClipBounds); 285 this->getClip()->getConservativeBounds(optState->getRenderTarget(), &dev ClipBounds);
284 devRect = &devClipBounds; 286 devRect = &devClipBounds;
285 } 287 }
286 // This must come after textures are flushed because a texture may need 288 // This must come after textures are flushed because a texture may need
287 // to be msaa-resolved (which will modify bound FBO state). 289 // to be msaa-resolved (which will modify bound FBO state).
288 this->flushRenderTarget(glRT, devRect); 290 this->flushRenderTarget(glRT, devRect);
289 291
290 return true; 292 return true;
291 } 293 }
292 294
293 void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) { 295 void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
296 SkAutoTUnref<GrOptDrawState> optState(this->getDrawState().createOptState()) ;
294 297
295 GrGLsizei stride = static_cast<GrGLsizei>(this->getDrawState().getVertexStri de()); 298 GrGLsizei stride = static_cast<GrGLsizei>(optState->getVertexStride());
296 299
297 size_t vertexOffsetInBytes = stride * info.startVertex(); 300 size_t vertexOffsetInBytes = stride * info.startVertex();
298 301
299 const GeometryPoolState& geoPoolState = this->getGeomPoolState(); 302 const GeometryPoolState& geoPoolState = this->getGeomPoolState();
300 303
301 GrGLVertexBuffer* vbuf; 304 GrGLVertexBuffer* vbuf;
302 switch (this->getGeomSrc().fVertexSrc) { 305 switch (this->getGeomSrc().fVertexSrc) {
303 case kBuffer_GeometrySrcType: 306 case kBuffer_GeometrySrcType:
304 vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer; 307 vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer;
305 break; 308 break;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 342 }
340 343
341 SkASSERT(ibuf); 344 SkASSERT(ibuf);
342 SkASSERT(!ibuf->isMapped()); 345 SkASSERT(!ibuf->isMapped());
343 *indexOffsetInBytes += ibuf->baseOffset(); 346 *indexOffsetInBytes += ibuf->baseOffset();
344 } 347 }
345 GrGLAttribArrayState* attribState = 348 GrGLAttribArrayState* attribState =
346 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); 349 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf);
347 350
348 if (fCurrentProgram->hasVertexShader()) { 351 if (fCurrentProgram->hasVertexShader()) {
349 int vertexAttribCount = this->getDrawState().getVertexAttribCount(); 352 int vertexAttribCount = optState->getVertexAttribCount();
350 uint32_t usedAttribArraysMask = 0; 353 uint32_t usedAttribArraysMask = 0;
351 const GrVertexAttrib* vertexAttrib = this->getDrawState().getVertexAttri bs(); 354 const GrVertexAttrib* vertexAttrib = optState->getVertexAttribs();
352
353 bool canIgnoreColorAttrib = this->getDrawState().canIgnoreColorAttribute ();
354 355
355 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount; 356 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount;
356 ++vertexAttribIndex, ++vertexAttrib) { 357 ++vertexAttribIndex, ++vertexAttrib) {
357
358 if (kColor_GrVertexAttribBinding != vertexAttrib->fBinding || !canIg noreColorAttrib) {
359 usedAttribArraysMask |= (1 << vertexAttribIndex); 358 usedAttribArraysMask |= (1 << vertexAttribIndex);
360 GrVertexAttribType attribType = vertexAttrib->fType; 359 GrVertexAttribType attribType = vertexAttrib->fType;
361 attribState->set(this, 360 attribState->set(this,
362 vertexAttribIndex, 361 vertexAttribIndex,
363 vbuf, 362 vbuf,
364 GrGLAttribTypeToLayout(attribType).fCount, 363 GrGLAttribTypeToLayout(attribType).fCount,
365 GrGLAttribTypeToLayout(attribType).fType, 364 GrGLAttribTypeToLayout(attribType).fType,
366 GrGLAttribTypeToLayout(attribType).fNormalized, 365 GrGLAttribTypeToLayout(attribType).fNormalized,
367 stride, 366 stride,
368 reinterpret_cast<GrGLvoid*>( 367 reinterpret_cast<GrGLvoid*>(
369 vertexOffsetInBytes + vertexAttrib->fOffset)); 368 vertexOffsetInBytes + vertexAttrib->fOffset));
370 }
371 } 369 }
372 attribState->disableUnusedArrays(this, usedAttribArraysMask); 370 attribState->disableUnusedArrays(this, usedAttribArraysMask);
373 } 371 }
374 } 372 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL.cpp ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698