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

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

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

Powered by Google App Engine
This is Rietveld 408576698