From 46e757b2785ea2ed2d0b952537e28dfeeac1f41c Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 23 Jul 2019 11:53:33 +0200 Subject: [PATCH] GLSL/HLSL: Verify member alignment for explicit offset as well. --- spirv_glsl.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index abc02d44..72718ee8 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -1340,14 +1340,20 @@ bool CompilerGLSL::buffer_is_packing_standard(const SPIRType &type, BufferPackin // Only care about packing if we are in the given range if (offset >= start_offset) { + uint32_t actual_offset = type_struct_member_offset(type, i); + // We only care about offsets in std140, std430, etc ... // For EnhancedLayout variants, we have the flexibility to choose our own offsets. if (!packing_has_flexible_offset(packing)) { - uint32_t actual_offset = type_struct_member_offset(type, i); if (actual_offset != offset) // This cannot be the packing we're looking for. return false; } + else if ((actual_offset & (alignment - 1)) != 0) + { + // We still need to verify that alignment rules are observed, even if we have explicit offset. + return false; + } // Verify array stride rules. if (!memb_type.array.empty() && type_to_packed_array_stride(memb_type, member_flags, packing) !=