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

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

Issue 24853002: Make GPU coord transforms automatic (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | 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 2012 Google Inc. 2 * Copyright 2012 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 "gl/GrGLShaderBuilder.h" 8 #include "gl/GrGLShaderBuilder.h"
9 #include "gl/GrGLProgram.h" 9 #include "gl/GrGLProgram.h"
10 #include "gl/GrGLUniformHandle.h" 10 #include "gl/GrGLUniformHandle.h"
11 #include "GrCoordTransform.h"
11 #include "GrDrawEffect.h" 12 #include "GrDrawEffect.h"
12 #include "GrGpuGL.h" 13 #include "GrGpuGL.h"
13 #include "GrTexture.h" 14 #include "GrTexture.h"
14 #include "SkRTConf.h" 15 #include "SkRTConf.h"
15 #include "SkTrace.h" 16 #include "SkTrace.h"
16 17
17 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) 18 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X)
18 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) 19 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X)
19 20
20 // number of each input/output type in a single allocation block 21 // number of each input/output type in a single allocation block
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 void GrGLShaderBuilder::fsAppendTextureLookupAndModulate( 341 void GrGLShaderBuilder::fsAppendTextureLookupAndModulate(
341 const char* modulation, 342 const char* modulation,
342 const GrGLShaderBuilder::TextureSamp ler& sampler, 343 const GrGLShaderBuilder::TextureSamp ler& sampler,
343 const char* coordName, 344 const char* coordName,
344 GrSLType varyingType) { 345 GrSLType varyingType) {
345 SkString lookup; 346 SkString lookup;
346 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); 347 this->appendTextureLookup(&lookup, sampler, coordName, varyingType);
347 GrGLSLModulatef<4>(&fFSCode, modulation, lookup.c_str()); 348 GrGLSLModulatef<4>(&fFSCode, modulation, lookup.c_str());
348 } 349 }
349 350
350 GrBackendEffectFactory::EffectKey GrGLShaderBuilder::KeyForTextureAccess( 351 GrGLShaderBuilder::EffectKey GrGLShaderBuilder::KeyForTextureAccess(const GrText ureAccess& access,
351 const GrTextureAcces s& access, 352 const GrGLCa ps& caps) {
352 const GrGLCaps& caps ) {
353 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getTexture( )->config()); 353 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getTexture( )->config());
354 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.swizz leMask())) { 354 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.swizz leMask())) {
355 return 1; 355 return 1;
356 } else { 356 } else {
357 return 0; 357 return 0;
358 } 358 }
359 } 359 }
360 360
361 GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture* dstCopy, 361 GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture* dstCopy,
362 const GrGLCaps& c aps) { 362 const GrGLCaps& c aps) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 uni.fVariable.setPrecision(kDefaultFragmentPrecision); 433 uni.fVariable.setPrecision(kDefaultFragmentPrecision);
434 } 434 }
435 435
436 if (NULL != outName) { 436 if (NULL != outName) {
437 *outName = uni.fVariable.c_str(); 437 *outName = uni.fVariable.c_str();
438 } 438 }
439 439
440 return h; 440 return h;
441 } 441 }
442 442
443 SkString GrGLShaderBuilder::ensureFSCoords2D(const TransformedCoordsArray& coord s, int index) {
444 if (kVec3f_GrSLType != coords[index].type()) {
445 SkASSERT(kVec2f_GrSLType == coords[index].type());
446 return coords[index].getName();
447 }
448
449 SkString coords2D("coords2D");
450 if (0 != index) {
451 coords2D.appendf("_%i", index);
452 }
453 this->fsCodeAppendf("\tvec2 %s = %s.xy / %s.z;",
454 coords2D.c_str(), coords[index].c_str(), coords[index].c _str());
455 return coords2D;
456 }
457
443 const char* GrGLShaderBuilder::fragmentPosition() { 458 const char* GrGLShaderBuilder::fragmentPosition() {
444 if (fCodeStage.inStageCode()) { 459 if (fCodeStage.inStageCode()) {
445 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); 460 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect();
446 if (!effect->willReadFragmentPosition()) { 461 if (!effect->willReadFragmentPosition()) {
447 GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect " 462 GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect "
448 "did not request access."); 463 "did not request access.");
449 return ""; 464 return "";
450 } 465 }
451 } 466 }
452 if (fTopLeftFragPosRead) { 467 if (fTopLeftFragPosRead) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 for (int i = 0; i < fUniforms.count(); ++i) { 567 for (int i = 0; i < fUniforms.count(); ++i) {
553 if (fUniforms[i].fVisibility & visibility) { 568 if (fUniforms[i].fVisibility & visibility) {
554 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); 569 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out);
555 out->append(";\n"); 570 out->append(";\n");
556 } 571 }
557 } 572 }
558 } 573 }
559 574
560 void GrGLShaderBuilder::emitEffects( 575 void GrGLShaderBuilder::emitEffects(
561 const GrEffectStage* effectStages[], 576 const GrEffectStage* effectStages[],
562 const GrBackendEffectFactory::EffectKey effectKeys[], 577 const EffectKey effectKeys[],
563 int effectCnt, 578 int effectCnt,
564 SkString* fsInOutColor, 579 SkString* fsInOutColor,
565 GrSLConstantVec* fsInOutColorKnownValue, 580 GrSLConstantVec* fsInOutColorKnownValue,
581 SkTArray<GrGLCoordTransform, false>* effectCoordTransfor mArrays[],
566 SkTArray<GrGLUniformManager::UniformHandle, true>* effec tSamplerHandles[], 582 SkTArray<GrGLUniformManager::UniformHandle, true>* effec tSamplerHandles[],
567 GrGLEffect* glEffects[]) { 583 GrGLEffect* glEffects[]) {
568 bool effectEmitted = false; 584 bool effectEmitted = false;
569 585
570 SkString inColor = *fsInOutColor; 586 SkString inColor = *fsInOutColor;
571 SkString outColor; 587 SkString outColor;
572 588
573 for (int e = 0; e < effectCnt; ++e) { 589 for (int e = 0; e < effectCnt; ++e) {
574 SkASSERT(NULL != effectStages[e] && NULL != effectStages[e]->getEffect() ); 590 SkASSERT(NULL != effectStages[e] && NULL != effectStages[e]->getEffect() );
575 const GrEffectStage& stage = *effectStages[e]; 591 const GrEffectStage& stage = *effectStages[e];
576 const GrEffectRef& effect = *stage.getEffect(); 592 const GrEffectRef& effect = *stage.getEffect();
577 593
578 CodeStage::AutoStageRestore csar(&fCodeStage, &stage); 594 CodeStage::AutoStageRestore csar(&fCodeStage, &stage);
579 595
596 int numTransforms = effect->numTransforms();
597 SkSTArray<8, GrGLCoordTransform::TransformedCoords> transformedCoords;
598 transformedCoords.push_back_n(numTransforms);
599 EffectKey transformKey = GrBackendEffectFactory::GetTransformKey(effectK eys[e]);
600 for (int c = 0; c < numTransforms; ++c) {
601 GrGLCoordTransform& ct = effectCoordTransformArrays[e]->push_back();
602 EffectKey key = (transformKey >> (c * GrGLCoordTransform::kKeyBits)) &
603 (GrGLCoordTransform::kKeyMask);
604 ct.emitCode(this, key, &transformedCoords[c], c);
605 }
606
580 int numTextures = effect->numTextures(); 607 int numTextures = effect->numTextures();
581 SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers; 608 SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers;
582 textureSamplers.push_back_n(numTextures); 609 textureSamplers.push_back_n(numTextures);
583 for (int t = 0; t < numTextures; ++t) { 610 for (int t = 0; t < numTextures; ++t) {
584 textureSamplers[t].init(this, &effect->textureAccess(t), t); 611 textureSamplers[t].init(this, &effect->textureAccess(t), t);
585 effectSamplerHandles[e]->push_back(textureSamplers[t].fSamplerUnifor m); 612 effectSamplerHandles[e]->push_back(textureSamplers[t].fSamplerUnifor m);
586 } 613 }
614
587 GrDrawEffect drawEffect(stage, NULL != fVertexBuilder.get() 615 GrDrawEffect drawEffect(stage, NULL != fVertexBuilder.get()
588 && fVertexBuilder->hasExplicitLocalCoords ()); 616 && fVertexBuilder->hasExplicitLocalCoords ());
589 617
590 int numAttributes = stage.getVertexAttribIndexCount(); 618 int numAttributes = stage.getVertexAttribIndexCount();
591 const int* attributeIndices = stage.getVertexAttribIndices(); 619 const int* attributeIndices = stage.getVertexAttribIndices();
592 SkSTArray<GrEffect::kMaxVertexAttribs, SkString> attributeNames; 620 SkSTArray<GrEffect::kMaxVertexAttribs, SkString> attributeNames;
593 for (int a = 0; a < numAttributes; ++a) { 621 for (int a = 0; a < numAttributes; ++a) {
594 // TODO: Make addAttribute mangle the name. 622 // TODO: Make addAttribute mangle the name.
595 SkASSERT(NULL != fVertexBuilder.get()); 623 SkASSERT(NULL != fVertexBuilder.get());
596 SkString attributeName("aAttr"); 624 SkString attributeName("aAttr");
(...skipping 21 matching lines...) Expand all
618 if (NULL != fVertexBuilder.get()) { 646 if (NULL != fVertexBuilder.get()) {
619 fVertexBuilder->vsCodeAppend(openBrace.c_str()); 647 fVertexBuilder->vsCodeAppend(openBrace.c_str());
620 } 648 }
621 this->fsCodeAppend(openBrace.c_str()); 649 this->fsCodeAppend(openBrace.c_str());
622 650
623 glEffects[e]->emitCode(this, 651 glEffects[e]->emitCode(this,
624 drawEffect, 652 drawEffect,
625 effectKeys[e], 653 effectKeys[e],
626 outColor.c_str(), 654 outColor.c_str(),
627 inColor.isEmpty() ? NULL : inColor.c_str(), 655 inColor.isEmpty() ? NULL : inColor.c_str(),
656 transformedCoords,
628 textureSamplers); 657 textureSamplers);
629 658
630 if (NULL != fVertexBuilder.get()) { 659 if (NULL != fVertexBuilder.get()) {
631 fVertexBuilder->vsCodeAppend("\t}\n"); 660 fVertexBuilder->vsCodeAppend("\t}\n");
632 } 661 }
633 this->fsCodeAppend("\t}\n"); 662 this->fsCodeAppend("\t}\n");
634 663
635 inColor = outColor; 664 inColor = outColor;
636 *fsInOutColorKnownValue = kNone_GrSLConstantVec; 665 *fsInOutColorKnownValue = kNone_GrSLConstantVec;
637 effectEmitted = true; 666 effectEmitted = true;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 GL_CALL(BindAttribLocation(programId, 1011 GL_CALL(BindAttribLocation(programId,
983 header.fCoverageAttributeIndex, 1012 header.fCoverageAttributeIndex,
984 coverage_attribute_name())); 1013 coverage_attribute_name()));
985 } 1014 }
986 1015
987 const AttributePair* attribEnd = fEffectAttributes.end(); 1016 const AttributePair* attribEnd = fEffectAttributes.end();
988 for (const AttributePair* attrib = fEffectAttributes.begin(); attrib != attr ibEnd; ++attrib) { 1017 for (const AttributePair* attrib = fEffectAttributes.begin(); attrib != attr ibEnd; ++attrib) {
989 GL_CALL(BindAttribLocation(programId, attrib->fIndex, attrib->fName.c_s tr())); 1018 GL_CALL(BindAttribLocation(programId, attrib->fIndex, attrib->fName.c_s tr()));
990 } 1019 }
991 } 1020 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698