Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "GrGLProgramBuilder.h" | 8 #include "GrGLProgramBuilder.h" |
| 9 | 9 |
| 10 #include "gl/GrGLGeometryProcessor.h" | 10 #include "gl/GrGLGeometryProcessor.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); | 172 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); |
| 173 out->append(";\n"); | 173 out->append(";\n"); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { | 178 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { |
| 179 return fGpu->ctxInfo(); | 179 return fGpu->ctxInfo(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 template <> | |
| 183 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, | |
|
joshualitt
2015/08/03 14:06:02
This should be GrFragmentProcessor& so it doesn't
wangyix
2015/08/03 16:12:47
Removed this function for the time being; Was disc
| |
| 184 GrGLProcessor::TextureSamplerArray* outSam plers, | |
| 185 GrGLInstalledProc<GrGLFragmentProcessor>* ifp) { | |
| 186 SkDEBUGCODE(ifp->fSamplersIdx = fSamplerUniforms.count();) | |
| 187 int numTextures = processor.numTextures(); | |
| 188 int samplerUniformsOffset = fSamplerUniforms.count(); | |
| 189 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur es); | |
| 190 SkString name; | |
| 191 for (int t = 0; t < numTextures; ++t) { | |
| 192 name.printf("Sampler%d", samplerUniformsOffset + t); | |
| 193 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment _Visibility, | |
| 194 kSampler2D_GrSLType, kDefault _GrSLPrecision, | |
| 195 name.c_str()); | |
| 196 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLProcessor::TextureSampler, | |
| 197 (localSamplerUniforms[t], processor.textureAccess (t))); | |
| 198 } | |
| 199 | |
| 200 // recursively emit the samplers of this processor's child processors | |
| 201 const GrFragmentProcessor& fp = processor.cast<GrFragmentProcessor>(); | |
| 202 for (int i = 0; i < fp.numChildProcessors(); ++i) { | |
| 203 this->emitSamplers(*fp.childProcessor(i), outSamplers, ifp); | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 void appendGrFPCoordTransforms(const GrFragmentProcessor* processor, | |
|
joshualitt
2015/08/03 14:06:02
static void append_gr_fp_coord_transforms
wangyix
2015/08/03 16:12:47
Done.
| |
| 208 SkTArray<const GrCoordTransform*, true>* procCoord s) { | |
| 209 // add the coord transforms of this processor | |
| 210 for (int i = 0; i < processor->numTransforms(); ++i) { | |
| 211 procCoords->push_back(&processor->coordTransform(i)); | |
| 212 } | |
| 213 // recursively add the coord transforms of this processor's child processors | |
| 214 for (int i = 0; i < processor->numChildProcessors(); ++i) { | |
| 215 appendGrFPCoordTransforms(processor->childProcessor(i), procCoords); | |
| 216 } | |
| 217 } | |
| 218 | |
| 182 bool GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr 4* inputCoverage) { | 219 bool GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr 4* inputCoverage) { |
| 183 // First we loop over all of the installed processors and collect coord tran sforms. These will | 220 // First we loop over all of the installed processors and collect coord tran sforms. These will |
| 184 // be sent to the GrGLPrimitiveProcessor in its emitCode function | 221 // be sent to the GrGLPrimitiveProcessor in its emitCode function |
| 185 const GrPrimitiveProcessor& primProc = this->primitiveProcessor(); | 222 const GrPrimitiveProcessor& primProc = this->primitiveProcessor(); |
| 186 int totalTextures = primProc.numTextures(); | 223 int totalTextures = primProc.numTextures(); |
| 187 const int maxTextureUnits = fGpu->glCaps().maxFragmentTextureUnits(); | 224 const int maxTextureUnits = fGpu->glCaps().maxFragmentTextureUnits(); |
| 188 SkSTArray<8, GrGLProcessor::TransformedCoordsArray> outCoords; | 225 SkSTArray<8, GrGLProcessor::TransformedCoordsArray> outCoords; |
| 189 for (int i = 0; i < this->pipeline().numFragmentStages(); i++) { | 226 for (int i = 0; i < this->pipeline().numFragmentStages(); i++) { |
| 190 const GrFragmentProcessor* processor = this->pipeline().getFragmentStage (i).processor(); | 227 const GrFragmentProcessor* processor = this->pipeline().getFragmentStage (i).processor(); |
| 191 SkSTArray<2, const GrCoordTransform*, true>& procCoords = fCoordTransfor ms.push_back(); | 228 SkSTArray<2, const GrCoordTransform*, true>& procCoords = fCoordTransfor ms.push_back(); |
| 192 for (int t = 0; t < processor->numTransforms(); t++) { | |
| 193 procCoords.push_back(&processor->coordTransform(t)); | |
| 194 } | |
| 195 | 229 |
| 196 totalTextures += processor->numTextures(); | 230 appendGrFPCoordTransforms(processor, &procCoords); |
| 231 | |
| 232 totalTextures += processor->numTexturesIncludeChildProcs(); | |
| 197 if (totalTextures >= maxTextureUnits) { | 233 if (totalTextures >= maxTextureUnits) { |
| 198 GrCapsDebugf(fGpu->caps(), "Program would use too many texture units \n"); | 234 GrCapsDebugf(fGpu->caps(), "Program would use too many texture units \n"); |
| 199 return false; | 235 return false; |
| 200 } | 236 } |
| 201 } | 237 } |
| 202 | 238 |
| 203 this->emitAndInstallProc(primProc, inputColor, inputCoverage); | 239 this->emitAndInstallProc(primProc, inputColor, inputCoverage); |
| 204 | 240 |
| 205 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); | 241 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); |
| 206 int numProcs = this->pipeline().numFragmentStages(); | 242 int numProcs = this->pipeline().numFragmentStages(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 | 313 |
| 278 void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& fs, | 314 void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& fs, |
| 279 int index, | 315 int index, |
| 280 const char* outColor, | 316 const char* outColor, |
| 281 const char* inColor) { | 317 const char* inColor) { |
| 282 GrGLInstalledFragProc* ifp = SkNEW(GrGLInstalledFragProc); | 318 GrGLInstalledFragProc* ifp = SkNEW(GrGLInstalledFragProc); |
| 283 | 319 |
| 284 const GrFragmentProcessor& fp = *fs.processor(); | 320 const GrFragmentProcessor& fp = *fs.processor(); |
| 285 ifp->fGLProc.reset(fp.createGLInstance()); | 321 ifp->fGLProc.reset(fp.createGLInstance()); |
| 286 | 322 |
| 287 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures()); | 323 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTexturesIncludeCh ildProcs()); |
| 288 this->emitSamplers(fp, &samplers, ifp); | 324 this->emitSamplers(fp, &samplers, ifp); |
| 289 | 325 |
| 290 GrGLFragmentProcessor::EmitArgs args(this, fp, outColor, inColor, fOutCoords [index], samplers); | 326 GrGLFragmentProcessor::EmitArgs args(this, fp, outColor, inColor, fOutCoords [index], samplers); |
| 291 ifp->fGLProc->emitCode(args); | 327 ifp->fGLProc->emitCode(args); |
| 292 | 328 |
| 293 // We have to check that effects and the code they emit are consistent, ie i f an effect | 329 // We have to check that effects and the code they emit are consistent, ie i f an effect |
| 294 // asks for dst color, then the emit code needs to follow suit | 330 // asks for dst color, then the emit code needs to follow suit |
| 295 verify(fp); | 331 verify(fp); |
| 296 fFragmentProcessors->fProcs.push_back(ifp); | 332 fFragmentProcessors->fProcs.push_back(ifp); |
| 297 } | 333 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 | 397 |
| 362 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) { | 398 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) { |
| 363 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); | 399 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); |
| 364 } | 400 } |
| 365 | 401 |
| 366 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { | 402 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { |
| 367 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); | 403 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); |
| 368 } | 404 } |
| 369 | 405 |
| 370 template <class Proc> | 406 template <class Proc> |
| 371 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, | 407 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, |
|
joshualitt
2015/08/03 14:06:02
This should be Proc& processor
wangyix
2015/08/03 16:12:47
Didn't do this; Was discussed.
| |
| 372 GrGLProcessor::TextureSamplerArray* outSam plers, | 408 GrGLProcessor::TextureSamplerArray* outSam plers, |
| 373 GrGLInstalledProc<Proc>* ip) { | 409 GrGLInstalledProc<Proc>* ip) { |
| 374 SkDEBUGCODE(ip->fSamplersIdx = fSamplerUniforms.count();) | 410 SkDEBUGCODE(ip->fSamplersIdx = fSamplerUniforms.count();) |
| 375 int numTextures = processor.numTextures(); | 411 int numTextures = processor.numTextures(); |
| 376 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur es); | 412 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur es); |
| 377 SkString name; | 413 SkString name; |
| 378 for (int t = 0; t < numTextures; ++t) { | 414 for (int t = 0; t < numTextures; ++t) { |
| 379 name.printf("Sampler%d", t); | 415 name.printf("Sampler%d", t); |
| 380 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment _Visibility, | 416 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment _Visibility, |
| 381 kSampler2D_GrSLType, kDefault _GrSLPrecision, | 417 kSampler2D_GrSLType, kDefault _GrSLPrecision, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 } | 533 } |
| 498 | 534 |
| 499 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 535 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
| 500 | 536 |
| 501 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 537 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
| 502 int numProcs = fProcs.count(); | 538 int numProcs = fProcs.count(); |
| 503 for (int e = 0; e < numProcs; ++e) { | 539 for (int e = 0; e < numProcs; ++e) { |
| 504 SkDELETE(fProcs[e]); | 540 SkDELETE(fProcs[e]); |
| 505 } | 541 } |
| 506 } | 542 } |
| OLD | NEW |