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

Side by Side Diff: src/gpu/effects/GrConvolutionEffect.cpp

Issue 1457543003: Add ShaderBuilders to EmitArgs and remove gettings from ProgBuilder. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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/effects/GrConvexPolyEffect.cpp ('k') | src/gpu/effects/GrCoverageSetOpXP.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 "GrConvolutionEffect.h" 8 #include "GrConvolutionEffect.h"
9 #include "glsl/GrGLSLFragmentProcessor.h" 9 #include "glsl/GrGLSLFragmentProcessor.h"
10 #include "glsl/GrGLSLFragmentShaderBuilder.h" 10 #include "glsl/GrGLSLFragmentShaderBuilder.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 "ImageIncrement"); 53 "ImageIncrement");
54 if (this->useBounds()) { 54 if (this->useBounds()) {
55 fBoundsUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_V isibility, 55 fBoundsUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_V isibility,
56 kVec2f_GrSLType, kDefault_GrSLPrecision , 56 kVec2f_GrSLType, kDefault_GrSLPrecision ,
57 "Bounds"); 57 "Bounds");
58 } 58 }
59 fKernelUni = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_ Visibility, 59 fKernelUni = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_ Visibility,
60 kFloat_GrSLType, kDefault_GrSLPrecisio n, 60 kFloat_GrSLType, kDefault_GrSLPrecisio n,
61 "Kernel", this->width()); 61 "Kernel", this->width());
62 62
63 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder() ; 63 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
64 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); 64 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
65 65
66 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor); 66 fragBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor);
67 67
68 int width = this->width(); 68 int width = this->width();
69 const GrGLSLShaderVar& kernel = args.fBuilder->getUniformVariable(fKernelUni ); 69 const GrGLSLShaderVar& kernel = args.fBuilder->getUniformVariable(fKernelUni );
70 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni); 70 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni);
71 71
72 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str( ), fRadius, imgInc); 72 fragBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_st r(), fRadius, imgInc);
73 73
74 // Manually unroll loop because some drivers don't; yields 20-30% speedup. 74 // Manually unroll loop because some drivers don't; yields 20-30% speedup.
75 for (int i = 0; i < width; i++) { 75 for (int i = 0; i < width; i++) {
76 SkString index; 76 SkString index;
77 SkString kernelIndex; 77 SkString kernelIndex;
78 index.appendS32(i); 78 index.appendS32(i);
79 kernel.appendArrayAccess(index.c_str(), &kernelIndex); 79 kernel.appendArrayAccess(index.c_str(), &kernelIndex);
80 80
81 if (this->useBounds()) { 81 if (this->useBounds()) {
82 // We used to compute a bool indicating whether we're in bounds or n ot, cast it to a 82 // We used to compute a bool indicating whether we're in bounds or n ot, cast it to a
83 // float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems 83 // float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems
84 // to have a bug that caused corruption. 84 // to have a bug that caused corruption.
85 const char* bounds = args.fBuilder->getUniformCStr(fBoundsUni); 85 const char* bounds = args.fBuilder->getUniformCStr(fBoundsUni);
86 const char* component = this->direction() == Gr1DKernelEffect::kY_Di rection ? "y" : "x"; 86 const char* component = this->direction() == Gr1DKernelEffect::kY_Di rection ? "y" : "x";
87 fsBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {" , 87 fragBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {",
88 component, bounds, component, bounds); 88 component, bounds, component, bounds);
89 } 89 }
90 fsBuilder->codeAppendf("\t\t%s += ", args.fOutputColor); 90 fragBuilder->codeAppendf("\t\t%s += ", args.fOutputColor);
91 fsBuilder->appendTextureLookup(args.fSamplers[0], "coord"); 91 fragBuilder->appendTextureLookup(args.fSamplers[0], "coord");
92 fsBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str()); 92 fragBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str());
93 if (this->useBounds()) { 93 if (this->useBounds()) {
94 fsBuilder->codeAppend("}"); 94 fragBuilder->codeAppend("}");
95 } 95 }
96 fsBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc); 96 fragBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc);
97 } 97 }
98 98
99 SkString modulate; 99 SkString modulate;
100 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); 100 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
101 fsBuilder->codeAppend(modulate.c_str()); 101 fragBuilder->codeAppend(modulate.c_str());
102 } 102 }
103 103
104 void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman, 104 void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
105 const GrProcessor& processor) { 105 const GrProcessor& processor) {
106 const GrConvolutionEffect& conv = processor.cast<GrConvolutionEffect>(); 106 const GrConvolutionEffect& conv = processor.cast<GrConvolutionEffect>();
107 GrTexture& texture = *conv.texture(0); 107 GrTexture& texture = *conv.texture(0);
108 // the code we generated was for a specific kernel radius 108 // the code we generated was for a specific kernel radius
109 SkASSERT(conv.radius() == fRadius); 109 SkASSERT(conv.radius() == fRadius);
110 float imageIncrement[2] = { 0 }; 110 float imageIncrement[2] = { 0 };
111 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; 111 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 231 }
232 232
233 bool useBounds = d->fRandom->nextBool(); 233 bool useBounds = d->fRandom->nextBool();
234 return GrConvolutionEffect::Create(d->fTextures[texIdx], 234 return GrConvolutionEffect::Create(d->fTextures[texIdx],
235 dir, 235 dir,
236 radius, 236 radius,
237 kernel, 237 kernel,
238 useBounds, 238 useBounds,
239 bounds); 239 bounds);
240 } 240 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConvexPolyEffect.cpp ('k') | src/gpu/effects/GrCoverageSetOpXP.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698