diff options
author | Brian Salomon <bsalomon@google.com> | 2017-04-03 16:57:43 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-03 21:35:47 +0000 |
commit | 18dfa980765bee6a1ce7c5f430cb32f487da6590 (patch) | |
tree | f82444c520111b4710746480652fde74d2db3815 /src/gpu/glsl | |
parent | b9c4a6fc7de252633f16d11c2df10ee6de16af03 (diff) |
Store the dst texture used by an XP in GrPipeline rather than in the XP.
This will allow the XP to be created before the dst texture.
Change-Id: I3e5bdfa8e5d47e58a3560792ce5cf3899d30a024
Reviewed-on: https://skia-review.googlesource.com/11011
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/glsl')
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.cpp | 70 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.h | 12 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLXferProcessor.cpp | 21 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLXferProcessor.h | 25 |
4 files changed, 62 insertions, 66 deletions
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp index 1fcf0405f7..4cd4fd6ec5 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp +++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp @@ -62,7 +62,7 @@ bool GrGLSLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, this->emitAndInstallPrimProc(primProc, inputColor, inputCoverage); this->emitAndInstallFragProcs(inputColor, inputCoverage); - this->emitAndInstallXferProc(this->pipeline().getXferProcessor(), *inputColor, *inputCoverage); + this->emitAndInstallXferProc(*inputColor, *inputCoverage); this->emitFSOutputSwizzle(this->pipeline().getXferProcessor().hasSecondaryOutput()); return this->checkSamplerCounts() && this->checkImageStorageCounts(); @@ -211,13 +211,13 @@ void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp, fFS.codeAppend("}"); } -void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp, - const GrGLSLExpr4& colorIn, +void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrGLSLExpr4& colorIn, const GrGLSLExpr4& coverageIn) { // Program builders have a bit of state we need to clear with each effect AutoStageAdvance adv(this); SkASSERT(!fXferProcessor); + const GrXferProcessor& xp = fPipeline.getXferProcessor(); fXferProcessor = xp.createGLSLInstance(); // Enable dual source secondary output if we have one @@ -233,21 +233,28 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp, openBrace.printf("{ // Xfer Processor: %s\n", xp.name()); fFS.codeAppend(openBrace.c_str()); - SkSTArray<4, SamplerHandle> texSamplers(xp.numTextureSamplers()); - SkSTArray<2, SamplerHandle> bufferSamplers(xp.numBuffers()); - SkSTArray<2, ImageStorageHandle> imageStorageArray(xp.numImageStorages()); - this->emitSamplersAndImageStorages(xp, &texSamplers, &bufferSamplers, &imageStorageArray); + SamplerHandle dstTextureSamplerHandle; + GrSurfaceOrigin dstTextureOrigin = kTopLeft_GrSurfaceOrigin; + if (GrTexture* dstTexture = fPipeline.dstTexture()) { + // GrProcessor::TextureSampler sampler(dstTexture); + SkString name("DstTextureSampler"); + dstTextureSamplerHandle = + this->emitSampler(dstTexture->texturePriv().samplerType(), dstTexture->config(), + "DstTextureSampler", kFragment_GrShaderFlag); + dstTextureOrigin = dstTexture->origin(); + SkASSERT(kTextureExternalSampler_GrSLType != dstTexture->texturePriv().samplerType()); + } GrGLSLXferProcessor::EmitArgs args(&fFS, this->uniformHandler(), this->shaderCaps(), - xp, colorIn.c_str(), + xp, + colorIn.c_str(), coverageIn.c_str(), fFS.getPrimaryColorOutputName(), fFS.getSecondaryColorOutputName(), - texSamplers.begin(), - bufferSamplers.begin(), - imageStorageArray.begin()); + dstTextureSamplerHandle, + dstTextureOrigin); fXferProcessor->emitCode(args); // We have to check that effects and the code they emit are consistent, ie if an effect @@ -276,11 +283,9 @@ void GrGLSLProgramBuilder::emitSamplersAndImageStorages( 1 << GrGLSLShaderBuilder::kExternalTexture_GLSLPrivateFeature, externalFeatureString); } - this->emitSampler(samplerType, sampler.texture()->config(), name.c_str(), - sampler.visibility(), outTexSamplerHandles); - + outTexSamplerHandles->emplace_back(this->emitSampler( + samplerType, sampler.texture()->config(), name.c_str(), sampler.visibility())); } - if (int numBuffers = processor.numBuffers()) { SkASSERT(this->shaderCaps()->texelBufferSupport()); GrShaderFlags texelBufferVisibility = kNone_GrShaderFlags; @@ -288,8 +293,9 @@ void GrGLSLProgramBuilder::emitSamplersAndImageStorages( for (int b = 0; b < numBuffers; ++b) { const GrProcessor::BufferAccess& access = processor.bufferAccess(b); name.printf("BufferSampler_%d", outBufferSamplerHandles->count()); - this->emitSampler(kBufferSampler_GrSLType, access.texelConfig(), name.c_str(), - access.visibility(), outBufferSamplerHandles); + outBufferSamplerHandles->emplace_back( + this->emitSampler(kBufferSampler_GrSLType, access.texelConfig(), name.c_str(), + access.visibility())); texelBufferVisibility |= access.visibility(); } @@ -303,15 +309,15 @@ void GrGLSLProgramBuilder::emitSamplersAndImageStorages( for (int i = 0; i < numImageStorages; ++i) { const GrProcessor::ImageStorageAccess& imageStorageAccess = processor.imageStorageAccess(i); name.printf("Image_%d", outImageStorageHandles->count()); - this->emitImageStorage(imageStorageAccess, name.c_str(), outImageStorageHandles); + outImageStorageHandles->emplace_back( + this->emitImageStorage(imageStorageAccess, name.c_str())); } } -void GrGLSLProgramBuilder::emitSampler(GrSLType samplerType, - GrPixelConfig config, - const char* name, - GrShaderFlags visibility, - SkTArray<SamplerHandle>* outSamplerHandles) { +GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(GrSLType samplerType, + GrPixelConfig config, + const char* name, + GrShaderFlags visibility) { if (visibility & kVertex_GrShaderFlag) { ++fNumVertexSamplers; } @@ -324,16 +330,11 @@ void GrGLSLProgramBuilder::emitSampler(GrSLType samplerType, } GrSLPrecision precision = this->shaderCaps()->samplerPrecision(config, visibility); GrSwizzle swizzle = this->shaderCaps()->configTextureSwizzle(config); - outSamplerHandles->emplace_back(this->uniformHandler()->addSampler(visibility, - swizzle, - samplerType, - precision, - name)); + return this->uniformHandler()->addSampler(visibility, swizzle, samplerType, precision, name); } -void GrGLSLProgramBuilder::emitImageStorage(const GrProcessor::ImageStorageAccess& access, - const char* name, - SkTArray<ImageStorageHandle>* outImageStorageHandles) { +GrGLSLProgramBuilder::ImageStorageHandle GrGLSLProgramBuilder::emitImageStorage( + const GrProcessor::ImageStorageAccess& access, const char* name) { if (access.visibility() & kVertex_GrShaderFlag) { ++fNumVertexImageStorages; } @@ -345,10 +346,9 @@ void GrGLSLProgramBuilder::emitImageStorage(const GrProcessor::ImageStorageAcces ++fNumFragmentImageStorages; } GrSLType uniformType = access.texture()->texturePriv().imageStorageType(); - ImageStorageHandle handle = this->uniformHandler()->addImageStorage(access.visibility(), - uniformType, access.format(), access.memoryModel(), access.restrict(), access.ioType(), - name); - outImageStorageHandles->emplace_back(handle); + return this->uniformHandler()->addImageStorage(access.visibility(), uniformType, + access.format(), access.memoryModel(), + access.restrict(), access.ioType(), name); } void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) { diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h index 748664625f..2d2ab47a5e 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.h +++ b/src/gpu/glsl/GrGLSLProgramBuilder.h @@ -152,18 +152,14 @@ private: int transformedCoordVarsIdx, const GrGLSLExpr4& input, GrGLSLExpr4* output); - void emitAndInstallXferProc(const GrXferProcessor&, - const GrGLSLExpr4& colorIn, - const GrGLSLExpr4& coverageIn); + void emitAndInstallXferProc(const GrGLSLExpr4& colorIn, const GrGLSLExpr4& coverageIn); void emitSamplersAndImageStorages(const GrProcessor& processor, SkTArray<SamplerHandle>* outTexSamplerHandles, SkTArray<SamplerHandle>* outBufferSamplerHandles, SkTArray<ImageStorageHandle>* outImageStorageHandles); - void emitSampler(GrSLType samplerType, GrPixelConfig, const char* name, - GrShaderFlags visibility, SkTArray<SamplerHandle >* outSamplerHandles); - void emitImageStorage(const GrProcessor::ImageStorageAccess&, - const char* name, - SkTArray<ImageStorageHandle>* outImageStorageHandles); + SamplerHandle emitSampler(GrSLType samplerType, GrPixelConfig, const char* name, + GrShaderFlags visibility); + ImageStorageHandle emitImageStorage(const GrProcessor::ImageStorageAccess&, const char* name); void emitFSOutputSwizzle(bool hasSecondaryOutput); bool checkSamplerCounts(); bool checkImageStorageCounts(); diff --git a/src/gpu/glsl/GrGLSLXferProcessor.cpp b/src/gpu/glsl/GrGLSLXferProcessor.cpp index 4101080090..545a9fd1f7 100644 --- a/src/gpu/glsl/GrGLSLXferProcessor.cpp +++ b/src/gpu/glsl/GrGLSLXferProcessor.cpp @@ -25,8 +25,8 @@ void GrGLSLXferProcessor::emitCode(const EmitArgs& args) { bool needsLocalOutColor = false; - if (args.fXP.getDstTexture()) { - bool topDown = kTopLeft_GrSurfaceOrigin == args.fXP.getDstTexture()->origin(); + if (args.fDstTextureSamplerHandle.isValid()) { + bool flipY = kBottomLeft_GrSurfaceOrigin == args.fDstTextureOrigin; if (args.fInputCoverage) { // We don't think any shaders actually output negative coverage, but just as a safety @@ -54,12 +54,13 @@ void GrGLSLXferProcessor::emitCode(const EmitArgs& args) { fragBuilder->codeAppendf("vec2 _dstTexCoord = (sk_FragCoord.xy - %s) * %s;", dstTopLeftName, dstCoordScaleName); - if (!topDown) { + if (flipY) { fragBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;"); } fragBuilder->codeAppendf("vec4 %s = ", dstColor); - fragBuilder->appendTextureLookup(args.fTexSamplers[0], "_dstTexCoord", kVec2f_GrSLType); + fragBuilder->appendTextureLookup(args.fDstTextureSamplerHandle, "_dstTexCoord", + kVec2f_GrSLType); fragBuilder->codeAppend(";"); } else { needsLocalOutColor = args.fShaderCaps->requiresLocalOutputColorForFBFetch(); @@ -85,13 +86,13 @@ void GrGLSLXferProcessor::emitCode(const EmitArgs& args) { } } -void GrGLSLXferProcessor::setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp) { - if (xp.getDstTexture()) { +void GrGLSLXferProcessor::setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp, + const GrTexture* dstTexture, const SkIPoint& dstTextureOffset) { + if (dstTexture) { if (fDstTopLeftUni.isValid()) { - pdm.set2f(fDstTopLeftUni, static_cast<float>(xp.dstTextureOffset().fX), - static_cast<float>(xp.dstTextureOffset().fY)); - pdm.set2f(fDstScaleUni, 1.f / xp.getDstTexture()->width(), - 1.f / xp.getDstTexture()->height()); + pdm.set2f(fDstTopLeftUni, static_cast<float>(dstTextureOffset.fX), + static_cast<float>(dstTextureOffset.fY)); + pdm.set2f(fDstScaleUni, 1.f / dstTexture->width(), 1.f / dstTexture->height()); } else { SkASSERT(!fDstScaleUni.isValid()); } diff --git a/src/gpu/glsl/GrGLSLXferProcessor.h b/src/gpu/glsl/GrGLSLXferProcessor.h index b4bde37e30..791bb068e2 100644 --- a/src/gpu/glsl/GrGLSLXferProcessor.h +++ b/src/gpu/glsl/GrGLSLXferProcessor.h @@ -8,6 +8,7 @@ #ifndef GrGLSLXferProcessor_DEFINED #define GrGLSLXferProcessor_DEFINED +#include "SkPoint.h" #include "glsl/GrGLSLProgramDataManager.h" #include "glsl/GrGLSLUniformHandler.h" @@ -15,14 +16,15 @@ class GrXferProcessor; class GrGLSLXPBuilder; class GrGLSLXPFragmentBuilder; class GrShaderCaps; +class GrTexture; class GrGLSLXferProcessor { public: GrGLSLXferProcessor() {} virtual ~GrGLSLXferProcessor() {} - using SamplerHandle = GrGLSLUniformHandler::SamplerHandle; - using ImageStorageHandle = GrGLSLUniformHandler::ImageStorageHandle; + using SamplerHandle = GrGLSLUniformHandler::SamplerHandle; + using ImageStorageHandle = GrGLSLUniformHandler::ImageStorageHandle; struct EmitArgs { EmitArgs(GrGLSLXPFragmentBuilder* fragBuilder, @@ -33,9 +35,8 @@ public: const char* inputCoverage, const char* outputPrimary, const char* outputSecondary, - const SamplerHandle* texSamplers, - const SamplerHandle* bufferSamplers, - const ImageStorageHandle* imageStorages) + const SamplerHandle dstTextureSamplerHandle, + GrSurfaceOrigin dstTextureOrigin) : fXPFragBuilder(fragBuilder) , fUniformHandler(uniformHandler) , fShaderCaps(caps) @@ -44,10 +45,8 @@ public: , fInputCoverage(inputCoverage) , fOutputPrimary(outputPrimary) , fOutputSecondary(outputSecondary) - , fTexSamplers(texSamplers) - , fBufferSamplers(bufferSamplers) - , fImageStorages(imageStorages) {} - + , fDstTextureSamplerHandle(dstTextureSamplerHandle) + , fDstTextureOrigin(dstTextureOrigin) {} GrGLSLXPFragmentBuilder* fXPFragBuilder; GrGLSLUniformHandler* fUniformHandler; const GrShaderCaps* fShaderCaps; @@ -56,9 +55,8 @@ public: const char* fInputCoverage; const char* fOutputPrimary; const char* fOutputSecondary; - const SamplerHandle* fTexSamplers; - const SamplerHandle* fBufferSamplers; - const ImageStorageHandle* fImageStorages; + const SamplerHandle fDstTextureSamplerHandle; + GrSurfaceOrigin fDstTextureOrigin; }; /** * This is similar to emitCode() in the base class, except it takes a full shader builder. @@ -73,7 +71,8 @@ public: to have an identical processor key as the one that created this GrGLSLXferProcessor. This function calls onSetData on the subclass of GrGLSLXferProcessor */ - void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp); + void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp, + const GrTexture* dstTexture, const SkIPoint& dstTextureOffset); protected: static void DefaultCoverageModulation(GrGLSLXPFragmentBuilder* fragBuilder, |