summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Hollings <bill.hollings@brenwill.com>2023-07-14 18:57:34 -0400
committerBill Hollings <bill.hollings@brenwill.com>2023-07-14 18:57:34 -0400
commit05524e7f829c18f77dae5064642c5d38bc46a211 (patch)
tree51d5e8c53ccbbb95e7cbe45913250f6c006568ce
parentb43c1a1e63ca7ac967c3b0e71ba29dbe08aa3dc0 (diff)
downloadSPIRV-Cross-05524e7f829c18f77dae5064642c5d38bc46a211.tar.gz
SPIRV-Cross-05524e7f829c18f77dae5064642c5d38bc46a211.tar.bz2
SPIRV-Cross-05524e7f829c18f77dae5064642c5d38bc46a211.zip
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.
-rw-r--r--spirv_msl.cpp14
1 files 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.