diff --git a/3rdparty/spirv-cross/spirv_msl.cpp b/3rdparty/spirv-cross/spirv_msl.cpp index 5ff72abe38..de8d530a01 100644 --- a/3rdparty/spirv-cross/spirv_msl.cpp +++ b/3rdparty/spirv-cross/spirv_msl.cpp @@ -17400,11 +17400,11 @@ void CompilerMSL::analyze_argument_buffers() // member_index and next_arg_buff_index are incremented when padding members are added. if (msl_options.pad_argument_buffer_resources) { + auto &rez_bind = get_argument_buffer_resource(desc_set, next_arg_buff_index); if (!resource.descriptor_alias) { while (resource.index > next_arg_buff_index) { - auto &rez_bind = get_argument_buffer_resource(desc_set, next_arg_buff_index); switch (rez_bind.basetype) { case SPIRType::Void: @@ -17442,12 +17442,9 @@ void CompilerMSL::analyze_argument_buffers() } // Adjust the number of slots consumed by current member itself. - // If actual member is an array, allow runtime array resolution as well. - uint32_t elem_cnt = type.array.empty() ? 1 : to_array_size_literal(type); - if (elem_cnt == 0) - elem_cnt = get_resource_array_size(var.self); - - next_arg_buff_index += elem_cnt; + // Use the count value from the app, instead of the shader, in case the + // shader is only accesing part, or even one element, of the array. + next_arg_buff_index += rez_bind.count; } string mbr_name = ensure_valid_name(resource.name, "m"); @@ -17599,8 +17596,7 @@ void CompilerMSL::add_argument_buffer_padding_buffer_type(SPIRType &struct_type, argument_buffer_padding_buffer_type_id = ptr_type_id; } - for (uint32_t rez_idx = 0; rez_idx < rez_bind.count; rez_idx++) - add_argument_buffer_padding_type(argument_buffer_padding_buffer_type_id, struct_type, mbr_idx, arg_buff_index, 1); + add_argument_buffer_padding_type(argument_buffer_padding_buffer_type_id, struct_type, mbr_idx, arg_buff_index, rez_bind.count); } // Adds an argument buffer padding argument image type as a member of the struct type at the member index.