mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 13:48:06 +02:00
radv: use nir_intrinsic_printf in radv_build_printf()
This avoids passing radv_debug_nir everywhere. This also requires to lower printf slightly later for meta shaders. Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40517>
This commit is contained in:
parent
276c8b721b
commit
1dc6cee956
4 changed files with 64 additions and 23 deletions
|
|
@ -30,7 +30,7 @@ pass(nir_builder *b, nir_intrinsic_instr *instr, void *state)
|
|||
for (uint32_t i = 0; i < info->num_args; i++)
|
||||
args[i] = nir_load_deref(b, nir_build_deref_struct(b, packed_args, i));
|
||||
|
||||
radv_build_printf_args(debug_nir, b, NULL, info->strings, info->num_args, args);
|
||||
radv_build_printf_args(debug_nir, b, info->strings, info->num_args, args);
|
||||
|
||||
nir_instr_remove(&instr->instr);
|
||||
|
||||
|
|
|
|||
|
|
@ -95,8 +95,8 @@ radv_printf_data_finish(struct radv_device *device)
|
|||
}
|
||||
|
||||
void
|
||||
radv_build_printf_args(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def *cond, const char *format_string,
|
||||
uint32_t argc, nir_def **in_args)
|
||||
radv_build_printf_args(struct radv_debug_nir *debug_nir, nir_builder *b, const char *format_string, uint32_t argc,
|
||||
nir_def **in_args)
|
||||
{
|
||||
struct radv_printf_data *printf = &debug_nir->printf;
|
||||
|
||||
|
|
@ -110,9 +110,6 @@ radv_build_printf_args(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def
|
|||
|
||||
uint32_t format_index = util_dynarray_num_elements(&printf->formats, struct radv_printf_format);
|
||||
|
||||
if (cond)
|
||||
nir_push_if(b, cond);
|
||||
|
||||
if (b->shader->info.stage == MESA_SHADER_FRAGMENT)
|
||||
nir_push_if(b, nir_inot(b, nir_is_helper_invocation(b, 1)));
|
||||
|
||||
|
|
@ -190,9 +187,6 @@ radv_build_printf_args(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def
|
|||
}
|
||||
nir_pop_if(b, NULL);
|
||||
|
||||
if (cond)
|
||||
nir_pop_if(b, NULL);
|
||||
|
||||
if (b->shader->info.stage == MESA_SHADER_FRAGMENT)
|
||||
nir_pop_if(b, NULL);
|
||||
|
||||
|
|
@ -203,13 +197,8 @@ radv_build_printf_args(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def
|
|||
}
|
||||
|
||||
void
|
||||
radv_build_printf(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def *cond, const char *format_string, ...)
|
||||
radv_build_printf(nir_builder *b, nir_def *cond, const char *format_string, ...)
|
||||
{
|
||||
struct radv_printf_data *printf = &debug_nir->printf;
|
||||
|
||||
if (!printf->buffer_addr)
|
||||
return;
|
||||
|
||||
va_list arg_list;
|
||||
va_start(arg_list, format_string);
|
||||
|
||||
|
|
@ -225,8 +214,60 @@ radv_build_printf(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def *con
|
|||
|
||||
va_end(arg_list);
|
||||
|
||||
radv_build_printf_args(debug_nir, b, cond, format_string, num_args, args);
|
||||
b->shader->info.uses_printf = true;
|
||||
b->shader->printf_info_count++;
|
||||
b->shader->printf_info = reralloc(b->shader, b->shader->printf_info, u_printf_info, b->shader->printf_info_count);
|
||||
|
||||
u_printf_info *info = &b->shader->printf_info[b->shader->printf_info_count - 1];
|
||||
|
||||
*info = (u_printf_info){
|
||||
.arg_sizes = ralloc_array(b->shader, unsigned, num_args),
|
||||
.num_args = num_args,
|
||||
.strings = ralloc_strdup(b->shader, format_string),
|
||||
.string_size = strlen(format_string) + 1,
|
||||
};
|
||||
|
||||
uint32_t info_index = b->shader->printf_info_count;
|
||||
|
||||
glsl_struct_field *fields = NULL;
|
||||
nir_def *printf_src;
|
||||
|
||||
if (num_args) {
|
||||
fields = calloc(num_args, sizeof(glsl_struct_field));
|
||||
|
||||
for (uint32_t i = 0; i < num_args; i++) {
|
||||
nir_def *arg = args[i];
|
||||
|
||||
fields[i].type = glsl_intN_t_type(arg->bit_size);
|
||||
fields[i].name = "";
|
||||
|
||||
info->arg_sizes[i] = arg->bit_size / 8;
|
||||
}
|
||||
|
||||
nir_variable *packed_args =
|
||||
nir_local_variable_create(b->impl, glsl_struct_type(fields, num_args, "packed_args", false), "packed_args");
|
||||
nir_deref_instr *var_deref = nir_build_deref_var(b, packed_args);
|
||||
|
||||
for (uint32_t i = 0; i < num_args; i++) {
|
||||
nir_def *arg = args[i];
|
||||
nir_deref_instr *arg_deref = nir_build_deref_struct(b, var_deref, i);
|
||||
nir_store_deref(b, arg_deref, arg, BITFIELD_MASK(NIR_MAX_VEC_COMPONENTS));
|
||||
}
|
||||
|
||||
printf_src = &var_deref->def;
|
||||
} else {
|
||||
printf_src = nir_undef(b, 1, 32);
|
||||
}
|
||||
|
||||
if (cond)
|
||||
nir_push_if(b, cond);
|
||||
|
||||
nir_printf(b, printf_src, .fmt_idx = info_index);
|
||||
|
||||
if (cond)
|
||||
nir_pop_if(b, NULL);
|
||||
|
||||
free(fields);
|
||||
free(args);
|
||||
}
|
||||
|
||||
|
|
@ -474,7 +515,7 @@ radv_build_is_valid_va(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def
|
|||
nir_pop_if(b, NULL);
|
||||
nir_def *valid = nir_if_phi(b, then_valid, else_valid);
|
||||
|
||||
radv_build_printf(debug_nir, b, nir_inot(b, valid), "radv: Invalid VA %lx\n", addr);
|
||||
radv_build_printf(b, nir_inot(b, valid), "radv: Invalid VA %lx\n", addr);
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,10 +63,10 @@ VkResult radv_printf_data_init(struct radv_device *device);
|
|||
|
||||
void radv_printf_data_finish(struct radv_device *device);
|
||||
|
||||
void radv_build_printf_args(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def *cond, const char *format,
|
||||
uint32_t argc, nir_def **args);
|
||||
void radv_build_printf_args(struct radv_debug_nir *debug_nir, nir_builder *b, const char *format, uint32_t argc,
|
||||
nir_def **args);
|
||||
|
||||
void radv_build_printf(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def *cond, const char *format, ...);
|
||||
void radv_build_printf(nir_builder *b, nir_def *cond, const char *format, ...);
|
||||
|
||||
void radv_dump_printf_data(struct radv_device *device, FILE *out);
|
||||
|
||||
|
|
|
|||
|
|
@ -521,9 +521,6 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_shader_st
|
|||
|
||||
free(spec_entries);
|
||||
|
||||
if (device->debug_nir.printf.buffer_addr)
|
||||
NIR_PASS(_, nir, radv_nir_lower_printf, &device->debug_nir);
|
||||
|
||||
const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
|
||||
.point_coord = true,
|
||||
};
|
||||
|
|
@ -631,6 +628,9 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_shader_st
|
|||
NIR_PASS(_, nir, ac_nir_lower_sin_cos);
|
||||
}
|
||||
|
||||
if (device->debug_nir.printf.buffer_addr)
|
||||
NIR_PASS(_, nir, radv_nir_lower_printf, &device->debug_nir);
|
||||
|
||||
if (options && options->lower_view_index_to_device_index)
|
||||
NIR_PASS(_, nir, nir_lower_view_index_to_device_index);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue