MSL: Remove workaround for passing constant arrays to functions.

Arrays are value-types now, so remove the old workaround.
This commit is contained in:
Hans-Kristian Arntzen 2019-10-28 12:14:43 +01:00
parent 32bd1329b6
commit 8f13a3f4b1
4 changed files with 2 additions and 38 deletions

View File

@ -75,14 +75,13 @@ float4 consume_constant_arrays(spvUnsafeArray<float4, 4> positions, spvUnsafeArr
vertex main0_out main0(main0_in in [[stage_in]])
{
spvUnsafeArray<float4, 4> _68_array_copy = spvUnsafeArray<float4, 4>({ float4(0.0), float4(1.0), float4(2.0), float4(3.0) });
main0_out out = {};
spvUnsafeArray<float4, 4> LUT2;
LUT2[0] = float4(10.0);
LUT2[1] = float4(11.0);
LUT2[2] = float4(12.0);
LUT2[3] = float4(13.0);
out.gl_Position = consume_constant_arrays(_68_array_copy, LUT2, in.Index1, in.Index2);
out.gl_Position = consume_constant_arrays(_68, LUT2, in.Index1, in.Index2);
return out;
}

View File

@ -938,11 +938,6 @@ struct SPIRFunction : IVariant
// Intentionally not a small vector, this one is rare, and std::function can be large.
Vector<std::function<void()>> fixup_hooks_in;
// On function entry, make sure to copy a constant array into thread addr space to work around
// the case where we are passing a constant array by value to a function on backends which do not
// consider arrays value types.
SmallVector<ID> constant_arrays_needed_on_stack;
bool active = false;
bool flush_undeclared = true;
bool do_combined_parameters = true;

View File

@ -11380,14 +11380,6 @@ void CompilerGLSL::emit_function(SPIRFunction &func, const Bitset &return_flags)
current_function = &func;
auto &entry_block = get<SPIRBlock>(func.entry_block);
sort(begin(func.constant_arrays_needed_on_stack), end(func.constant_arrays_needed_on_stack));
for (auto &array : func.constant_arrays_needed_on_stack)
{
auto &c = get<SPIRConstant>(array);
auto &type = get<SPIRType>(c.constant_type);
statement(variable_decl(type, join("_", array, "_array_copy")), " = ", constant_expression(c), ";");
}
for (auto &v : func.local_variables)
{
auto &var = get<SPIRVariable>(v);

View File

@ -7966,29 +7966,7 @@ string CompilerMSL::to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_
if (is_dynamic_img_sampler && !arg_is_dynamic_img_sampler)
arg_str = join("spvDynamicImageSampler<", type_to_glsl(get<SPIRType>(type.image.type)), ">(");
auto *c = maybe_get<SPIRConstant>(id);
if (c && !get<SPIRType>(c->constant_type).array.empty())
{
// If we are passing a constant array directly to a function for some reason,
// the callee will expect an argument in thread const address space
// (since we can only bind to arrays with references in MSL).
// To resolve this, we must emit a copy in this address space.
// This kind of code gen should be rare enough that performance is not a real concern.
// Inline the SPIR-V to avoid this kind of suboptimal codegen.
//
// We risk calling this inside a continue block (invalid code),
// so just create a thread local copy in the current function.
arg_str = join("_", id, "_array_copy");
auto &constants = current_function->constant_arrays_needed_on_stack;
auto itr = find(begin(constants), end(constants), ID(id));
if (itr == end(constants))
{
force_recompile();
constants.push_back(id);
}
}
else
arg_str += CompilerGLSL::to_func_call_arg(arg, id);
arg_str += CompilerGLSL::to_func_call_arg(arg, id);
// Need to check the base variable in case we need to apply a qualified alias.
uint32_t var_id = 0;