aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLUniformHandler.cpp
diff options
context:
space:
mode:
authorGravatar egdaniel <egdaniel@google.com>2016-04-19 14:45:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-19 14:45:57 -0700
commit45b61a1c4c0be896e7b12fd1405abfece799114f (patch)
treed39781d14238a55da739d0174854cbfedb8b76f1 /src/gpu/gl/GrGLUniformHandler.cpp
parent4c13db2a6bb4c795bec6b050b6ebd2ff5177bb5e (diff)
Refactor how we store and use samplers in Ganesh
The main goal of this refactorization is to allow Vulkan to use separate sampler and texture objects in the shader and descriptor sets and combine them into a sampler2d in the shader where needed. A large part of this is separating how we store samplers and uniforms in the UniformHandler. We no longer need to store handles to samplers besides when we are initially emitting code. After we emit code all we ever do is loop over all samplers and do some processor independent work on them, so we have no need for direct access to individual samplers. In the GLProgram all we ever do is set the sampler uniforms in the ctor and never touch them again, so no need to save sampler info there. The texture access on program reuse just assume that they come in the same order as we set the texture units for the samplers For Vulkan, it is a similar story. We create the descriptor set layouts with the samplers, then when we get new textures, we just assume they come in in the same order as we set the samplers on the descriptor sets. Thus no need to save direct vulkan info. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1885863004 Review URL: https://codereview.chromium.org/1885863004
Diffstat (limited to 'src/gpu/gl/GrGLUniformHandler.cpp')
-rw-r--r--src/gpu/gl/GrGLUniformHandler.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/gpu/gl/GrGLUniformHandler.cpp b/src/gpu/gl/GrGLUniformHandler.cpp
index 94da1f1776..c4189267f1 100644
--- a/src/gpu/gl/GrGLUniformHandler.cpp
+++ b/src/gpu/gl/GrGLUniformHandler.cpp
@@ -52,6 +52,22 @@ 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) {
+ 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());
+ return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
+}
+
void GrGLUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
for (int i = 0; i < fUniforms.count(); ++i) {
if (fUniforms[i].fVisibility & visibility) {
@@ -59,6 +75,12 @@ void GrGLUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
out->append(";\n");
}
}
+ for (int i = 0; i < fSamplers.count(); ++i) {
+ if (fSamplers[i].visibility() & visibility) {
+ fSamplers[i].fShaderVar.appendDecl(fProgramBuilder->glslCaps(), out);
+ out->append(";\n");
+ }
+ }
}
void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps& caps) {
@@ -68,6 +90,10 @@ void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps
GL_CALL(BindUniformLocation(programID, i, fUniforms[i].fVariable.c_str()));
fUniforms[i].fLocation = i;
}
+ for (int i = 0; i < fSamplers.count(); ++i) {
+ GL_CALL(BindUniformLocation(programID, i, fSamplers[i].fShaderVar.c_str()));
+ fSamplers[i].fLocation = i;
+ }
}
}
@@ -79,6 +105,11 @@ void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps&
GL_CALL_RET(location, GetUniformLocation(programID, fUniforms[i].fVariable.c_str()));
fUniforms[i].fLocation = location;
}
+ for (int i = 0; i < fSamplers.count(); ++i) {
+ GrGLint location;
+ GL_CALL_RET(location, GetUniformLocation(programID, fSamplers[i].fShaderVar.c_str()));
+ fSamplers[i].fLocation = location;
+ }
}
}