aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/vk/GrVkUniformHandler.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/vk/GrVkUniformHandler.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/vk/GrVkUniformHandler.cpp')
-rw-r--r--src/gpu/vk/GrVkUniformHandler.cpp72
1 files changed, 39 insertions, 33 deletions
diff --git a/src/gpu/vk/GrVkUniformHandler.cpp b/src/gpu/vk/GrVkUniformHandler.cpp
index 4ffbcfe7d8..3451d6b344 100644
--- a/src/gpu/vk/GrVkUniformHandler.cpp
+++ b/src/gpu/vk/GrVkUniformHandler.cpp
@@ -136,6 +136,7 @@ GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray(
SkASSERT(0 == (~kVisibilityMask & visibility));
SkASSERT(0 != visibility);
SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
+ GrSLTypeIsFloatType(type);
UniformInfo& uni = fUniforms.push_back();
uni.fVariable.setType(type);
@@ -155,58 +156,63 @@ GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray(
SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == visibility);
uni.fVisibility = visibility;
uni.fVariable.setPrecision(precision);
- if (GrSLTypeIsFloatType(type)) {
- // When outputing the GLSL, only the outer uniform block will get the Uniform modifier. Thus
- // we set the modifier to none for all uniforms declared inside the block.
- uni.fVariable.setTypeModifier(GrGLSLShaderVar::kNone_TypeModifier);
+ // When outputing the GLSL, only the outer uniform block will get the Uniform modifier. Thus
+ // we set the modifier to none for all uniforms declared inside the block.
+ uni.fVariable.setTypeModifier(GrGLSLShaderVar::kNone_TypeModifier);
- uint32_t* currentOffset = kVertex_GrShaderFlag == visibility ? &fCurrentVertexUBOOffset
- : &fCurrentFragmentUBOOffset;
- get_ubo_aligned_offset(&uni.fUBOffset, currentOffset, type, arrayCount);
- uni.fSetNumber = kUniformBufferDescSet;
- uni.fBinding = kVertex_GrShaderFlag == visibility ? kVertexBinding : kFragBinding;
+ uint32_t* currentOffset = kVertex_GrShaderFlag == visibility ? &fCurrentVertexUBOOffset
+ : &fCurrentFragmentUBOOffset;
+ get_ubo_aligned_offset(&uni.fUBOffset, currentOffset, type, arrayCount);
- if (outName) {
- *outName = uni.fVariable.c_str();
- }
- } else {
- SkASSERT(type == kSampler2D_GrSLType);
- uni.fVariable.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier);
-
- uni.fSetNumber = kSamplerDescSet;
- uni.fBinding = fCurrentSamplerBinding++;
- uni.fUBOffset = 0; // This value will be ignored, but initializing to avoid any errors.
- SkString layoutQualifier;
- layoutQualifier.appendf("set=%d, binding=%d", uni.fSetNumber, uni.fBinding);
- uni.fVariable.setLayoutQualifier(layoutQualifier.c_str());
+ if (outName) {
+ *outName = uni.fVariable.c_str();
}
return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
}
+GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::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(),
+ (uint32_t)fSamplers.count(), kSamplerDescSet);
+ return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
+}
+
void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
- SkTArray<UniformInfo*> uniformBufferUniform;
- // Used to collect all the variables that will be place inside the uniform buffer
- SkString uniformsString;
SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == visibility);
- uint32_t uniformBinding = (visibility == kVertex_GrShaderFlag) ? kVertexBinding : kFragBinding;
+
+ for (int i = 0; i < fSamplers.count(); ++i) {
+ const GrVkGLSLSampler& sampler = fSamplers[i];
+ SkASSERT(sampler.type() == kSampler2D_GrSLType);
+ if (visibility == sampler.visibility()) {
+ sampler.fShaderVar.appendDecl(fProgramBuilder->glslCaps(), out);
+ out->append(";\n");
+ }
+ }
+
+ SkString uniformsString;
for (int i = 0; i < fUniforms.count(); ++i) {
const UniformInfo& localUniform = fUniforms[i];
if (visibility == localUniform.fVisibility) {
if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) {
- SkASSERT(uniformBinding == localUniform.fBinding);
- SkASSERT(kUniformBufferDescSet == localUniform.fSetNumber);
localUniform.fVariable.appendDecl(fProgramBuilder->glslCaps(), &uniformsString);
uniformsString.append(";\n");
- } else {
- SkASSERT(localUniform.fVariable.getType() == kSampler2D_GrSLType);
- SkASSERT(kSamplerDescSet == localUniform.fSetNumber);
- localUniform.fVariable.appendDecl(fProgramBuilder->glslCaps(), out);
- out->append(";\n");
}
}
}
if (!uniformsString.isEmpty()) {
+ uint32_t uniformBinding = (visibility == kVertex_GrShaderFlag) ? kVertexBinding
+ : kFragBinding;
const char* stage = (visibility == kVertex_GrShaderFlag) ? "vertex" : "fragment";
out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n",
kUniformBufferDescSet, uniformBinding, stage);