Merge pull request #2139 from EpicGames/fixes_glsl

GLSL: Use actual field offset to validate vec4 boundary alignment.
This commit is contained in:
Hans-Kristian Arntzen 2023-04-27 17:03:47 +02:00 committed by GitHub
commit da12e7ade7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1786,16 +1786,17 @@ bool CompilerGLSL::buffer_is_packing_standard(const SPIRType &type, BufferPackin
packed_size = type_to_packed_size(memb_type, member_flags, packing); packed_size = type_to_packed_size(memb_type, member_flags, packing);
// We only need to care about this if we have non-array types which can straddle the vec4 boundary. // We only need to care about this if we have non-array types which can straddle the vec4 boundary.
uint32_t actual_offset = type_struct_member_offset(type, i);
if (packing_is_hlsl(packing)) if (packing_is_hlsl(packing))
{ {
// If a member straddles across a vec4 boundary, alignment is actually vec4. // If a member straddles across a vec4 boundary, alignment is actually vec4.
uint32_t begin_word = offset / 16; uint32_t begin_word = actual_offset / 16;
uint32_t end_word = (offset + packed_size - 1) / 16; uint32_t end_word = (actual_offset + packed_size - 1) / 16;
if (begin_word != end_word) if (begin_word != end_word)
packed_alignment = max<uint32_t>(packed_alignment, 16u); packed_alignment = max<uint32_t>(packed_alignment, 16u);
} }
uint32_t actual_offset = type_struct_member_offset(type, i);
// Field is not in the specified range anymore and we can ignore any further fields. // Field is not in the specified range anymore and we can ignore any further fields.
if (actual_offset >= end_offset) if (actual_offset >= end_offset)
break; break;