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

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

Issue 14633007: Key shader on whether frag pos read is relative to top-left or bottom-left (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: address comments Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | tests/GLProgramsTest.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 2012 Google Inc. 2 * Copyright 2012 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 "gl/GrGLShaderBuilder.h" 8 #include "gl/GrGLShaderBuilder.h"
9 #include "gl/GrGLProgram.h" 9 #include "gl/GrGLProgram.h"
10 #include "gl/GrGLUniformHandle.h" 10 #include "gl/GrGLUniformHandle.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 , fUniformManager(uniformManager) 105 , fUniformManager(uniformManager)
106 , fFSFeaturesAddedMask(0) 106 , fFSFeaturesAddedMask(0)
107 #if GR_GL_EXPERIMENTAL_GS 107 #if GR_GL_EXPERIMENTAL_GS
108 , fUsesGS(desc.fExperimentalGS) 108 , fUsesGS(desc.fExperimentalGS)
109 #else 109 #else
110 , fUsesGS(false) 110 , fUsesGS(false)
111 #endif 111 #endif
112 , fSetupFragPosition(false) 112 , fSetupFragPosition(false)
113 , fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle) 113 , fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle)
114 , fDstCopyTopLeftUniform (GrGLUniformManager::kInvalidUniformHandle) 114 , fDstCopyTopLeftUniform (GrGLUniformManager::kInvalidUniformHandle)
115 , fDstCopyScaleUniform (GrGLUniformManager::kInvalidUniformHandle) { 115 , fDstCopyScaleUniform (GrGLUniformManager::kInvalidUniformHandle)
116 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.fFragPosKey) {
116 117
117 fPositionVar = &fVSAttrs.push_back(); 118 fPositionVar = &fVSAttrs.push_back();
118 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, " aPosition"); 119 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, " aPosition");
119 if (-1 != desc.fLocalCoordAttributeIndex) { 120 if (-1 != desc.fLocalCoordAttributeIndex) {
120 fLocalCoordsVar = &fVSAttrs.push_back(); 121 fLocalCoordsVar = &fVSAttrs.push_back();
121 fLocalCoordsVar->set(kVec2f_GrSLType, 122 fLocalCoordsVar->set(kVec2f_GrSLType,
122 GrGLShaderVar::kAttribute_TypeModifier, 123 GrGLShaderVar::kAttribute_TypeModifier,
123 "aLocalCoords"); 124 "aLocalCoords");
124 } else { 125 } else {
125 fLocalCoordsVar = fPositionVar; 126 fLocalCoordsVar = fPositionVar;
126 } 127 }
127 // Emit code to read the dst copy textue if necessary. 128 // Emit code to read the dst copy textue if necessary.
128 if (kNoDstRead_DstReadKey != desc.fDstRead && 129 if (kNoDstRead_DstReadKey != desc.fDstReadKey &&
129 GrGLCaps::kNone_FBFetchType == ctxInfo.caps()->fbFetchType()) { 130 GrGLCaps::kNone_FBFetchType == ctxInfo.caps()->fbFetchType()) {
130 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & desc.fDstRead); 131 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & desc.fDstReadKey) ;
131 const char* dstCopyTopLeftName; 132 const char* dstCopyTopLeftName;
132 const char* dstCopyCoordScaleName; 133 const char* dstCopyCoordScaleName;
133 uint32_t configMask; 134 uint32_t configMask;
134 if (SkToBool(kUseAlphaConfig_DstReadKeyBit & desc.fDstRead)) { 135 if (SkToBool(kUseAlphaConfig_DstReadKeyBit & desc.fDstReadKey)) {
135 configMask = kA_GrColorComponentFlag; 136 configMask = kA_GrColorComponentFlag;
136 } else { 137 } else {
137 configMask = kRGBA_GrColorComponentFlags; 138 configMask = kRGBA_GrColorComponentFlags;
138 } 139 }
139 fDstCopySampler.init(this, configMask, "rgba", 0); 140 fDstCopySampler.init(this, configMask, "rgba", 0);
140 141
141 fDstCopyTopLeftUniform = this->addUniform(kFragment_ShaderType, 142 fDstCopyTopLeftUniform = this->addUniform(kFragment_ShaderType,
142 kVec2f_GrSLType, 143 kVec2f_GrSLType,
143 "DstCopyUpperLeft", 144 "DstCopyUpperLeft",
144 &dstCopyTopLeftName); 145 &dstCopyTopLeftName);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // The fact that the config is alpha-only must be considered when genera ting code. 345 // The fact that the config is alpha-only must be considered when genera ting code.
345 key |= kUseAlphaConfig_DstReadKeyBit; 346 key |= kUseAlphaConfig_DstReadKeyBit;
346 } 347 }
347 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { 348 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) {
348 key |= kTopLeftOrigin_DstReadKeyBit; 349 key |= kTopLeftOrigin_DstReadKeyBit;
349 } 350 }
350 GrAssert(static_cast<DstReadKey>(key) == key); 351 GrAssert(static_cast<DstReadKey>(key) == key);
351 return static_cast<DstReadKey>(key); 352 return static_cast<DstReadKey>(key);
352 } 353 }
353 354
355 GrGLShaderBuilder::FragPosKey GrGLShaderBuilder::KeyForFragmentPosition(const Gr RenderTarget* dst,
356 const Gr GLCaps&) {
357 if (kTopLeft_GrSurfaceOrigin == dst->origin()) {
358 return kTopLeftFragPosRead_FragPosKey;
359 } else {
360 return kBottomLeftFragPosRead_FragPosKey;
361 }
362 }
363
364
354 const GrGLenum* GrGLShaderBuilder::GetTexParamSwizzle(GrPixelConfig config, cons t GrGLCaps& caps) { 365 const GrGLenum* GrGLShaderBuilder::GetTexParamSwizzle(GrPixelConfig config, cons t GrGLCaps& caps) {
355 if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) { 366 if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) {
356 if (caps.textureRedSupport()) { 367 if (caps.textureRedSupport()) {
357 static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RE D, GR_GL_RED }; 368 static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RE D, GR_GL_RED };
358 return gRedSmear; 369 return gRedSmear;
359 } else { 370 } else {
360 static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA, 371 static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA,
361 GR_GL_ALPHA, GR_GL_ALPHA }; 372 GR_GL_ALPHA, GR_GL_ALPHA };
362 return gAlphaSmear; 373 return gAlphaSmear;
363 } 374 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 477
467 const char* GrGLShaderBuilder::fragmentPosition() { 478 const char* GrGLShaderBuilder::fragmentPosition() {
468 if (fCodeStage.inStageCode()) { 479 if (fCodeStage.inStageCode()) {
469 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); 480 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect();
470 if (!effect->willReadFragmentPosition()) { 481 if (!effect->willReadFragmentPosition()) {
471 GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect " 482 GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect "
472 "did not request access."); 483 "did not request access.");
473 return ""; 484 return "";
474 } 485 }
475 } 486 }
476 #if 1 487 if (fTopLeftFragPosRead) {
477 if (fCtxInfo.caps()->fragCoordConventionsSupport()) { 488 if (!fSetupFragPosition) {
489 fFSInputs.push_back().set(kVec4f_GrSLType,
490 GrGLShaderVar::kIn_TypeModifier,
491 "gl_FragCoord",
492 GrGLShaderVar::kDefault_Precision);
493 fSetupFragPosition = true;
494 }
495 return "gl_FragCoord";
496 } else if (fCtxInfo.caps()->fragCoordConventionsSupport()) {
478 if (!fSetupFragPosition) { 497 if (!fSetupFragPosition) {
479 SkAssertResult(this->enablePrivateFeature(kFragCoordConventions_GLSL PrivateFeature)); 498 SkAssertResult(this->enablePrivateFeature(kFragCoordConventions_GLSL PrivateFeature));
480 fFSInputs.push_back().set(kVec4f_GrSLType, 499 fFSInputs.push_back().set(kVec4f_GrSLType,
481 GrGLShaderVar::kIn_TypeModifier, 500 GrGLShaderVar::kIn_TypeModifier,
482 "gl_FragCoord", 501 "gl_FragCoord",
483 GrGLShaderVar::kDefault_Precision, 502 GrGLShaderVar::kDefault_Precision,
484 GrGLShaderVar::kUpperLeft_Origin); 503 GrGLShaderVar::kUpperLeft_Origin);
485 fSetupFragPosition = true; 504 fSetupFragPosition = true;
486 } 505 }
487 return "gl_FragCoord"; 506 return "gl_FragCoord";
(...skipping 11 matching lines...) Expand all
499 "RTHeight", 518 "RTHeight",
500 &rtHeightName); 519 &rtHeightName);
501 520
502 this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_Fra gCoord.y, gl_FragCoord.zw);\n", 521 this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_Fra gCoord.y, gl_FragCoord.zw);\n",
503 kCoordName, rtHeightName); 522 kCoordName, rtHeightName);
504 fSetupFragPosition = true; 523 fSetupFragPosition = true;
505 } 524 }
506 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fRTHeightUniform); 525 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fRTHeightUniform);
507 return kCoordName; 526 return kCoordName;
508 } 527 }
509 #else
510 // This is the path we'll need to use once we have support for TopLeft
511 // render targets.
512 if (!fSetupFragPosition) {
513 fFSInputs.push_back().set(kVec4f_GrSLType,
514 GrGLShaderVar::kIn_TypeModifier,
515 "gl_FragCoord",
516 GrGLShaderVar::kDefault_Precision);
517 fSetupFragPosition = true;
518 }
519 return "gl_FragCoord";
520 #endif
521 } 528 }
522 529
523 530
524 void GrGLShaderBuilder::emitFunction(ShaderType shader, 531 void GrGLShaderBuilder::emitFunction(ShaderType shader,
525 GrSLType returnType, 532 GrSLType returnType,
526 const char* name, 533 const char* name,
527 int argCnt, 534 int argCnt,
528 const GrGLShaderVar* args, 535 const GrGLShaderVar* args,
529 const char* body, 536 const char* body,
530 SkString* outName) { 537 SkString* outName) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 for (const AttributePair* attrib = this->getEffectAttributes().begin(); 729 for (const AttributePair* attrib = this->getEffectAttributes().begin();
723 attrib != attribEnd; 730 attrib != attribEnd;
724 ++attrib) { 731 ++attrib) {
725 if (attrib->fIndex == attributeIndex) { 732 if (attrib->fIndex == attributeIndex) {
726 return &attrib->fName; 733 return &attrib->fName;
727 } 734 }
728 } 735 }
729 736
730 return NULL; 737 return NULL;
731 } 738 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | tests/GLProgramsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698