Skip to content

Commit

Permalink
MSL: Fixup nits from review.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKristian-Work committed Aug 17, 2023
1 parent 844cb59 commit 44966e5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
5 changes: 3 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions spirv_cross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 4 additions & 9 deletions spirv_msl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
{
Expand All @@ -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)";
Expand Down
2 changes: 1 addition & 1 deletion test_shaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 44966e5

Please sign in to comment.