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

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

Issue 1426653008: Revert of Create swizzle table inside of glsl caps (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/gl/builders/GrGLShaderBuilder.h ('k') | src/gpu/glsl/GrGLSLCaps.h » ('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 2014 Google Inc. 2 * Copyright 2014 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 "GrGLShaderBuilder.h" 8 #include "GrGLShaderBuilder.h"
9 #include "gl/GrGLGpu.h"
9 #include "gl/builders/GrGLProgramBuilder.h" 10 #include "gl/builders/GrGLProgramBuilder.h"
10 #include "glsl/GrGLSLCaps.h" 11 #include "glsl/GrGLSLCaps.h"
11 #include "glsl/GrGLSLShaderVar.h" 12 #include "glsl/GrGLSLShaderVar.h"
12 #include "glsl/GrGLSLTextureSampler.h" 13 #include "glsl/GrGLSLTextureSampler.h"
13 14
14 static void map_swizzle(const char* swizzleMap, const char* swizzle, char* mangl edSwizzle) { 15 namespace {
15 int i; 16 void append_texture_lookup(SkString* out,
16 for (i = 0; '\0' != swizzle[i]; ++i) { 17 GrGLGpu* gpu,
17 switch (swizzle[i]) { 18 const char* samplerName,
18 case 'r': 19 const char* coordName,
19 mangledSwizzle[i] = swizzleMap[0]; 20 uint32_t configComponentMask,
20 break; 21 const char* swizzle,
21 case 'g': 22 GrSLType varyingType = kVec2f_GrSLType) {
22 mangledSwizzle[i] = swizzleMap[1];
23 break;
24 case 'b':
25 mangledSwizzle[i] = swizzleMap[2];
26 break;
27 case 'a':
28 mangledSwizzle[i] = swizzleMap[3];
29 break;
30 default:
31 SkFAIL("Unsupported swizzle");
32 }
33 }
34 mangledSwizzle[i] ='\0';
35 }
36
37 static void append_texture_lookup(SkString* out,
38 const GrGLSLCaps* glslCaps,
39 const char* samplerName,
40 const char* coordName,
41 GrPixelConfig config,
42 const char* swizzle,
43 GrSLType varyingType = kVec2f_GrSLType) {
44 SkASSERT(coordName); 23 SkASSERT(coordName);
45 24
46 out->appendf("%s(%s, %s)", 25 out->appendf("%s(%s, %s)",
47 GrGLSLTexture2DFunctionName(varyingType, glslCaps->generation() ), 26 GrGLSLTexture2DFunctionName(varyingType, gpu->glslGeneration()) ,
48 samplerName, 27 samplerName,
49 coordName); 28 coordName);
50 29
51 char mangledSwizzle[5]; 30 char mangledSwizzle[5];
52 31
53 // This refers to any swizzling we may need to get from some backend interna l format to the 32 // The swizzling occurs using texture params instead of shader-mangling if A RB_texture_swizzle
54 // format used in GrPixelConfig. Some backends will automatically do the siz zling for us. 33 // is available.
55 if (glslCaps->mustSwizzleInShader()) { 34 if (!gpu->glCaps().textureSwizzleSupport() &&
56 const char* swizzleMap = glslCaps->getSwizzleMap(config); 35 (kA_GrColorComponentFlag == configComponentMask)) {
57 // if the map is simply 'rgba' then we don't need to do any manual swizz ling to get us to 36 char alphaChar = gpu->glCaps().textureRedSupport() ? 'r' : 'a';
58 // a GrPixelConfig format. 37 int i;
59 if (memcmp(swizzleMap, "rgba", 4)) { 38 for (i = 0; '\0' != swizzle[i]; ++i) {
60 // Manually 'swizzle' the swizzle using our mapping 39 mangledSwizzle[i] = alphaChar;
61 map_swizzle(swizzleMap, swizzle, mangledSwizzle);
62 swizzle = mangledSwizzle;
63 } 40 }
41 mangledSwizzle[i] ='\0';
42 swizzle = mangledSwizzle;
64 } 43 }
65
66 // For shader prettiness we omit the swizzle rather than appending ".rgba". 44 // For shader prettiness we omit the swizzle rather than appending ".rgba".
67 if (memcmp(swizzle, "rgba", 4)) { 45 if (memcmp(swizzle, "rgba", 4)) {
68 out->appendf(".%s", swizzle); 46 out->appendf(".%s", swizzle);
69 } 47 }
70 } 48 }
49 }
71 50
72 GrGLShaderBuilder::GrGLShaderBuilder(GrGLProgramBuilder* program) 51 GrGLShaderBuilder::GrGLShaderBuilder(GrGLProgramBuilder* program)
73 : fProgramBuilder(program) 52 : fProgramBuilder(program)
74 , fInputs(GrGLProgramBuilder::kVarsPerBlock) 53 , fInputs(GrGLProgramBuilder::kVarsPerBlock)
75 , fOutputs(GrGLProgramBuilder::kVarsPerBlock) 54 , fOutputs(GrGLProgramBuilder::kVarsPerBlock)
76 , fFeaturesAddedMask(0) 55 , fFeaturesAddedMask(0)
77 , fCodeIndex(kCode) 56 , fCodeIndex(kCode)
78 , fFinalized(false) { 57 , fFinalized(false) {
79 // We push back some dummy pointers which will later become our header 58 // We push back some dummy pointers which will later become our header
80 for (int i = 0; i <= kCode; i++) { 59 for (int i = 0; i <= kCode; i++) {
(...skipping 30 matching lines...) Expand all
111 this->functions().append(") {\n"); 90 this->functions().append(") {\n");
112 this->functions().append(body); 91 this->functions().append(body);
113 this->functions().append("}\n\n"); 92 this->functions().append("}\n\n");
114 } 93 }
115 94
116 void GrGLShaderBuilder::appendTextureLookup(SkString* out, 95 void GrGLShaderBuilder::appendTextureLookup(SkString* out,
117 const GrGLSLTextureSampler& sampler, 96 const GrGLSLTextureSampler& sampler,
118 const char* coordName, 97 const char* coordName,
119 GrSLType varyingType) const { 98 GrSLType varyingType) const {
120 append_texture_lookup(out, 99 append_texture_lookup(out,
121 fProgramBuilder->glslCaps(), 100 fProgramBuilder->gpu(),
122 fProgramBuilder->getUniformCStr(sampler.fSamplerUnifor m), 101 fProgramBuilder->getUniformCStr(sampler.fSamplerUnifor m),
123 coordName, 102 coordName,
124 sampler.config(), 103 sampler.configComponentMask(),
125 sampler.swizzle(), 104 sampler.swizzle(),
126 varyingType); 105 varyingType);
127 } 106 }
128 107
129 void GrGLShaderBuilder::appendTextureLookup(const GrGLSLTextureSampler& sampler, 108 void GrGLShaderBuilder::appendTextureLookup(const GrGLSLTextureSampler& sampler,
130 const char* coordName, 109 const char* coordName,
131 GrSLType varyingType) { 110 GrSLType varyingType) {
132 this->appendTextureLookup(&this->code(), sampler, coordName, varyingType); 111 this->appendTextureLookup(&this->code(), sampler, coordName, varyingType);
133 } 112 }
134 113
(...skipping 13 matching lines...) Expand all
148 } 127 }
149 } 128 }
150 129
151 void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { 130 void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const {
152 for (int i = 0; i < vars.count(); ++i) { 131 for (int i = 0; i < vars.count(); ++i) {
153 vars[i].appendDecl(fProgramBuilder->glslCaps(), out); 132 vars[i].appendDecl(fProgramBuilder->glslCaps(), out);
154 out->append(";\n"); 133 out->append(";\n");
155 } 134 }
156 } 135 }
157 136
137 void GrGLShaderBuilder::appendTextureLookup(const char* samplerName,
138 const char* coordName,
139 uint32_t configComponentMask,
140 const char* swizzle) {
141 append_texture_lookup(&this->code(),
142 fProgramBuilder->gpu(),
143 samplerName,
144 coordName,
145 configComponentMask,
146 swizzle,
147 kVec2f_GrSLType);
148 }
149
158 void GrGLShaderBuilder::addLayoutQualifier(const char* param, InterfaceQualifier interface) { 150 void GrGLShaderBuilder::addLayoutQualifier(const char* param, InterfaceQualifier interface) {
159 SkASSERT(fProgramBuilder->glslCaps()->generation() >= k330_GrGLSLGeneration || 151 SkASSERT(fProgramBuilder->glslCaps()->generation() >= k330_GrGLSLGeneration ||
160 fProgramBuilder->glslCaps()->mustEnableAdvBlendEqs()); 152 fProgramBuilder->glslCaps()->mustEnableAdvBlendEqs());
161 fLayoutParams[interface].push_back() = param; 153 fLayoutParams[interface].push_back() = param;
162 } 154 }
163 155
164 void GrGLShaderBuilder::compileAndAppendLayoutQualifiers() { 156 void GrGLShaderBuilder::compileAndAppendLayoutQualifiers() {
165 static const char* interfaceQualifierNames[] = { 157 static const char* interfaceQualifierNames[] = {
166 "out" 158 "out"
167 }; 159 };
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 this->code().append("}"); 192 this->code().append("}");
201 193
202 for (int i = 0; i <= fCodeIndex; i++) { 194 for (int i = 0; i <= fCodeIndex; i++) {
203 fCompilerStrings[i] = fShaderStrings[i].c_str(); 195 fCompilerStrings[i] = fShaderStrings[i].c_str();
204 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); 196 fCompilerStringLengths[i] = (int)fShaderStrings[i].size();
205 } 197 }
206 198
207 fFinalized = true; 199 fFinalized = true;
208 } 200 }
209 201
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLShaderBuilder.h ('k') | src/gpu/glsl/GrGLSLCaps.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698