spirv: handle function parameters passed by value

Cc: mesa-stable
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29896>
This commit is contained in:
Karol Herbst
2024-06-25 13:51:34 +02:00
committed by Marge Bot
parent 9b55dcca54
commit bad67ee77c
3 changed files with 26 additions and 25 deletions

View File

@@ -607,11 +607,6 @@ program@execute@builtin@builtin-ulong-popcount-1.2.generated@popcount ulong16,Fa
program@execute@builtin@builtin-ulong-popcount-1.2.generated@popcount ulong2,Fail
program@execute@builtin@builtin-ulong-popcount-1.2.generated@popcount ulong4,Fail
program@execute@builtin@builtin-ulong-popcount-1.2.generated@popcount ulong8,Fail
program@execute@calls-large-struct,Fail
program@execute@calls-large-struct@byval struct,Fail
program@execute@calls-struct,Fail
program@execute@calls-struct@regs struct,Fail
program@execute@calls-struct@small struct in regs,Fail
program@execute@global-offset,Fail
program@execute@global-offset@3d- input dependent,Fail
program@execute@scalar-arithmetic-long,Crash

View File

@@ -136,14 +136,37 @@ function_parameter_decoration_cb(struct vtn_builder *b, struct vtn_value *val,
static void
vtn_ssa_value_load_function_param(struct vtn_builder *b,
struct vtn_ssa_value *value,
struct vtn_type *type,
struct vtn_func_arg_info *info,
unsigned *param_idx)
{
if (glsl_type_is_vector_or_scalar(value->type)) {
value->def = nir_load_param(&b->nb, (*param_idx)++);
/* if the parameter is passed by value, we need to create a local copy if it's a pointer */
if (info->by_value && type && type->base_type == vtn_base_type_pointer) {
struct vtn_type *pointee_type = type->deref;
nir_variable *copy =
nir_local_variable_create(b->nb.impl, pointee_type->type, NULL);
nir_variable_mode mode;
vtn_storage_class_to_mode(b, type->storage_class, NULL, &mode);
nir_def *param = nir_load_param(&b->nb, (*param_idx)++);
nir_deref_instr *src = nir_build_deref_cast(&b->nb, param, mode, copy->type, 0);
nir_deref_instr *dst = nir_build_deref_var(&b->nb, copy);
nir_copy_deref(&b->nb, dst, src);
nir_deref_instr *load =
nir_build_deref_cast(&b->nb, &dst->def, nir_var_function_temp, type->type, 0);
value->def = &load->def;
} else {
value->def = nir_load_param(&b->nb, (*param_idx)++);
}
} else {
unsigned elems = glsl_get_length(value->type);
for (unsigned i = 0; i < elems; i++)
vtn_ssa_value_load_function_param(b, value->elems[i], param_idx);
vtn_ssa_value_load_function_param(b, value->elems[i], NULL, info, param_idx);
}
}
@@ -314,7 +337,7 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
struct vtn_value *val = vtn_untyped_value(b, w[2]);
vtn_foreach_decoration(b, val, function_parameter_decoration_cb, &arg_info);
vtn_ssa_value_load_function_param(b, ssa, &b->func_param_idx);
vtn_ssa_value_load_function_param(b, ssa, type, &arg_info, &b->func_param_idx);
vtn_push_ssa_value(b, w[2], ssa);
break;
}

View File

@@ -44,23 +44,6 @@ program@execute@builtin@builtin-float-nextafter-1.0.generated@nextafter float2,F
program@execute@builtin@builtin-float-nextafter-1.0.generated@nextafter float4,Fail
program@execute@builtin@builtin-float-nextafter-1.0.generated@nextafter float8,Fail
# Expecting 14 (0xe) with tolerance 0, but got 114 (0x72)
# Error at int[0]
# Argument 1: FAIL
program@execute@calls-large-struct,Fail
program@execute@calls-large-struct@byval struct,Fail
program@execute@calls-struct,Fail
# Expecting 14 (0xe) with tolerance 0, but got 114 (0x72)
# Error at int[0]
# Argument 1: FAIL
program@execute@calls-struct@regs struct,Fail
# Expecting 86 (0x56) with tolerance 0, but got 134 (0x86)
# Error at int[0]
# Argument 0: FAIL
# Argument 1: PASS
program@execute@calls-struct@small struct in regs,Fail
# Expecting 0 (0x0) with tolerance 0, but got 9 (0x9)
program@execute@global-offset,Fail
program@execute@global-offset@3d- input dependent,Fail