diff options
-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)); |