OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "glsl/GrGLSLProgramBuilder.h" | 8 #include "glsl/GrGLSLProgramBuilder.h" |
9 | 9 |
10 #include "GrPipeline.h" | 10 #include "GrPipeline.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 proc, | 92 proc, |
93 outputColor->c_str(), | 93 outputColor->c_str(), |
94 outputCoverage->c_str(), | 94 outputCoverage->c_str(), |
95 samplers, | 95 samplers, |
96 fCoordTransforms, | 96 fCoordTransforms, |
97 &fOutCoords); | 97 &fOutCoords); |
98 fGeometryProcessor->emitCode(args); | 98 fGeometryProcessor->emitCode(args); |
99 | 99 |
100 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 100 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
101 // asks for dst color, then the emit code needs to follow suit | 101 // asks for dst color, then the emit code needs to follow suit |
102 verify(proc); | 102 SkDEBUGCODE(verify(proc);) |
103 | 103 |
104 fFS.codeAppend("}"); | 104 fFS.codeAppend("}"); |
105 } | 105 } |
106 | 106 |
107 void GrGLSLProgramBuilder::emitAndInstallFragProcs(int procOffset, | 107 void GrGLSLProgramBuilder::emitAndInstallFragProcs(int procOffset, |
108 int numProcs, | 108 int numProcs, |
109 GrGLSLExpr4* inOut) { | 109 GrGLSLExpr4* inOut) { |
110 for (int i = procOffset; i < numProcs; ++i) { | 110 for (int i = procOffset; i < numProcs; ++i) { |
111 GrGLSLExpr4 output; | 111 GrGLSLExpr4 output; |
112 const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i)
; | 112 const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i)
; |
(...skipping 27 matching lines...) Expand all Loading... |
140 this->glslCaps(), | 140 this->glslCaps(), |
141 fp, | 141 fp, |
142 output->c_str(), | 142 output->c_str(), |
143 input.isOnes() ? nullptr : input.c_st
r(), | 143 input.isOnes() ? nullptr : input.c_st
r(), |
144 fOutCoords[index], | 144 fOutCoords[index], |
145 samplers); | 145 samplers); |
146 fragProc->emitCode(args); | 146 fragProc->emitCode(args); |
147 | 147 |
148 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 148 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
149 // asks for dst color, then the emit code needs to follow suit | 149 // asks for dst color, then the emit code needs to follow suit |
150 verify(fp); | 150 SkDEBUGCODE(verify(fp);) |
151 fFragmentProcessors.push_back(fragProc); | 151 fFragmentProcessors.push_back(fragProc); |
152 | 152 |
153 fFS.codeAppend("}"); | 153 fFS.codeAppend("}"); |
154 } | 154 } |
155 | 155 |
156 void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp, | 156 void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp, |
157 const GrGLSLExpr4& colorIn, | 157 const GrGLSLExpr4& colorIn, |
158 const GrGLSLExpr4& coverageIn, | 158 const GrGLSLExpr4& coverageIn, |
159 bool ignoresCoverage, | 159 bool ignoresCoverage, |
160 GrPixelLocalStorageState plsSt
ate) { | 160 GrPixelLocalStorageState plsSt
ate) { |
(...skipping 26 matching lines...) Expand all Loading... |
187 xp, colorIn.c_str(), | 187 xp, colorIn.c_str(), |
188 ignoresCoverage ? nullptr : coverageIn.c_
str(), | 188 ignoresCoverage ? nullptr : coverageIn.c_
str(), |
189 fFS.getPrimaryColorOutputName(), | 189 fFS.getPrimaryColorOutputName(), |
190 fFS.getSecondaryColorOutputName(), | 190 fFS.getSecondaryColorOutputName(), |
191 samplers, | 191 samplers, |
192 usePLSDstRead); | 192 usePLSDstRead); |
193 fXferProcessor->emitCode(args); | 193 fXferProcessor->emitCode(args); |
194 | 194 |
195 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 195 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
196 // asks for dst color, then the emit code needs to follow suit | 196 // asks for dst color, then the emit code needs to follow suit |
197 verify(xp); | 197 SkDEBUGCODE(verify(xp);) |
198 fFS.codeAppend("}"); | 198 fFS.codeAppend("}"); |
199 } | 199 } |
200 | 200 |
201 void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) { | 201 void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) { |
202 // Swizzle the fragment shader outputs if necessary. | 202 // Swizzle the fragment shader outputs if necessary. |
203 GrSwizzle swizzle; | 203 GrSwizzle swizzle; |
204 swizzle.setFromKey(this->desc().header().fOutputSwizzle); | 204 swizzle.setFromKey(this->desc().header().fOutputSwizzle); |
205 if (swizzle != GrSwizzle::RGBA()) { | 205 if (swizzle != GrSwizzle::RGBA()) { |
206 fFS.codeAppendf("%s = %s.%s;", fFS.getPrimaryColorOutputName(), | 206 fFS.codeAppendf("%s = %s.%s;", fFS.getPrimaryColorOutputName(), |
207 fFS.getPrimaryColorOutputName(), | 207 fFS.getPrimaryColorOutputName(), |
208 swizzle.c_str()); | 208 swizzle.c_str()); |
209 if (hasSecondaryOutput) { | 209 if (hasSecondaryOutput) { |
210 fFS.codeAppendf("%s = %s.%s;", fFS.getSecondaryColorOutputName(), | 210 fFS.codeAppendf("%s = %s.%s;", fFS.getSecondaryColorOutputName(), |
211 fFS.getSecondaryColorOutputName(), | 211 fFS.getSecondaryColorOutputName(), |
212 swizzle.c_str()); | 212 swizzle.c_str()); |
213 } | 213 } |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
| 217 #ifdef SK_DEBUG |
217 void GrGLSLProgramBuilder::verify(const GrPrimitiveProcessor& gp) { | 218 void GrGLSLProgramBuilder::verify(const GrPrimitiveProcessor& gp) { |
218 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition()); | 219 SkASSERT(fFS.usedProcessorFeatures() == gp.requiredFeatures()); |
219 } | 220 } |
220 | 221 |
221 void GrGLSLProgramBuilder::verify(const GrXferProcessor& xp) { | 222 void GrGLSLProgramBuilder::verify(const GrXferProcessor& xp) { |
| 223 SkASSERT(fFS.usedProcessorFeatures() == xp.requiredFeatures()); |
222 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); | 224 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); |
223 } | 225 } |
224 | 226 |
225 void GrGLSLProgramBuilder::verify(const GrFragmentProcessor& fp) { | 227 void GrGLSLProgramBuilder::verify(const GrFragmentProcessor& fp) { |
226 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); | 228 SkASSERT(fFS.usedProcessorFeatures() == fp.requiredFeatures()); |
227 } | 229 } |
| 230 #endif |
228 | 231 |
229 void GrGLSLProgramBuilder::nameVariable(SkString* out, char prefix, const char*
name, bool mangle) { | 232 void GrGLSLProgramBuilder::nameVariable(SkString* out, char prefix, const char*
name, bool mangle) { |
230 if ('\0' == prefix) { | 233 if ('\0' == prefix) { |
231 *out = name; | 234 *out = name; |
232 } else { | 235 } else { |
233 out->printf("%c%s", prefix, name); | 236 out->printf("%c%s", prefix, name); |
234 } | 237 } |
235 if (mangle) { | 238 if (mangle) { |
236 if (out->endsWith('_')) { | 239 if (out->endsWith('_')) { |
237 // Names containing "__" are reserved. | 240 // Names containing "__" are reserved. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 delete fFragmentProcessors[i]; | 288 delete fFragmentProcessors[i]; |
286 } | 289 } |
287 } | 290 } |
288 | 291 |
289 void GrGLSLProgramBuilder::finalizeShaders() { | 292 void GrGLSLProgramBuilder::finalizeShaders() { |
290 this->varyingHandler()->finalize(); | 293 this->varyingHandler()->finalize(); |
291 fVS.finalize(kVertex_GrShaderFlag); | 294 fVS.finalize(kVertex_GrShaderFlag); |
292 fFS.finalize(kFragment_GrShaderFlag); | 295 fFS.finalize(kFragment_GrShaderFlag); |
293 | 296 |
294 } | 297 } |
OLD | NEW |