From 9b620aa0c12d12dd7ec7ced43ce9e58f275d47c1 Mon Sep 17 00:00:00 2001 From: Chow Date: Wed, 11 Mar 2020 17:59:25 +0800 Subject: [PATCH] Add flag to check whether offset is implicit or explicit (#2031) When we use unsized array in shader storage buffer, glslang calculate the offset during delcaring the block, it may lead to incorrect block offsets when its implicit array size changed. So here is what we do: 1. For GLSL, we add flag explicitOffset in TQualifier, and set it when layout offset is specified explicitly 2. By using this flag we could tell difference as whether it is an explicit offset, and recalculate the block member offset conditionally in OpenGL. --- glslang/Include/Types.h | 1 + glslang/MachineIndependent/ParseHelper.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/glslang/Include/Types.h b/glslang/Include/Types.h index 3572099..db4f0b1 100644 --- a/glslang/Include/Types.h +++ b/glslang/Include/Types.h @@ -553,6 +553,7 @@ public: // having a constant_id is not sufficient: expressions have no id, but are still specConstant bool specConstant : 1; bool nonUniform : 1; + bool explicitOffset : 1; #ifdef GLSLANG_WEB bool isWriteOnly() const { return false; } diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index d8bb3cf..d9a4d4a 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -5141,6 +5141,7 @@ void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publi profileRequires(loc, EEsProfile, 310, nullptr, feature); } publicType.qualifier.layoutOffset = value; + publicType.qualifier.explicitOffset = true; if (nonLiteral) error(loc, "needs a literal integer", "offset", ""); return; -- 2.7.4