diff options
author | Greg Daniel <egdaniel@google.com> | 2017-01-24 15:12:12 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-27 16:55:35 +0000 |
commit | dbd44c78ec98adc07569d430f3b27e0834186a7e (patch) | |
tree | d10e303f70260b3eee8478dfccff2a91a1cd93fe | |
parent | 587e08f361ee3e775a6bbc6dca761dbba82e422c (diff) |
Add offset to uniform blocks in Vulkan
This is the first step to being able to use push constants.
BUG=skia:5039
Change-Id: I49edea8faacf78814036ce3b3f9f2814974cf2c7
Reviewed-on: https://skia-review.googlesource.com/7448
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
-rw-r--r-- | src/gpu/vk/GrVkUniformHandler.cpp | 13 | ||||
-rw-r--r-- | src/sksl/SkSLSPIRVCodeGenerator.cpp | 2 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/gpu/vk/GrVkUniformHandler.cpp b/src/gpu/vk/GrVkUniformHandler.cpp index c64864b55a..f0f0fff7a6 100644 --- a/src/gpu/vk/GrVkUniformHandler.cpp +++ b/src/gpu/vk/GrVkUniformHandler.cpp @@ -165,6 +165,10 @@ GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray( : &fCurrentFragmentUBOOffset; get_ubo_aligned_offset(&uni.fUBOffset, currentOffset, type, arrayCount); + SkString layoutQualifier; + layoutQualifier.appendf("offset=%d", uni.fUBOffset); + uni.fVariable.addLayoutQualifier(layoutQualifier.c_str()); + if (outName) { *outName = uni.fVariable.c_str(); } @@ -213,11 +217,20 @@ void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* } } + SkDEBUGCODE(bool firstOffsetCheck = false); SkString uniformsString; for (int i = 0; i < fUniforms.count(); ++i) { const UniformInfo& localUniform = fUniforms[i]; if (visibility == localUniform.fVisibility) { if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) { +#ifdef SK_DEBUG + if (!firstOffsetCheck) { + // Check to make sure we are starting our offset at 0 so the offset qualifier we + // set on each variable in the uniform block is valid. + SkASSERT(0 == localUniform.fUBOffset); + firstOffsetCheck = true; + } +#endif localUniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString); uniformsString.append(";\n"); } diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp index d43e4c4035..9c8a5d0001 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp @@ -993,7 +993,7 @@ void SPIRVCodeGenerator::writeStruct(const Type& type, const MemoryLayout& memor size_t alignment = memoryLayout.alignment(*type.fields()[i].fType); const Layout& fieldLayout = type.fields()[i].fModifiers.fLayout; if (fieldLayout.fOffset >= 0) { - if (fieldLayout.fOffset <= (int) offset) { + if (fieldLayout.fOffset < (int) offset) { fErrors.error(type.fPosition, "offset of field '" + type.fields()[i].fName + "' must be at " "least " + to_string((int) offset)); |