diff --git a/main.cpp b/main.cpp index 56175cab4..d8aff1523 100644 --- a/main.cpp +++ b/main.cpp @@ -865,7 +865,8 @@ static void print_help_msl() "\t\tRequires MSL 2.0 to be enabled.\n" "\t[--msl-argument-buffer-tier]:\n\t\tWhen using Metal argument buffers, indicate the Metal argument buffer tier level supported by the Metal platform.\n" "\t\tUses same values as Metal MTLArgumentBuffersTier enumeration (0 = Tier1, 1 = Tier2).\n" - "\t\tSetting this value also enables msl-argument-buffers.\n" + "\t\tNOTE: Setting this value no longer enables msl-argument-buffers implicitly.\n" + "\t[--msl-runtime-array-rich-descriptor]:\n\t\tWhen declaring a runtime array of SSBOs, declare an array of {ptr, len} pairs to support OpArrayLength.\n" "\t[--msl-texture-buffer-native]:\n\t\tEnable native support for texel buffers. Otherwise, it is emulated as a normal texture.\n" "\t[--msl-framebuffer-fetch]:\n\t\tImplement subpass inputs with frame buffer fetch.\n" "\t\tEmits [[color(N)]] inputs in fragment stage.\n" @@ -1789,7 +1790,7 @@ static int main_inner(int argc, char *argv[]) cbs.add("--msl-combined-sampler-suffix", [&args](CLIParser &parser) { args.msl_combined_sampler_suffix = parser.next_string(); }); - cbs.add("--msl-runtime-array-rich-decriptor", + cbs.add("--msl-runtime-array-rich-descriptor", [&args](CLIParser &) { args.msl_runtime_array_rich_descriptor = true; }); cbs.add("--extension", [&args](CLIParser &parser) { args.extensions.push_back(parser.next_string()); }); cbs.add("--rename-entry-point", [&args](CLIParser &parser) { diff --git a/spirv_cross.cpp b/spirv_cross.cpp index 10ac1af26..02565c955 100644 --- a/spirv_cross.cpp +++ b/spirv_cross.cpp @@ -635,9 +635,7 @@ bool Compiler::is_runtime_size_array(const SPIRType &type) if (type.array.empty()) return false; assert(type.array.size() == type.array_size_literal.size()); - if (type.array_size_literal[type.array.size() - 1]) - return type.array[type.array.size() - 1] == 0; - return false; + return type.array_size_literal.back() && type.array.back() == 0; } ShaderResources Compiler::get_shader_resources() const diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 520ddfd9c..b95b3827e 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -11674,7 +11674,10 @@ string CompilerMSL::to_buffer_size_expression(uint32_t id) { if (!msl_options.runtime_array_rich_descriptor) SPIRV_CROSS_THROW("OpArrayLength requires rich descriptor format"); - return buffer_expr + ".length(" + array_expr.substr(1, array_expr.size() - 2) + ")"; + + auto last_pos = array_expr.find_last_of(']'); + if (last_pos != std::string::npos) + return buffer_expr + ".length(" + array_expr.substr(1, last_pos - 1) + ")"; } } return buffer_expr + buffer_size_name_suffix + array_expr; @@ -13258,13 +13261,9 @@ void CompilerMSL::entry_point_args_discrete_descriptors(string &ep_args) ep_args += ", "; ep_args += sampler_type(type, var_id) + " " + r.name; if (is_runtime_size_array(type)) - { ep_args += "_ [[buffer(" + convert_to_string(r.index) + ")]]"; - } else - { ep_args += " [[sampler(" + convert_to_string(r.index) + ")]]"; - } break; case SPIRType::Image: { @@ -13280,13 +13279,9 @@ void CompilerMSL::entry_point_args_discrete_descriptors(string &ep_args) ep_args += join(plane_name_suffix, r.plane); if (is_runtime_size_array(type)) - { ep_args += "_ [[buffer(" + convert_to_string(r.index) + ")"; - } else - { ep_args += " [[texture(" + convert_to_string(r.index) + ")"; - } if (interlocked_resources.count(var_id)) ep_args += ", raster_order_group(0)"; diff --git a/test_shaders.py b/test_shaders.py index ab44c5006..887cb5b73 100755 --- a/test_shaders.py +++ b/test_shaders.py @@ -358,7 +358,7 @@ def cross_compile_msl(shader, spirv, opt, iterations, paths): if '.decoration-binding.' in shader: msl_args.append('--msl-decoration-binding') if '.rich-descriptor.' in shader: - msl_args.append('--msl-runtime-array-rich-decriptor') + msl_args.append('--msl-runtime-array-rich-descriptor') if '.mask-location-0.' in shader: msl_args.append('--mask-stage-output-location') msl_args.append('0')