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

Side by Side Diff: src/gpu/glsl/GrGLSLShaderBuilder.cpp

Issue 1885863004: Refactor how we store and use samplers in Ganesh (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove unneeded assert Created 4 years, 8 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 | « src/gpu/glsl/GrGLSLShaderBuilder.h ('k') | src/gpu/glsl/GrGLSLUniformHandler.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 "GrSwizzle.h" 8 #include "GrSwizzle.h"
9 #include "glsl/GrGLSLShaderBuilder.h" 9 #include "glsl/GrGLSLShaderBuilder.h"
10 #include "glsl/GrGLSLCaps.h" 10 #include "glsl/GrGLSLCaps.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (i < argCnt - 1) { 56 if (i < argCnt - 1) {
57 this->functions().append(", "); 57 this->functions().append(", ");
58 } 58 }
59 } 59 }
60 this->functions().append(") {\n"); 60 this->functions().append(") {\n");
61 this->functions().append(body); 61 this->functions().append(body);
62 this->functions().append("}\n\n"); 62 this->functions().append("}\n\n");
63 } 63 }
64 64
65 void GrGLSLShaderBuilder::appendTextureLookup(SkString* out, 65 void GrGLSLShaderBuilder::appendTextureLookup(SkString* out,
66 const GrGLSLSampler& sampler, 66 SamplerHandle samplerHandle,
67 const char* coordName, 67 const char* coordName,
68 GrSLType varyingType) const { 68 GrSLType varyingType) const {
69 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); 69 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps();
70 GrGLSLUniformHandler* uniformHandler = fProgramBuilder->uniformHandler(); 70 const GrGLSLSampler& sampler = fProgramBuilder->getSampler(samplerHandle);
71 GrSLType samplerType = uniformHandler->getUniformVariable(sampler.fSamplerUn iform).getType(); 71 GrSLType samplerType = sampler.type();
72 if (samplerType == kSampler2DRect_GrSLType) { 72 if (samplerType == kSampler2DRect_GrSLType) {
73 if (varyingType == kVec2f_GrSLType) { 73 if (varyingType == kVec2f_GrSLType) {
74 out->appendf("%s(%s, textureSize(%s) * %s)", 74 out->appendf("%s(%s, textureSize(%s) * %s)",
75 GrGLSLTexture2DFunctionName(varyingType, samplerType, 75 GrGLSLTexture2DFunctionName(varyingType, samplerType,
76 glslCaps->generation()), 76 glslCaps->generation()),
77 uniformHandler->getUniformCStr(sampler.fSamplerUniform) , 77 sampler.getSamplerNameForTexture2D(),
78 uniformHandler->getUniformCStr(sampler.fSamplerUniform) , 78 sampler.getSamplerNameForTexture2D(),
79 coordName); 79 coordName);
80 } else { 80 } else {
81 out->appendf("%s(%s, vec3(textureSize(%s) * %s.xy, %s.z))", 81 out->appendf("%s(%s, vec3(textureSize(%s) * %s.xy, %s.z))",
82 GrGLSLTexture2DFunctionName(varyingType, samplerType, 82 GrGLSLTexture2DFunctionName(varyingType, samplerType,
83 glslCaps->generation()), 83 glslCaps->generation()),
84 uniformHandler->getUniformCStr(sampler.fSamplerUniform) , 84 sampler.getSamplerNameForTexture2D(),
85 uniformHandler->getUniformCStr(sampler.fSamplerUniform) , 85 sampler.getSamplerNameForTexture2D(),
86 coordName, 86 coordName,
87 coordName); 87 coordName);
88 } 88 }
89 } else { 89 } else {
90 out->appendf("%s(%s, %s)", 90 out->appendf("%s(%s, %s)",
91 GrGLSLTexture2DFunctionName(varyingType, samplerType, glslC aps->generation()), 91 GrGLSLTexture2DFunctionName(varyingType, samplerType, glslC aps->generation()),
92 uniformHandler->getUniformCStr(sampler.fSamplerUniform), 92 sampler.getSamplerNameForTexture2D(),
93 coordName); 93 coordName);
94 } 94 }
95 95
96 this->appendTextureSwizzle(out, sampler.config()); 96 this->appendTextureSwizzle(out, sampler.config());
97 } 97 }
98 98
99 void GrGLSLShaderBuilder::appendTextureLookup(const GrGLSLSampler& sampler, 99 void GrGLSLShaderBuilder::appendTextureLookup(SamplerHandle samplerHandle,
100 const char* coordName, 100 const char* coordName,
101 GrSLType varyingType) { 101 GrSLType varyingType) {
102 this->appendTextureLookup(&this->code(), sampler, coordName, varyingType); 102 this->appendTextureLookup(&this->code(), samplerHandle, coordName, varyingTy pe);
103 } 103 }
104 104
105 void GrGLSLShaderBuilder::appendTextureLookupAndModulate(const char* modulation, 105 void GrGLSLShaderBuilder::appendTextureLookupAndModulate(const char* modulation,
106 const GrGLSLSampler& sa mpler, 106 SamplerHandle samplerHa ndle,
107 const char* coordName, 107 const char* coordName,
108 GrSLType varyingType) { 108 GrSLType varyingType) {
109 SkString lookup; 109 SkString lookup;
110 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); 110 this->appendTextureLookup(&lookup, samplerHandle, coordName, varyingType);
111 this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str()); 111 this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str());
112 } 112 }
113 113
114 void GrGLSLShaderBuilder::appendTexelFetch(SkString* out, 114 void GrGLSLShaderBuilder::appendTexelFetch(SkString* out,
115 const GrGLSLSampler& sampler, 115 SamplerHandle samplerHandle,
116 const char* coordExpr) const { 116 const char* coordExpr) const {
117 const GrGLSLUniformHandler* uniformHandler = fProgramBuilder->uniformHandler (); 117 const GrGLSLSampler& sampler = fProgramBuilder->getSampler(samplerHandle);
118 SkASSERT(fProgramBuilder->glslCaps()->texelFetchSupport()); 118 SkASSERT(fProgramBuilder->glslCaps()->texelFetchSupport());
119 SkASSERT(GrSLTypeIsSamplerType( 119 SkASSERT(GrSLTypeIsSamplerType(sampler.type()));
120 uniformHandler->getUniformVariable(sampler.fSamplerUniform).getType ()));
121 120
122 out->appendf("texelFetch(%s, %s)", 121 out->appendf("texelFetch(%s, %s)", sampler.getSamplerNameForTexelFetch(), co ordExpr);
123 uniformHandler->getUniformCStr(sampler.fSamplerUniform),
124 coordExpr);
125 122
126 this->appendTextureSwizzle(out, sampler.config()); 123 this->appendTextureSwizzle(out, sampler.config());
127 } 124 }
128 125
129 void GrGLSLShaderBuilder::appendTexelFetch(const GrGLSLSampler& sampler, const c har* coordExpr) { 126 void GrGLSLShaderBuilder::appendTexelFetch(SamplerHandle samplerHandle, const ch ar* coordExpr) {
130 this->appendTexelFetch(&this->code(), sampler, coordExpr); 127 this->appendTexelFetch(&this->code(), samplerHandle, coordExpr);
131 } 128 }
132 129
133 void GrGLSLShaderBuilder::appendTextureSwizzle(SkString* out, GrPixelConfig conf ig) const { 130 void GrGLSLShaderBuilder::appendTextureSwizzle(SkString* out, GrPixelConfig conf ig) const {
134 const GrSwizzle& configSwizzle = fProgramBuilder->glslCaps()->configTextureS wizzle(config); 131 const GrSwizzle& configSwizzle = fProgramBuilder->glslCaps()->configTextureS wizzle(config);
135 132
136 if (configSwizzle != GrSwizzle::RGBA()) { 133 if (configSwizzle != GrSwizzle::RGBA()) {
137 out->appendf(".%s", configSwizzle.c_str()); 134 out->appendf(".%s", configSwizzle.c_str());
138 } 135 }
139 } 136 }
140 137
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // append the 'footer' to code 190 // append the 'footer' to code
194 this->code().append("}"); 191 this->code().append("}");
195 192
196 for (int i = 0; i <= fCodeIndex; i++) { 193 for (int i = 0; i <= fCodeIndex; i++) {
197 fCompilerStrings[i] = fShaderStrings[i].c_str(); 194 fCompilerStrings[i] = fShaderStrings[i].c_str();
198 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); 195 fCompilerStringLengths[i] = (int)fShaderStrings[i].size();
199 } 196 }
200 197
201 fFinalized = true; 198 fFinalized = true;
202 } 199 }
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLShaderBuilder.h ('k') | src/gpu/glsl/GrGLSLUniformHandler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698