diff options
author | Brian Salomon <bsalomon@google.com> | 2016-11-18 11:58:54 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-21 18:01:43 +0000 |
commit | 101b844d6ba031de5c4e95b43f9292f266799237 (patch) | |
tree | 138593a7d161695e26b691db6557fd1b22914b4d /src/gpu | |
parent | 3502c5cc736f131674147ed19f1942f83f5fb9a4 (diff) |
Remove GrGLSLSampler type and subclasses
GrGLSLUniformManager and GrGLSLProgramDataManager subclasses handle sampler variation across GPU backends.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5002
Change-Id: I968b006bab978c2fa209d1f7eda710c298d1212f
Reviewed-on: https://skia-review.googlesource.com/5002
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu')
24 files changed, 157 insertions, 359 deletions
diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp index 51f305115a..e3129fd68e 100644 --- a/src/gpu/effects/GrTextureDomain.cpp +++ b/src/gpu/effects/GrTextureDomain.cpp @@ -12,7 +12,6 @@ #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" #include "glsl/GrGLSLProgramDataManager.h" -#include "glsl/GrGLSLSampler.h" #include "glsl/GrGLSLShaderBuilder.h" #include "glsl/GrGLSLUniformHandler.h" diff --git a/src/gpu/effects/GrTextureDomain.h b/src/gpu/effects/GrTextureDomain.h index 4c3cf22dee..3ba6ee849f 100644 --- a/src/gpu/effects/GrTextureDomain.h +++ b/src/gpu/effects/GrTextureDomain.h @@ -15,7 +15,6 @@ class GrGLProgramBuilder; class GrGLSLShaderBuilder; class GrInvariantOutput; -class GrGLSLSampler; class GrGLSLUniformHandler; struct SkRect; diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 27361e786d..1f2e1c8446 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -31,7 +31,7 @@ GrGLProgram::GrGLProgram(GrGLGpu* gpu, const BuiltinUniformHandles& builtinUniforms, GrGLuint programID, const UniformInfoArray& uniforms, - const SkTArray<GrGLSampler>& samplers, + const UniformInfoArray& samplers, const VaryingInfoArray& pathProcVaryings, GrGLSLPrimitiveProcessor* geometryProcessor, GrGLSLXferProcessor* xferProcessor, diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index 157f404128..3b0940e0d2 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -111,8 +111,8 @@ protected: const GrProgramDesc&, const BuiltinUniformHandles&, GrGLuint programID, - const UniformInfoArray&, - const SkTArray<GrGLSampler>&, + const UniformInfoArray& uniforms, + const UniformInfoArray& samplers, const VaryingInfoArray&, // used for NVPR only currently GrGLSLPrimitiveProcessor* geometryProcessor, GrGLSLXferProcessor* xferProcessor, diff --git a/src/gpu/gl/GrGLProgramDataManager.cpp b/src/gpu/gl/GrGLProgramDataManager.cpp index 9fe7d3b4f7..68d01669a8 100644 --- a/src/gpu/gl/GrGLProgramDataManager.cpp +++ b/src/gpu/gl/GrGLProgramDataManager.cpp @@ -30,18 +30,7 @@ GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID, uniform.fArrayCount = builderUniform.fVariable.getArrayCount(); uniform.fType = builderUniform.fVariable.getType(); ); - // TODO: Move the Xoom uniform array in both FS and VS bug workaround here. - - if (kVertex_GrShaderFlag & builderUniform.fVisibility) { - uniform.fVSLocation = builderUniform.fLocation; - } else { - uniform.fVSLocation = kUnusedUniform; - } - if (kFragment_GrShaderFlag & builderUniform.fVisibility) { - uniform.fFSLocation = builderUniform.fLocation; - } else { - uniform.fFSLocation = kUnusedUniform; - } + uniform.fLocation = builderUniform.fLocation; } // NVPR programs have separable varyings @@ -61,30 +50,17 @@ GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID, } } -void GrGLProgramDataManager::setSamplers(const SkTArray<GrGLSampler>& samplers) const { +void GrGLProgramDataManager::setSamplers(const UniformInfoArray& samplers) const { for (int i = 0; i < samplers.count(); ++i) { - GrGLint vsLocation; - GrGLint fsLocation; - const GrGLSampler& sampler = samplers[i]; - if (kVertex_GrShaderFlag & sampler.visibility()) { - vsLocation = sampler.location(); + const UniformInfo& sampler = samplers[i]; + SkASSERT(sampler.fVisibility); + if (kUnusedUniform != sampler.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform1i(sampler.fLocation, i)); } else { - vsLocation = kUnusedUniform; - } - if (kFragment_GrShaderFlag & sampler.visibility()) { - fsLocation = sampler.location(); - } else { - fsLocation = kUnusedUniform; - } - // FIXME: We still insert a single sampler uniform for every stage. If the shader does not - // reference the sampler then the compiler may have optimized it out. Uncomment this assert - // once stages insert their own samplers. - // this->printUnused(uni); - if (kUnusedUniform != fsLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform1i(fsLocation, i)); - } - if (kUnusedUniform != vsLocation && vsLocation != fsLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform1i(vsLocation, i)); + // FIXME: We still insert a single sampler uniform for every stage. If the shader does + // not reference the sampler then the compiler may have optimized it out. Uncomment this + // assert once stages insert their own samplers. + // this->printUnused(uni); } } } @@ -94,11 +70,8 @@ void GrGLProgramDataManager::set1i(UniformHandle u, int32_t i) const { SkASSERT(uni.fType == kInt_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); SkDEBUGCODE(this->printUnused(uni)); - if (kUnusedUniform != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, i)); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, i)); + if (kUnusedUniform != uni.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fLocation, i)); } } @@ -109,11 +82,8 @@ void GrGLProgramDataManager::set1iv(UniformHandle u, SkASSERT(uni.fType == kInt_GrSLType); SkASSERT(arrayCount > 0); ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); - if (kUnusedUniform != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform1iv(uni.fFSLocation, arrayCount, v)); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform1iv(uni.fVSLocation, arrayCount, v)); + if (kUnusedUniform != uni.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform1iv(uni.fLocation, arrayCount, v)); } } @@ -122,11 +92,8 @@ void GrGLProgramDataManager::set1f(UniformHandle u, float v0) const { SkASSERT(uni.fType == kFloat_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); SkDEBUGCODE(this->printUnused(uni);) - if (kUnusedUniform != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0)); + if (kUnusedUniform != uni.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fLocation, v0)); } } @@ -141,11 +108,8 @@ void GrGLProgramDataManager::set1fv(UniformHandle u, // Once the uniform manager is responsible for inserting the duplicate uniform // arrays in VS and FS driver bug workaround, this can be enabled. // this->printUni(uni); - if (kUnusedUniform != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount, v)); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount, v)); + if (kUnusedUniform != uni.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fLocation, arrayCount, v)); } } @@ -154,11 +118,8 @@ void GrGLProgramDataManager::set2f(UniformHandle u, float v0, float v1) const { SkASSERT(uni.fType == kVec2f_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); SkDEBUGCODE(this->printUnused(uni);) - if (kUnusedUniform != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1)); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1)); + if (kUnusedUniform != uni.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fLocation, v0, v1)); } } @@ -170,11 +131,8 @@ void GrGLProgramDataManager::set2fv(UniformHandle u, SkASSERT(arrayCount > 0); ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); SkDEBUGCODE(this->printUnused(uni);) - if (kUnusedUniform != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount, v)); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount, v)); + if (kUnusedUniform != uni.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fLocation, arrayCount, v)); } } @@ -183,11 +141,8 @@ void GrGLProgramDataManager::set3f(UniformHandle u, float v0, float v1, float v2 SkASSERT(uni.fType == kVec3f_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); SkDEBUGCODE(this->printUnused(uni);) - if (kUnusedUniform != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2)); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2)); + if (kUnusedUniform != uni.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fLocation, v0, v1, v2)); } } @@ -199,11 +154,8 @@ void GrGLProgramDataManager::set3fv(UniformHandle u, SkASSERT(arrayCount > 0); ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); SkDEBUGCODE(this->printUnused(uni);) - if (kUnusedUniform != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount, v)); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount, v)); + if (kUnusedUniform != uni.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fLocation, arrayCount, v)); } } @@ -216,11 +168,8 @@ void GrGLProgramDataManager::set4f(UniformHandle u, SkASSERT(uni.fType == kVec4f_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); SkDEBUGCODE(this->printUnused(uni);) - if (kUnusedUniform != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v3)); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v3)); + if (kUnusedUniform != uni.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fLocation, v0, v1, v2, v3)); } } @@ -232,11 +181,8 @@ void GrGLProgramDataManager::set4fv(UniformHandle u, SkASSERT(arrayCount > 0); ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); SkDEBUGCODE(this->printUnused(uni);) - if (kUnusedUniform != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount, v)); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount, v)); + if (kUnusedUniform != uni.fLocation) { + GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fLocation, arrayCount, v)); } } @@ -274,11 +220,8 @@ template<int N> inline void GrGLProgramDataManager::setMatrices(UniformHandle u, SkASSERT(arrayCount > 0); ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); SkDEBUGCODE(this->printUnused(uni);) - if (kUnusedUniform != uni.fFSLocation) { - set_uniform_matrix<N>::set(fGpu->glInterface(), uni.fFSLocation, arrayCount, matrices); - } - if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { - set_uniform_matrix<N>::set(fGpu->glInterface(), uni.fVSLocation, arrayCount, matrices); + if (kUnusedUniform != uni.fLocation) { + set_uniform_matrix<N>::set(fGpu->glInterface(), uni.fLocation, arrayCount, matrices); } } @@ -318,7 +261,7 @@ void GrGLProgramDataManager::setPathFragmentInputTransform(VaryingHandle u, #ifdef SK_DEBUG void GrGLProgramDataManager::printUnused(const Uniform& uni) const { - if (kUnusedUniform == uni.fFSLocation && kUnusedUniform == uni.fVSLocation) { + if (kUnusedUniform == uni.fLocation) { GrCapsDebugf(fGpu->caps(), "Unused uniform in shader\n"); } } diff --git a/src/gpu/gl/GrGLProgramDataManager.h b/src/gpu/gl/GrGLProgramDataManager.h index 30c4a63ebc..fa1456dcc7 100644 --- a/src/gpu/gl/GrGLProgramDataManager.h +++ b/src/gpu/gl/GrGLProgramDataManager.h @@ -11,7 +11,6 @@ #include "glsl/GrGLSLProgramDataManager.h" #include "GrAllocator.h" -#include "gl/GrGLSampler.h" #include "gl/GrGLTypes.h" #include "glsl/GrGLSLShaderVar.h" @@ -38,6 +37,7 @@ public: GrGLint fLocation; }; + // This uses an allocator rather than array so that the GrGLSLShaderVars don't move in memory // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their // name strings. Otherwise, we'd have to hand out copies. @@ -48,7 +48,7 @@ public: const VaryingInfoArray&); - void setSamplers(const SkTArray<GrGLSampler>& samplers) const; + void setSamplers(const UniformInfoArray& samplers) const; /** Functions for uploading uniform values. The varities ending in v can be used to upload to an * array of uniforms. arrayCount must be <= the array count of the uniform. @@ -82,12 +82,11 @@ private: }; struct Uniform { - GrGLint fVSLocation; - GrGLint fFSLocation; - SkDEBUGCODE( - GrSLType fType; - int fArrayCount; - ); + GrGLint fLocation; +#ifdef SK_DEBUG + GrSLType fType; + int fArrayCount; +#endif }; enum { diff --git a/src/gpu/gl/GrGLSampler.h b/src/gpu/gl/GrGLSampler.h deleted file mode 100644 index 1f67ac9a5e..0000000000 --- a/src/gpu/gl/GrGLSampler.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -* Copyright 2016 Google Inc. -* -* Use of this source code is governed by a BSD-style license that can be -* found in the LICENSE file. -*/ - -#ifndef GrGLSampler_DEFINED -#define GrGLSampler_DEFINED - -#include "glsl/GrGLSLSampler.h" - -#include "gl/GrGLTypes.h" -#include "glsl/GrGLSLShaderVar.h" - -class GrGLSampler : public GrGLSLSampler { -public: - GrGLSampler(uint32_t visibility, - GrPixelConfig config, - GrSLType type, - GrSLPrecision precision, - const char* name) : INHERITED(visibility, config) { - SkASSERT(GrSLTypeIsCombinedSamplerType(type)); - fShaderVar.setType(type); - fShaderVar.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier); - fShaderVar.setPrecision(precision); - fShaderVar.accessName()->set(name); - } - - GrGLint location() const { return fLocation; } - GrSLType type() const override { return fShaderVar.getType(); } - - const char* onGetSamplerNameForTexture2D() const override { return fShaderVar.c_str(); } - const char* getSamplerNameForTexelFetch() const override { return fShaderVar.c_str(); } - -private: - GrGLSLShaderVar fShaderVar; - GrGLint fLocation; - - friend class GrGLUniformHandler; - - typedef GrGLSLSampler INHERITED; -}; - -#endif diff --git a/src/gpu/gl/GrGLUniformHandler.cpp b/src/gpu/gl/GrGLUniformHandler.cpp index c388e4621b..37f241838f 100644 --- a/src/gpu/gl/GrGLUniformHandler.cpp +++ b/src/gpu/gl/GrGLUniformHandler.cpp @@ -45,6 +45,7 @@ GrGLSLUniformHandler::UniformHandle GrGLUniformHandler::internalAddUniformArray( uni.fVariable.setArrayCount(arrayCount); uni.fVisibility = visibility; uni.fVariable.setPrecision(precision); + uni.fLocation = -1; if (outName) { *outName = uni.fVariable.c_str(); @@ -52,19 +53,30 @@ GrGLSLUniformHandler::UniformHandle GrGLUniformHandler::internalAddUniformArray( return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1); } -GrGLSLUniformHandler::SamplerHandle GrGLUniformHandler::internalAddSampler(uint32_t visibility, - GrPixelConfig config, - GrSLType type, - GrSLPrecision precision, - const char* name) { +GrGLSLUniformHandler::SamplerHandle GrGLUniformHandler::addSampler(uint32_t visibility, + GrSwizzle swizzle, + GrSLType type, + GrSLPrecision precision, + const char* name) { SkASSERT(name && strlen(name)); SkDEBUGCODE(static const uint32_t kVisMask = kVertex_GrShaderFlag | kFragment_GrShaderFlag); SkASSERT(0 == (~kVisMask & visibility)); SkASSERT(0 != visibility); + SkString mangleName; char prefix = 'u'; fProgramBuilder->nameVariable(&mangleName, prefix, name, true); - fSamplers.emplace_back(visibility, config, type, precision, mangleName.c_str()); + + UniformInfo& sampler = fSamplers.push_back(); + SkASSERT(GrSLTypeIsCombinedSamplerType(type)); + sampler.fVariable.setType(type); + sampler.fVariable.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier); + sampler.fVariable.setPrecision(precision); + sampler.fVariable.setName(mangleName); + sampler.fLocation = -1; + sampler.fVisibility = visibility; + fSamplerSwizzles.push_back(swizzle); + SkASSERT(fSamplers.count() == fSamplerSwizzles.count()); return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1); } @@ -76,8 +88,8 @@ void GrGLUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* } } for (int i = 0; i < fSamplers.count(); ++i) { - if (fSamplers[i].visibility() & visibility) { - fSamplers[i].fShaderVar.appendDecl(fProgramBuilder->glslCaps(), out); + if (fSamplers[i].fVisibility & visibility) { + fSamplers[i].fVariable.appendDecl(fProgramBuilder->glslCaps(), out); out->append(";\n"); } } @@ -92,7 +104,7 @@ void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps } for (int i = 0; i < fSamplers.count(); ++i) { GrGLint location = i + uniformCnt; - GL_CALL(BindUniformLocation(programID, location, fSamplers[i].fShaderVar.c_str())); + GL_CALL(BindUniformLocation(programID, location, fSamplers[i].fVariable.c_str())); fSamplers[i].fLocation = location; } } @@ -108,7 +120,7 @@ void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps& } for (int i = 0; i < fSamplers.count(); ++i) { GrGLint location; - GL_CALL_RET(location, GetUniformLocation(programID, fSamplers[i].fShaderVar.c_str())); + GL_CALL_RET(location, GetUniformLocation(programID, fSamplers[i].fVariable.c_str())); fSamplers[i].fLocation = location; } } diff --git a/src/gpu/gl/GrGLUniformHandler.h b/src/gpu/gl/GrGLUniformHandler.h index 3656d3a108..da5b96d0ca 100644 --- a/src/gpu/gl/GrGLUniformHandler.h +++ b/src/gpu/gl/GrGLUniformHandler.h @@ -11,7 +11,6 @@ #include "glsl/GrGLSLUniformHandler.h" #include "gl/GrGLProgramDataManager.h" -#include "gl/GrGLSampler.h" class GrGLCaps; @@ -29,7 +28,8 @@ public: private: explicit GrGLUniformHandler(GrGLSLProgramBuilder* program) : INHERITED(program) - , fUniforms(kUniformsPerBlock) {} + , fUniforms(kUniformsPerBlock) + , fSamplers(kUniformsPerBlock) {} UniformHandle internalAddUniformArray(uint32_t visibility, GrSLType type, @@ -39,15 +39,15 @@ private: int arrayCount, const char** outName) override; - SamplerHandle internalAddSampler(uint32_t visibility, - GrPixelConfig config, - GrSLType type, - GrSLPrecision precision, - const char* name) override; + SamplerHandle addSampler(uint32_t visibility, GrSwizzle, GrSLType, GrSLPrecision, + const char* name) override; - int numSamplers() const override { return fSamplers.count(); } - const GrGLSLSampler& getSampler(SamplerHandle handle) const override { - return fSamplers[handle.toIndex()]; + const GrGLSLShaderVar& samplerVariable(SamplerHandle handle) const override { + return fSamplers[handle.toIndex()].fVariable; + } + + GrSwizzle samplerSwizzle(SamplerHandle handle) const override { + return fSamplerSwizzles[handle.toIndex()]; } void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; @@ -63,9 +63,9 @@ private: typedef GrGLProgramDataManager::UniformInfo UniformInfo; typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; - UniformInfoArray fUniforms; - - SkTArray<GrGLSampler> fSamplers; + UniformInfoArray fUniforms; + UniformInfoArray fSamplers; + SkTArray<GrSwizzle> fSamplerSwizzles; friend class GrGLProgramBuilder; diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index 370cee6a0e..e951c6bcf9 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -22,7 +22,6 @@ #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLGeometryProcessor.h" #include "glsl/GrGLSLProgramDataManager.h" -#include "glsl/GrGLSLSampler.h" #include "glsl/GrGLSLXferProcessor.h" #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h index 2189250d7c..aba68b7e05 100644 --- a/src/gpu/glsl/GrGLSLFragmentProcessor.h +++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h @@ -11,7 +11,6 @@ #include "GrFragmentProcessor.h" #include "GrShaderVar.h" #include "glsl/GrGLSLProgramDataManager.h" -#include "glsl/GrGLSLSampler.h" class GrProcessor; class GrProcessorKeyBuilder; diff --git a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h index d270fa18fe..fd77bdd42a 100644 --- a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h +++ b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h @@ -11,7 +11,6 @@ #include "GrFragmentProcessor.h" #include "GrPrimitiveProcessor.h" #include "glsl/GrGLSLProgramDataManager.h" -#include "glsl/GrGLSLSampler.h" class GrBatchTracker; class GrPrimitiveProcessor; diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp index 1e78788600..7dea0be761 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp +++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp @@ -295,8 +295,9 @@ void GrGLSLProgramBuilder::emitSampler(GrSLType samplerType, ++fNumFragmentSamplers; } GrSLPrecision precision = this->glslCaps()->samplerPrecision(config, visibility); + GrSwizzle swizzle = this->glslCaps()->configTextureSwizzle(config); SamplerHandle handle = this->uniformHandler()->addSampler(visibility, - config, + swizzle, samplerType, precision, name); @@ -390,9 +391,6 @@ void GrGLSLProgramBuilder::appendUniformDecls(GrShaderFlags visibility, SkString this->uniformHandler()->appendUniformDecls(visibility, out); } -const GrGLSLSampler& GrGLSLProgramBuilder::getSampler(SamplerHandle handle) const { - return this->uniformHandler()->getSampler(handle); -} void GrGLSLProgramBuilder::addRTAdjustmentUniform(GrSLPrecision precision, const char* name, diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h index 8a8cff55ad..727614455f 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.h +++ b/src/gpu/glsl/GrGLSLProgramBuilder.h @@ -16,7 +16,6 @@ #include "glsl/GrGLSLPrimitiveProcessor.h" #include "glsl/GrGLSLProgramDataManager.h" #include "glsl/GrGLSLUniformHandler.h" -#include "glsl/GrGLSLSampler.h" #include "glsl/GrGLSLVertexShaderBuilder.h" #include "glsl/GrGLSLXferProcessor.h" @@ -44,7 +43,13 @@ public: typedef GrGLSLUniformHandler::SamplerHandle SamplerHandle; - const GrGLSLSampler& getSampler(SamplerHandle handle) const; + const GrGLSLShaderVar& samplerVariable(SamplerHandle handle) const { + return this->uniformHandler()->samplerVariable(handle); + } + + GrSwizzle samplerSwizzle(SamplerHandle handle) const { + return this->uniformHandler()->samplerSwizzle(handle); + } // Handles for program uniforms (other than per-effect uniforms) struct BuiltinUniformHandles { diff --git a/src/gpu/glsl/GrGLSLSampler.h b/src/gpu/glsl/GrGLSLSampler.h deleted file mode 100644 index bc90769295..0000000000 --- a/src/gpu/glsl/GrGLSLSampler.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrGLSLSampler_DEFINED -#define GrGLSLSampler_DEFINED - -#include "GrTypes.h" -#include "GrTypesPriv.h" -#include "SkString.h" - -class GrGLSLSampler { -public: - virtual ~GrGLSLSampler() {} - - explicit GrGLSLSampler(uint32_t visibility, GrPixelConfig config) - : fVisibility(visibility) - , fConfig(config) { - SkASSERT(kUnknown_GrPixelConfig != fConfig); - } - - uint32_t visibility() const { return fVisibility; } - GrPixelConfig config() const { return fConfig; } - virtual GrSLType type() const = 0; - - // Returns the string to be used for the sampler in glsl 2D texture functions (texture, - // texture2D, etc.) - const char* getSamplerNameForTexture2D() const { - SkASSERT(GrSLTypeIs2DCombinedSamplerType(this->type())); - return this->onGetSamplerNameForTexture2D(); - } - - // Returns the string to be used for the sampler in glsl texelFetch. - virtual const char* getSamplerNameForTexelFetch() const = 0; - -private: - virtual const char* onGetSamplerNameForTexture2D() const = 0; - uint32_t fVisibility; - GrPixelConfig fConfig; -}; - -#endif diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp index 6d77bdbf9a..2e7977938a 100644 --- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp @@ -10,7 +10,6 @@ #include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLColorSpaceXformHelper.h" #include "glsl/GrGLSLShaderVar.h" -#include "glsl/GrGLSLSampler.h" #include "glsl/GrGLSLProgramBuilder.h" GrGLSLShaderBuilder::GrGLSLShaderBuilder(GrGLSLProgramBuilder* program) @@ -63,38 +62,37 @@ void GrGLSLShaderBuilder::emitFunction(GrSLType returnType, this->functions().append("}\n\n"); } +static inline void append_texture_swizzle(SkString* out, GrSwizzle swizzle) { + if (swizzle != GrSwizzle::RGBA()) { + out->appendf(".%s", swizzle.c_str()); + } +} + void GrGLSLShaderBuilder::appendTextureLookup(SkString* out, SamplerHandle samplerHandle, const char* coordName, GrSLType varyingType) const { const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); - const GrGLSLSampler& sampler = fProgramBuilder->getSampler(samplerHandle); - GrSLType samplerType = sampler.type(); + const GrGLSLShaderVar& sampler = fProgramBuilder->samplerVariable(samplerHandle); + GrSLType samplerType = sampler.getType(); if (samplerType == kTexture2DRectSampler_GrSLType) { if (varyingType == kVec2f_GrSLType) { out->appendf("%s(%s, textureSize(%s) * %s)", GrGLSLTexture2DFunctionName(varyingType, samplerType, glslCaps->generation()), - sampler.getSamplerNameForTexture2D(), - sampler.getSamplerNameForTexture2D(), - coordName); + sampler.c_str(), sampler.c_str(), coordName); } else { out->appendf("%s(%s, vec3(textureSize(%s) * %s.xy, %s.z))", GrGLSLTexture2DFunctionName(varyingType, samplerType, glslCaps->generation()), - sampler.getSamplerNameForTexture2D(), - sampler.getSamplerNameForTexture2D(), - coordName, - coordName); + sampler.c_str(), sampler.c_str(), coordName, coordName); } } else { out->appendf("%s(%s, %s)", GrGLSLTexture2DFunctionName(varyingType, samplerType, glslCaps->generation()), - sampler.getSamplerNameForTexture2D(), - coordName); + sampler.c_str(), coordName); } - - this->appendTextureSwizzle(out, sampler.config()); + append_texture_swizzle(out, fProgramBuilder->samplerSwizzle(samplerHandle)); } void GrGLSLShaderBuilder::appendTextureLookup(SamplerHandle samplerHandle, @@ -164,27 +162,19 @@ void GrGLSLShaderBuilder::appendColorGamutXform(const char* srcColor, void GrGLSLShaderBuilder::appendTexelFetch(SkString* out, SamplerHandle samplerHandle, const char* coordExpr) const { - const GrGLSLSampler& sampler = fProgramBuilder->getSampler(samplerHandle); + const GrGLSLShaderVar& sampler = fProgramBuilder->samplerVariable(samplerHandle); SkASSERT(fProgramBuilder->glslCaps()->texelFetchSupport()); - SkASSERT(GrSLTypeIsCombinedSamplerType(sampler.type())); + SkASSERT(GrSLTypeIsCombinedSamplerType(sampler.getType())); - out->appendf("texelFetch(%s, %s)", sampler.getSamplerNameForTexelFetch(), coordExpr); + out->appendf("texelFetch(%s, %s)", sampler.c_str(), coordExpr); - this->appendTextureSwizzle(out, sampler.config()); + append_texture_swizzle(out, fProgramBuilder->samplerSwizzle(samplerHandle)); } void GrGLSLShaderBuilder::appendTexelFetch(SamplerHandle samplerHandle, const char* coordExpr) { this->appendTexelFetch(&this->code(), samplerHandle, coordExpr); } -void GrGLSLShaderBuilder::appendTextureSwizzle(SkString* out, GrPixelConfig config) const { - const GrSwizzle& configSwizzle = fProgramBuilder->glslCaps()->configTextureSwizzle(config); - - if (configSwizzle != GrSwizzle::RGBA()) { - out->appendf(".%s", configSwizzle.c_str()); - } -} - bool GrGLSLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionName) { if (featureBit & fFeaturesAddedMask) { return false; diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.h b/src/gpu/glsl/GrGLSLShaderBuilder.h index 378f523de9..2ab0eecf91 100644 --- a/src/gpu/glsl/GrGLSLShaderBuilder.h +++ b/src/gpu/glsl/GrGLSLShaderBuilder.h @@ -29,8 +29,8 @@ public: /** Appends a 2D texture sample with projection if necessary. coordType must either be Vec2f or Vec3f. The latter is interpreted as projective texture coords. The vec length and swizzle - order of the result depends on the GrProcessor::TextureSampelr associated with the - GrGLSLSampler. + order of the result depends on the GrProcessor::TextureSampler associated with the + SamplerHandle. */ void appendTextureLookup(SkString* out, SamplerHandle, @@ -45,7 +45,7 @@ public: /** Does the work of appendTextureLookup and modulates the result by modulation. The result is - always a vec4. modulation and the swizzle specified by GrGLSLSampler must both be + always a vec4. modulation and the swizzle specified by SamplerHandle must both be vec4 or float. If modulation is "" or nullptr it this function acts as though appendTextureLookup were called. */ void appendTextureLookupAndModulate(const char* modulation, @@ -203,12 +203,6 @@ protected: void compileAndAppendLayoutQualifiers(); - /* Appends any swizzling we may need to get from some backend internal format to the format used - * in GrPixelConfig. If this is implemented by the GrGpu object, then swizzle will be rgba. For - * shader prettiness we omit the swizzle rather than appending ".rgba". - */ - void appendTextureSwizzle(SkString* out, GrPixelConfig) const; - void nextStage() { fShaderStrings.push_back(); fCompilerStrings.push_back(this->code().c_str()); diff --git a/src/gpu/glsl/GrGLSLUniformHandler.h b/src/gpu/glsl/GrGLSLUniformHandler.h index d7b213869c..657be6a804 100644 --- a/src/gpu/glsl/GrGLSLUniformHandler.h +++ b/src/gpu/glsl/GrGLSLUniformHandler.h @@ -12,7 +12,6 @@ #include "GrGLSLShaderVar.h" class GrGLSLProgramBuilder; -class GrGLSLSampler; class GrGLSLUniformHandler { public: @@ -61,22 +60,11 @@ protected: GrGLSLProgramBuilder* fProgramBuilder; private: - virtual int numSamplers() const = 0; - virtual const GrGLSLSampler& getSampler(SamplerHandle handle) const = 0; + virtual const GrGLSLShaderVar& samplerVariable(SamplerHandle) const = 0; + virtual GrSwizzle samplerSwizzle(SamplerHandle) const = 0; - SamplerHandle addSampler(uint32_t visibility, - GrPixelConfig config, - GrSLType type, - GrSLPrecision precision, - const char* name) { - return this->internalAddSampler(visibility, config, type, precision, name); - } - - virtual SamplerHandle internalAddSampler(uint32_t visibility, - GrPixelConfig config, - GrSLType type, - GrSLPrecision precision, - const char* name) = 0; + virtual SamplerHandle addSampler(uint32_t visibility, GrSwizzle, GrSLType, GrSLPrecision, + const char* name) = 0; virtual UniformHandle internalAddUniformArray(uint32_t visibility, GrSLType type, diff --git a/src/gpu/glsl/GrGLSLXferProcessor.h b/src/gpu/glsl/GrGLSLXferProcessor.h index f4a8ebdfa0..bf6ee64299 100644 --- a/src/gpu/glsl/GrGLSLXferProcessor.h +++ b/src/gpu/glsl/GrGLSLXferProcessor.h @@ -9,7 +9,6 @@ #define GrGLSLXferProcessor_DEFINED #include "glsl/GrGLSLProgramDataManager.h" -#include "glsl/GrGLSLSampler.h" class GrXferProcessor; class GrGLSLCaps; diff --git a/src/gpu/vk/GrVkDescriptorSetManager.cpp b/src/gpu/vk/GrVkDescriptorSetManager.cpp index d05a11c49f..f523cee960 100644 --- a/src/gpu/vk/GrVkDescriptorSetManager.cpp +++ b/src/gpu/vk/GrVkDescriptorSetManager.cpp @@ -11,7 +11,6 @@ #include "GrVkDescriptorSet.h" #include "GrVkGpu.h" #include "GrVkUniformHandler.h" -#include "glsl/GrGLSLSampler.h" GrVkDescriptorSetManager::GrVkDescriptorSetManager(GrVkGpu* gpu, VkDescriptorType type, @@ -20,7 +19,7 @@ GrVkDescriptorSetManager::GrVkDescriptorSetManager(GrVkGpu* gpu, if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) { SkASSERT(uniformHandler); for (int i = 0; i < uniformHandler->numSamplers(); ++i) { - fBindingVisibilities.push_back(uniformHandler->getSampler(i).visibility()); + fBindingVisibilities.push_back(uniformHandler->samplerVisibility(i)); } } else { SkASSERT(type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); @@ -103,7 +102,7 @@ bool GrVkDescriptorSetManager::isCompatible(VkDescriptorType type, return false; } for (int i = 0; i < uniHandler->numSamplers(); ++i) { - if (uniHandler->getSampler(i).visibility() != fBindingVisibilities[i]) { + if (uniHandler->samplerVisibility(i) != fBindingVisibilities[i]) { return false; } } @@ -185,10 +184,7 @@ void GrVkDescriptorSetManager::DescriptorPoolManager::init(GrVkGpu* gpu, for (uint32_t i = 0; i < numSamplers; ++i) { uint32_t visibility; if (uniformHandler) { - const GrVkGLSLSampler& sampler = - static_cast<const GrVkGLSLSampler&>(uniformHandler->getSampler(i)); - SkASSERT(sampler.binding() == i); - visibility = sampler.visibility(); + visibility = uniformHandler->samplerVisibility(i); } else { visibility = (*visibilities)[i]; } diff --git a/src/gpu/vk/GrVkGLSLSampler.h b/src/gpu/vk/GrVkGLSLSampler.h deleted file mode 100644 index f0ba7fa335..0000000000 --- a/src/gpu/vk/GrVkGLSLSampler.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -* Copyright 2016 Google Inc. -* -* Use of this source code is governed by a BSD-style license that can be -* found in the LICENSE file. -*/ - -#ifndef GrVkGLSLSampler_DEFINED -#define GrVkGLSLSampler_DEFINED - -#include "glsl/GrGLSLSampler.h" - -#include "glsl/GrGLSLShaderVar.h" - -class GrVkGLSLSampler : public GrGLSLSampler { -public: - GrVkGLSLSampler(uint32_t visibility, - GrPixelConfig config, - GrSLType type, - GrSLPrecision precision, - const char* name, - uint32_t binding, - uint32_t set) : INHERITED(visibility, config), fBinding(binding) { - SkASSERT(GrSLTypeIsCombinedSamplerType(type)); - fShaderVar.setType(type); - fShaderVar.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier); - fShaderVar.setPrecision(precision); - fShaderVar.accessName()->set(name); - SkString layoutQualifier; - layoutQualifier.appendf("set=%d, binding=%d", set, binding); - fShaderVar.setLayoutQualifier(layoutQualifier.c_str()); - } - - GrSLType type() const override { return fShaderVar.getType(); } - uint32_t binding() const { return fBinding; } - - const char* onGetSamplerNameForTexture2D() const override { return fShaderVar.c_str(); } - const char* getSamplerNameForTexelFetch() const override { return fShaderVar.c_str(); } - -private: - GrGLSLShaderVar fShaderVar; - uint32_t fBinding; - - friend class GrVkUniformHandler; - - typedef GrGLSLSampler INHERITED; -}; - -#endif diff --git a/src/gpu/vk/GrVkResourceProvider.cpp b/src/gpu/vk/GrVkResourceProvider.cpp index 81e1738595..487633d3dc 100644 --- a/src/gpu/vk/GrVkResourceProvider.cpp +++ b/src/gpu/vk/GrVkResourceProvider.cpp @@ -10,7 +10,6 @@ #include "GrSamplerParams.h" #include "GrVkCommandBuffer.h" #include "GrVkCopyPipeline.h" -#include "GrVkGLSLSampler.h" #include "GrVkPipeline.h" #include "GrVkRenderTarget.h" #include "GrVkSampler.h" diff --git a/src/gpu/vk/GrVkUniformHandler.cpp b/src/gpu/vk/GrVkUniformHandler.cpp index 212095aee4..1da411934d 100644 --- a/src/gpu/vk/GrVkUniformHandler.cpp +++ b/src/gpu/vk/GrVkUniformHandler.cpp @@ -168,11 +168,11 @@ GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray( return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1); } -GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::internalAddSampler(uint32_t visibility, - GrPixelConfig config, - GrSLType type, - GrSLPrecision precision, - const char* name) { +GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(uint32_t visibility, + GrSwizzle swizzle, + GrSLType type, + GrSLPrecision precision, + const char* name) { SkASSERT(name && strlen(name)); SkDEBUGCODE(static const uint32_t kVisMask = kVertex_GrShaderFlag | kFragment_GrShaderFlag); SkASSERT(0 == (~kVisMask & visibility)); @@ -180,8 +180,20 @@ GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::internalAddSampler(uint3 SkString mangleName; char prefix = 'u'; fProgramBuilder->nameVariable(&mangleName, prefix, name, true); - fSamplers.emplace_back(visibility, config, type, precision, mangleName.c_str(), - (uint32_t)fSamplers.count(), kSamplerDescSet); + + UniformInfo& info = fSamplers.push_back(); + SkASSERT(GrSLTypeIsCombinedSamplerType(type)); + info.fVariable.setType(type); + info.fVariable.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier); + info.fVariable.setPrecision(precision); + info.fVariable.setName(mangleName); + SkString layoutQualifier; + layoutQualifier.appendf("set=%d, binding=%d", kSamplerDescSet, fSamplers.count() - 1); + info.fVariable.setLayoutQualifier(layoutQualifier.c_str()); + info.fVisibility = visibility; + info.fUBOffset = 0; + fSamplerSwizzles.push_back(swizzle); + SkASSERT(fSamplerSwizzles.count() == fSamplers.count()); return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1); } @@ -189,10 +201,10 @@ void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == visibility); for (int i = 0; i < fSamplers.count(); ++i) { - const GrVkGLSLSampler& sampler = fSamplers[i]; - SkASSERT(sampler.type() == kTexture2DSampler_GrSLType); - if (visibility == sampler.visibility()) { - sampler.fShaderVar.appendDecl(fProgramBuilder->glslCaps(), out); + const UniformInfo& sampler = fSamplers[i]; + SkASSERT(sampler.fVariable.getType() == kTexture2DSampler_GrSLType); + if (visibility == sampler.fVisibility) { + sampler.fVariable.appendDecl(fProgramBuilder->glslCaps(), out); out->append(";\n"); } } diff --git a/src/gpu/vk/GrVkUniformHandler.h b/src/gpu/vk/GrVkUniformHandler.h index a6ea936737..89dc410c1f 100644 --- a/src/gpu/vk/GrVkUniformHandler.h +++ b/src/gpu/vk/GrVkUniformHandler.h @@ -11,7 +11,6 @@ #include "glsl/GrGLSLUniformHandler.h" #include "GrAllocator.h" -#include "GrVkGLSLSampler.h" #include "glsl/GrGLSLShaderVar.h" class GrVkUniformHandler : public GrGLSLUniformHandler { @@ -47,6 +46,7 @@ private: explicit GrVkUniformHandler(GrGLSLProgramBuilder* program) : INHERITED(program) , fUniforms(kUniformsPerBlock) + , fSamplers(kUniformsPerBlock) , fCurrentVertexUBOOffset(0) , fCurrentFragmentUBOOffset(0) , fCurrentSamplerBinding(0) { @@ -60,15 +60,21 @@ private: int arrayCount, const char** outName) override; - SamplerHandle internalAddSampler(uint32_t visibility, - GrPixelConfig config, - GrSLType type, - GrSLPrecision precision, - const char* name) override; + SamplerHandle addSampler(uint32_t visibility, + GrSwizzle swizzle, + GrSLType type, + GrSLPrecision precision, + const char* name) override; - int numSamplers() const override { return fSamplers.count(); } - const GrGLSLSampler& getSampler(SamplerHandle handle) const override { - return fSamplers[handle.toIndex()]; + int numSamplers() const { return fSamplers.count(); } + const GrGLSLShaderVar& samplerVariable(SamplerHandle handle) const override { + return fSamplers[handle.toIndex()].fVariable; + } + GrSwizzle samplerSwizzle(SamplerHandle handle) const override { + return fSamplerSwizzles[handle.toIndex()]; + } + uint32_t samplerVisibility(SamplerHandle handle) const { + return fSamplers[handle.toIndex()].fVisibility; } void appendUniformDecls(GrShaderFlags, SkString*) const override; @@ -82,12 +88,13 @@ private: } - UniformInfoArray fUniforms; - SkTArray<GrVkGLSLSampler> fSamplers; + UniformInfoArray fUniforms; + UniformInfoArray fSamplers; + SkTArray<GrSwizzle> fSamplerSwizzles; - uint32_t fCurrentVertexUBOOffset; - uint32_t fCurrentFragmentUBOOffset; - uint32_t fCurrentSamplerBinding; + uint32_t fCurrentVertexUBOOffset; + uint32_t fCurrentFragmentUBOOffset; + uint32_t fCurrentSamplerBinding; friend class GrVkPipelineStateBuilder; friend class GrVkDescriptorSetManager; |