From 05524e7f829c18f77dae5064642c5d38bc46a211 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Fri, 14 Jul 2023 18:57:34 -0400 Subject: [PATCH] Fix argument buffer padding when content includes arrays. - When determining need for arg buffer padding, use the descriptor count provided by the app, rather than the shader, to determine the number of slots consumed, as the shader may only be accessing part, or even one element, of the array. --- spirv_msl.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/spirv_msl.cpp b/spirv_msl.cpp index a54fb95f..4ca4a04d 100644 --- a/spirv_msl.cpp +++ b/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.