diff options
Diffstat (limited to 'src/gpu/glsl')
-rw-r--r-- | src/gpu/glsl/GrGLSLFragmentProcessor.h | 10 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.cpp | 45 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.h | 2 |
3 files changed, 28 insertions, 29 deletions
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h index 8f903755ea..591146e925 100644 --- a/src/gpu/glsl/GrGLSLFragmentProcessor.h +++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h @@ -38,7 +38,7 @@ private: * the GrFragmentProcessor that generated the GLSLFP. For example, this is used to provide a * variable holding transformed coords for each GrCoordTransform owned by the FP. */ - template <typename T, typename FPBASE, int (FPBASE::*COUNT)() const> + template <typename T, int (GrFragmentProcessor::*COUNT)() const> class BuilderInputProvider { public: BuilderInputProvider(const GrFragmentProcessor* fp, const T* ts) : fFP(fp) , fTs(ts) {} @@ -67,10 +67,10 @@ private: }; public: - using TransformedCoordVars = BuilderInputProvider<GrShaderVar, GrFragmentProcessor, - &GrFragmentProcessor::numCoordTransforms>; - using TextureSamplers = BuilderInputProvider<SamplerHandle, GrResourceIOProcessor, - &GrResourceIOProcessor::numTextureSamplers>; + using TransformedCoordVars = + BuilderInputProvider<GrShaderVar, &GrFragmentProcessor::numCoordTransforms>; + using TextureSamplers = + BuilderInputProvider<SamplerHandle, &GrFragmentProcessor::numTextureSamplers>; /** Called when the program stage should insert its code into the shaders. The code in each shader will be in its own block ({}) and so locally scoped names will not collide across diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp index 05b78eef0c..b0cf8169d4 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp +++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp @@ -96,8 +96,15 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr SkASSERT(!fGeometryProcessor); fGeometryProcessor.reset(proc.createGLSLInstance(*this->shaderCaps())); - SkSTArray<4, SamplerHandle> texSamplers(proc.numTextureSamplers()); - this->emitSamplers(proc, &texSamplers); + SkAutoSTMalloc<4, SamplerHandle> texSamplers(proc.numTextureSamplers()); + for (int i = 0; i < proc.numTextureSamplers(); ++i) { + SkString name; + name.printf("TextureSampler_%d", i); + const auto& sampler = proc.textureSampler(i); + GrTextureType textureType = sampler.peekTexture()->texturePriv().textureType(); + texSamplers[i] = this->emitSampler(textureType, sampler.peekTexture()->config(), + name.c_str(), sampler.visibility()); + } GrGLSLPrimitiveProcessor::FPCoordTransformHandler transformHandler(fPipeline, &fTransformedCoordVars); @@ -111,7 +118,7 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr outputColor->c_str(), outputCoverage->c_str(), rtAdjustName, - texSamplers.begin(), + texSamplers.get(), &transformHandler); fGeometryProcessor->emitCode(args); @@ -168,15 +175,23 @@ SkString GrGLSLProgramBuilder::emitAndInstallFragProc( GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance(); - SkSTArray<4, SamplerHandle> textureSamplerArray(fp.numTextureSamplers()); - GrFragmentProcessor::Iter iter(&fp); - while (const GrFragmentProcessor* subFP = iter.next()) { - this->emitSamplers(*subFP, &textureSamplerArray); + SkSTArray<4, SamplerHandle> texSamplers; + GrFragmentProcessor::Iter fpIter(&fp); + int samplerIdx = 0; + while (const auto* subFP = fpIter.next()) { + for (int i = 0; i < subFP->numTextureSamplers(); ++i) { + SkString name; + name.printf("TextureSampler_%d", samplerIdx++); + const auto& sampler = subFP->textureSampler(i); + GrTextureType textureType = sampler.peekTexture()->texturePriv().textureType(); + texSamplers.emplace_back(this->emitSampler(textureType, sampler.peekTexture()->config(), + name.c_str(), kFragment_GrShaderFlag)); + } } const GrShaderVar* coordVars = fTransformedCoordVars.begin() + transformedCoordVarsIdx; GrGLSLFragmentProcessor::TransformedCoordVars coords(&fp, coordVars); - GrGLSLFragmentProcessor::TextureSamplers textureSamplers(&fp, textureSamplerArray.begin()); + GrGLSLFragmentProcessor::TextureSamplers textureSamplers(&fp, texSamplers.begin()); GrGLSLFragmentProcessor::EmitArgs args(&fFS, this->uniformHandler(), this->shaderCaps(), @@ -250,20 +265,6 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn, fFS.codeAppend("}"); } -void GrGLSLProgramBuilder::emitSamplers( - const GrResourceIOProcessor& processor, - SkTArray<SamplerHandle>* outTexSamplerHandles) { - SkString name; - int numTextureSamplers = processor.numTextureSamplers(); - for (int t = 0; t < numTextureSamplers; ++t) { - const GrResourceIOProcessor::TextureSampler& sampler = processor.textureSampler(t); - name.printf("TextureSampler_%d", outTexSamplerHandles->count()); - GrTextureType textureType = sampler.peekTexture()->texturePriv().textureType(); - outTexSamplerHandles->emplace_back(this->emitSampler( - textureType, sampler.peekTexture()->config(), name.c_str(), sampler.visibility())); - } -} - void GrGLSLProgramBuilder::updateSamplerCounts(GrShaderFlags visibility) { if (visibility & kVertex_GrShaderFlag) { ++fNumVertexSamplers; diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h index bdc39c00dd..8d263b8e00 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.h +++ b/src/gpu/glsl/GrGLSLProgramBuilder.h @@ -135,8 +135,6 @@ private: SkString output, SkTArray<std::unique_ptr<GrGLSLFragmentProcessor>>*); void emitAndInstallXferProc(const SkString& colorIn, const SkString& coverageIn); - void emitSamplers(const GrResourceIOProcessor& processor, - SkTArray<SamplerHandle>* outTexSamplerHandles); SamplerHandle emitSampler(GrTextureType, GrPixelConfig, const char* name, GrShaderFlags visibility); void emitFSOutputSwizzle(bool hasSecondaryOutput); |