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

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

Issue 1756583002: Pack float array uniforms into vec4 arrays (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Some cleanup Created 4 years, 9 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 | « no previous file | src/gpu/effects/GrMatrixConvolutionEffect.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 28 matching lines...) Expand all
39 kVec2f_GrSLType, kDefault_Gr SLPrecision, 39 kVec2f_GrSLType, kDefault_Gr SLPrecision,
40 "ImageIncrement"); 40 "ImageIncrement");
41 if (ce.useBounds()) { 41 if (ce.useBounds()) {
42 fBoundsUni = uniformHandler->addUniform(kFragment_GrShaderFlag, 42 fBoundsUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
43 kVec2f_GrSLType, kDefault_GrSLPr ecision, 43 kVec2f_GrSLType, kDefault_GrSLPr ecision,
44 "Bounds"); 44 "Bounds");
45 } 45 }
46 46
47 int width = Gr1DKernelEffect::WidthFromRadius(ce.radius()); 47 int width = Gr1DKernelEffect::WidthFromRadius(ce.radius());
48 48
49 int arrayCount = (width + 3) / 4;
50 SkASSERT(4 * arrayCount >= width);
51
49 fKernelUni = uniformHandler->addUniformArray(kFragment_GrShaderFlag, 52 fKernelUni = uniformHandler->addUniformArray(kFragment_GrShaderFlag,
50 kFloat_GrSLType, kDefault_GrSLP recision, 53 kVec4f_GrSLType, kDefault_GrSLP recision,
51 "Kernel", width); 54 "Kernel", arrayCount);
52 55
53 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 56 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
54 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0); 57 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
55 58
56 fragBuilder->codeAppendf("%s = vec4(0, 0, 0, 0);", args.fOutputColor); 59 fragBuilder->codeAppendf("%s = vec4(0, 0, 0, 0);", args.fOutputColor);
57 60
58 const GrGLSLShaderVar& kernel = uniformHandler->getUniformVariable(fKernelUn i); 61 const GrGLSLShaderVar& kernel = uniformHandler->getUniformVariable(fKernelUn i);
59 const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); 62 const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
60 63
61 fragBuilder->codeAppendf("vec2 coord = %s - %d.0 * %s;", coords2D.c_str(), c e.radius(), imgInc); 64 fragBuilder->codeAppendf("vec2 coord = %s - %d.0 * %s;", coords2D.c_str(), c e.radius(), imgInc);
62 65
63 // Manually unroll loop because some drivers don't; yields 20-30% speedup. 66 // Manually unroll loop because some drivers don't; yields 20-30% speedup.
67 const char* kVecSuffix[4] = { ".x", ".y", ".z", ".w" };
64 for (int i = 0; i < width; i++) { 68 for (int i = 0; i < width; i++) {
65 SkString index; 69 SkString index;
66 SkString kernelIndex; 70 SkString kernelIndex;
67 index.appendS32(i); 71 index.appendS32(i/4);
68 kernel.appendArrayAccess(index.c_str(), &kernelIndex); 72 kernel.appendArrayAccess(index.c_str(), &kernelIndex);
73 kernelIndex.append(kVecSuffix[i & 0x3]);
69 74
70 if (ce.useBounds()) { 75 if (ce.useBounds()) {
71 // We used to compute a bool indicating whether we're in bounds or n ot, cast it to a 76 // We used to compute a bool indicating whether we're in bounds or n ot, cast it to a
72 // float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems 77 // float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems
73 // to have a bug that caused corruption. 78 // to have a bug that caused corruption.
74 const char* bounds = uniformHandler->getUniformCStr(fBoundsUni); 79 const char* bounds = uniformHandler->getUniformCStr(fBoundsUni);
75 const char* component = ce.direction() == Gr1DKernelEffect::kY_Direc tion ? "y" : "x"; 80 const char* component = ce.direction() == Gr1DKernelEffect::kY_Direc tion ? "y" : "x";
76 fragBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {", 81 fragBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {",
77 component, bounds, component, bounds); 82 component, bounds, component, bounds);
78 } 83 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const float* bounds = conv.bounds(); 117 const float* bounds = conv.bounds();
113 if (Gr1DKernelEffect::kY_Direction == conv.direction() && 118 if (Gr1DKernelEffect::kY_Direction == conv.direction() &&
114 texture.origin() != kTopLeft_GrSurfaceOrigin) { 119 texture.origin() != kTopLeft_GrSurfaceOrigin) {
115 pdman.set2f(fBoundsUni, 1.0f - bounds[1], 1.0f - bounds[0]); 120 pdman.set2f(fBoundsUni, 1.0f - bounds[1], 1.0f - bounds[0]);
116 } else { 121 } else {
117 pdman.set2f(fBoundsUni, bounds[0], bounds[1]); 122 pdman.set2f(fBoundsUni, bounds[0], bounds[1]);
118 } 123 }
119 } 124 }
120 int width = Gr1DKernelEffect::WidthFromRadius(conv.radius()); 125 int width = Gr1DKernelEffect::WidthFromRadius(conv.radius());
121 126
122 pdman.set1fv(fKernelUni, width, conv.kernel()); 127 int arrayCount = (width + 3) / 4;
128 SkASSERT(4 * arrayCount >= width);
129 pdman.set4fv(fKernelUni, arrayCount, conv.kernel());
123 } 130 }
124 131
125 void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrGLSLCap s&, 132 void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrGLSLCap s&,
126 GrProcessorKeyBuilder* b) { 133 GrProcessorKeyBuilder* b) {
127 const GrConvolutionEffect& conv = processor.cast<GrConvolutionEffect>(); 134 const GrConvolutionEffect& conv = processor.cast<GrConvolutionEffect>();
128 uint32_t key = conv.radius(); 135 uint32_t key = conv.radius();
129 key <<= 2; 136 key <<= 2;
130 if (conv.useBounds()) { 137 if (conv.useBounds()) {
131 key |= 0x2; 138 key |= 0x2;
132 key |= GrConvolutionEffect::kY_Direction == conv.direction() ? 0x1 : 0x0 ; 139 key |= GrConvolutionEffect::kY_Direction == conv.direction() ? 0x1 : 0x0 ;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 228 }
222 229
223 bool useBounds = d->fRandom->nextBool(); 230 bool useBounds = d->fRandom->nextBool();
224 return GrConvolutionEffect::Create(d->fTextures[texIdx], 231 return GrConvolutionEffect::Create(d->fTextures[texIdx],
225 dir, 232 dir,
226 radius, 233 radius,
227 kernel, 234 kernel,
228 useBounds, 235 useBounds,
229 bounds); 236 bounds);
230 } 237 }
OLDNEW
« no previous file with comments | « no previous file | src/gpu/effects/GrMatrixConvolutionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698