radv: stop associating NIR with device for debugging tools

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40481>
This commit is contained in:
Samuel Pitoiset 2026-03-18 11:33:18 +01:00 committed by Marge Bot
parent fddbeddb2d
commit dcf0274e82
6 changed files with 25 additions and 57 deletions

View file

@ -29,8 +29,6 @@ nir_builder PRINTFLIKE(3, 4)
b.shader->options = &pdev->nir_options[stage];
radv_device_associate_nir(dev, b.shader);
return b;
}

View file

@ -25,6 +25,7 @@ struct radv_shader_layout;
struct radv_device;
struct radv_graphics_state_key;
struct radv_ps_epilog_key;
struct radv_debug_nir;
bool radv_nir_apply_pipeline_layout(nir_shader *shader, struct radv_device *device,
const struct radv_shader_stage *stage);
@ -81,7 +82,7 @@ bool radv_nir_remap_color_attachment(nir_shader *shader, const struct radv_graph
bool radv_nir_trim_fs_color_exports(nir_shader *shader, const struct radv_ps_epilog_key *epilog_key);
bool radv_nir_lower_printf(nir_shader *shader);
bool radv_nir_lower_printf(nir_shader *shader, struct radv_debug_nir *debug_nir);
typedef struct radv_nir_opt_tid_function_options {
bool use_masked_swizzle_amd : 1;

View file

@ -15,6 +15,8 @@
static bool
pass(nir_builder *b, nir_intrinsic_instr *instr, void *state)
{
struct radv_debug_nir *debug_nir = (struct radv_debug_nir *)state;
if (instr->intrinsic != nir_intrinsic_printf)
return false;
@ -28,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(b, NULL, info->strings, info->num_args, args);
radv_build_printf_args(debug_nir, b, NULL, info->strings, info->num_args, args);
nir_instr_remove(&instr->instr);
@ -38,9 +40,9 @@ pass(nir_builder *b, nir_intrinsic_instr *instr, void *state)
}
bool
radv_nir_lower_printf(nir_shader *shader)
radv_nir_lower_printf(nir_shader *shader, struct radv_debug_nir *debug_nir)
{
bool progress = nir_shader_intrinsics_pass(shader, pass, nir_metadata_none, NULL);
bool progress = nir_shader_intrinsics_pass(shader, pass, nir_metadata_none, debug_nir);
/* cleanup */
if (progress) {

View file

@ -8,15 +8,12 @@
#include "radv_device.h"
#include "radv_physical_device.h"
#include "util/hash_table.h"
#include "util/strndup.h"
#include "util/u_printf.h"
#include "nir.h"
#include "nir_builder.h"
static struct hash_table *device_ht = NULL;
VkResult
radv_printf_data_init(struct radv_device *device)
{
@ -97,22 +94,13 @@ radv_printf_data_finish(struct radv_device *device)
util_dynarray_fini(&printf->formats);
}
static bool
radv_shader_printf_enabled(nir_shader *shader)
{
if (!device_ht)
return false;
struct radv_device *device = _mesa_hash_table_search(device_ht, shader)->data;
struct radv_printf_data *printf = &device->debug_nir.printf;
return !!printf->buffer_addr;
}
void
radv_build_printf_args(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, nir_def *cond, const char *format_string,
uint32_t argc, nir_def **in_args)
{
if (!radv_shader_printf_enabled(b->shader))
struct radv_printf_data *printf = &debug_nir->printf;
if (!printf->buffer_addr)
return;
struct radv_printf_format format = {0};
@ -120,8 +108,6 @@ radv_build_printf_args(nir_builder *b, nir_def *cond, const char *format_string,
if (!format.string)
return;
struct radv_device *device = _mesa_hash_table_search(device_ht, b->shader)->data;
struct radv_printf_data *printf = &device->debug_nir.printf;
uint32_t format_index = util_dynarray_num_elements(&printf->formats, struct radv_printf_format);
if (cond)
@ -217,9 +203,11 @@ radv_build_printf_args(nir_builder *b, nir_def *cond, const char *format_string,
}
void
radv_build_printf(nir_builder *b, nir_def *cond, const char *format_string, ...)
radv_build_printf(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def *cond, const char *format_string, ...)
{
if (!radv_shader_printf_enabled(b->shader))
struct radv_printf_data *printf = &debug_nir->printf;
if (!printf->buffer_addr)
return;
va_list arg_list;
@ -237,7 +225,7 @@ radv_build_printf(nir_builder *b, nir_def *cond, const char *format_string, ...)
va_end(arg_list);
radv_build_printf_args(b, cond, format_string, num_args, args);
radv_build_printf_args(debug_nir, b, cond, format_string, num_args, args);
free(args);
}
@ -460,13 +448,10 @@ radv_va_validation_update_page(struct radv_device *device, uint64_t va, uint64_t
}
nir_def *
radv_build_is_valid_va(nir_builder *b, nir_def *addr)
radv_build_is_valid_va(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def *addr)
{
if (!device_ht)
return NULL;
struct radv_valid_va_data *valid_va = &debug_nir->valid_va;
struct radv_device *device = _mesa_hash_table_search(device_ht, b->shader)->data;
struct radv_valid_va_data *valid_va = &device->debug_nir.valid_va;
if (!valid_va->buffer_addr)
return NULL;
@ -489,22 +474,7 @@ radv_build_is_valid_va(nir_builder *b, nir_def *addr)
nir_pop_if(b, NULL);
nir_def *valid = nir_if_phi(b, then_valid, else_valid);
radv_build_printf(b, nir_inot(b, valid), "radv: Invalid VA %lx\n", addr);
radv_build_printf(debug_nir, b, nir_inot(b, valid), "radv: Invalid VA %lx\n", addr);
return valid;
}
void
radv_device_associate_nir(struct radv_device *device, nir_shader *nir)
{
struct radv_valid_va_data *valid_va = &device->debug_nir.valid_va;
struct radv_printf_data *printf = &device->debug_nir.printf;
if (!printf->buffer_addr && !valid_va->buffer_addr)
return;
if (!device_ht)
device_ht = _mesa_pointer_hash_table_create(NULL);
_mesa_hash_table_insert(device_ht, nir, device);
}

View file

@ -57,17 +57,16 @@ struct radv_debug_nir {
struct radv_valid_va_data valid_va;
};
void radv_device_associate_nir(struct radv_device *device, nir_shader *nir);
/* shader printf */
VkResult radv_printf_data_init(struct radv_device *device);
void radv_printf_data_finish(struct radv_device *device);
void radv_build_printf_args(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, nir_def *cond, const char *format,
uint32_t argc, nir_def **args);
void radv_build_printf(nir_builder *b, nir_def *cond, const char *format, ...);
void radv_build_printf(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def *cond, const char *format, ...);
void radv_dump_printf_data(struct radv_device *device, FILE *out);
@ -79,6 +78,6 @@ void radv_finish_va_validation(struct radv_device *device);
void radv_va_validation_update_page(struct radv_device *device, uint64_t va, uint64_t size, bool valid);
nir_def *radv_build_is_valid_va(nir_builder *b, nir_def *addr);
nir_def *radv_build_is_valid_va(struct radv_debug_nir *debug_nir, nir_builder *b, nir_def *addr);
#endif /* RADV_PRINTF_H */

View file

@ -519,10 +519,8 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_shader_st
free(spec_entries);
radv_device_associate_nir(device, nir);
if (device->debug_nir.printf.buffer_addr)
NIR_PASS(_, nir, radv_nir_lower_printf);
NIR_PASS(_, nir, radv_nir_lower_printf, &device->debug_nir);
const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
.point_coord = true,