From 4ecdb24e597b43708d86087d697bbf9fbc7f4627 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Mon, 3 Oct 2022 12:29:20 +0200 Subject: MSL: Expose way to query if a buffer needs array length. --- spirv_msl.cpp | 10 +++++----- spirv_msl.hpp | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/spirv_msl.cpp b/spirv_msl.cpp index f870444e..b974b669 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -856,7 +856,7 @@ void CompilerMSL::build_implicit_builtins() swizzle_buffer_id = var_id; } - if (!buffers_requiring_array_length.empty()) + if (needs_buffer_size_buffer()) { uint32_t var_id = build_constant_uint_array_pointer(); set_name(var_id, "spvBufferSizeConstants"); @@ -10021,7 +10021,7 @@ void CompilerMSL::emit_function_prototype(SPIRFunction &func, const Bitset &) decl += join(", constant uint", arg_is_array ? "* " : "& ", to_swizzle_expression(arg.id)); } - if (buffers_requiring_array_length.count(name_id)) + if (buffer_requires_array_length(name_id)) { bool arg_is_array = !arg_type.array.empty(); decl += join(", constant uint", arg_is_array ? "* " : "& ", to_buffer_size_expression(name_id)); @@ -11058,7 +11058,7 @@ string CompilerMSL::to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_ else if (msl_options.swizzle_texture_samples && has_sampled_images && is_sampled_image_type(type)) arg_str += ", " + to_swizzle_expression(var_id ? var_id : id); - if (buffers_requiring_array_length.count(var_id)) + if (buffer_requires_array_length(var_id)) arg_str += ", " + to_buffer_size_expression(var_id ? var_id : id); if (is_dynamic_img_sampler) @@ -12767,7 +12767,7 @@ void CompilerMSL::fix_up_shader_inputs_outputs() else if ((var.storage == StorageClassStorageBuffer || (var.storage == StorageClassUniform && ssbo)) && !is_hidden_variable(var)) { - if (buffers_requiring_array_length.count(var.self)) + if (buffer_requires_array_length(var.self)) { entry_func.fixup_hooks_in.push_back([this, &type, &var, var_id]() { bool is_array_type = !type.array.empty(); @@ -16710,7 +16710,7 @@ void CompilerMSL::analyze_argument_buffers() // Check if this descriptor set needs a swizzle buffer. if (needs_swizzle_buffer_def && is_sampled_image_type(type)) set_needs_swizzle_buffer[desc_set] = true; - else if (buffers_requiring_array_length.count(var_id) != 0) + else if (buffer_requires_array_length(var_id)) { set_needs_buffer_sizes[desc_set] = true; needs_buffer_sizes = true; diff --git a/spirv_msl.hpp b/spirv_msl.hpp index 1a7ee5c0..a848f9b5 100644 --- a/spirv_msl.hpp +++ b/spirv_msl.hpp @@ -504,6 +504,11 @@ public: return !buffers_requiring_array_length.empty(); } + bool buffer_requires_array_length(VariableID id) const + { + return buffers_requiring_array_length.count(id) != 0; + } + // Provide feedback to calling API to allow it to pass a buffer // containing the view mask for the current multiview subpass. bool needs_view_mask_buffer() const -- cgit v1.2.3