From: Samuel Pitoiset Date: Fri, 14 Aug 2020 11:59:16 +0000 (+0200) Subject: radv,aco: report ACO errors/warnings back via VK_EXT_debug_report X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=commitdiff_plain;h=e901b901cb61519514271ffc76a8c784c5e37d2a;hp=c2b1978aa47c5b8876a589aa035a670d55e87c2e radv,aco: report ACO errors/warnings back via VK_EXT_debug_report To help developers. Signed-off-by: Samuel Pitoiset Reviewed-by: Rhys Perry Part-of: --- diff --git a/src/amd/compiler/aco_interface.cpp b/src/amd/compiler/aco_interface.cpp index 4dfba2618cc..96a968d376a 100644 --- a/src/amd/compiler/aco_interface.cpp +++ b/src/amd/compiler/aco_interface.cpp @@ -66,6 +66,9 @@ void aco_compile_shader(unsigned shader_count, if (program->collect_statistics) memset(program->statistics, 0, sizeof(program->statistics)); + program->debug.func = args->options->debug.func; + program->debug.private_data = args->options->debug.private_data; + /* Instruction Selection */ if (args->is_gs_copy_shader) aco::select_gs_copy_shader(program.get(), shaders[0], &config, args); diff --git a/src/amd/compiler/aco_ir.h b/src/amd/compiler/aco_ir.h index 5fb4a095db9..0b3a7767a3c 100644 --- a/src/amd/compiler/aco_ir.h +++ b/src/amd/compiler/aco_ir.h @@ -37,6 +37,8 @@ #include "aco_opcodes.h" #include "aco_util.h" +#include "vulkan/radv_shader.h" + struct radv_nir_compiler_options; struct radv_shader_args; struct radv_shader_info; @@ -1580,6 +1582,13 @@ public: bool collect_statistics = false; uint32_t statistics[num_statistics]; + struct { + void (*func)(void *private_data, + enum radv_compiler_debug_level level, + const char *message); + void *private_data; + } debug; + uint32_t allocateId() { assert(allocationID <= 16777215); diff --git a/src/amd/compiler/aco_validate.cpp b/src/amd/compiler/aco_validate.cpp index b09cf2bb86b..b109c41a72a 100644 --- a/src/amd/compiler/aco_validate.cpp +++ b/src/amd/compiler/aco_validate.cpp @@ -29,8 +29,8 @@ namespace aco { -static void aco_log(Program *program, const char *prefix, - const char *file, unsigned line, +static void aco_log(Program *program, enum radv_compiler_debug_level level, + const char *prefix, const char *file, unsigned line, const char *fmt, va_list args) { char *msg; @@ -41,7 +41,8 @@ static void aco_log(Program *program, const char *prefix, ralloc_asprintf_append(&msg, " "); ralloc_vasprintf_append(&msg, fmt, args); - /* TODO: log messages via callback if available too. */ + if (program->debug.func) + program->debug.func(program->debug.private_data, level, msg); fprintf(stderr, "%s\n", msg); @@ -54,7 +55,8 @@ void _aco_perfwarn(Program *program, const char *file, unsigned line, va_list args; va_start(args, fmt); - aco_log(program, "ACO PERFWARN:\n", file, line, fmt, args); + aco_log(program, RADV_COMPILER_DEBUG_LEVEL_PERFWARN, + "ACO PERFWARN:\n", file, line, fmt, args); va_end(args); } @@ -64,7 +66,8 @@ void _aco_err(Program *program, const char *file, unsigned line, va_list args; va_start(args, fmt); - aco_log(program, "ACO ERROR:\n", file, line, fmt, args); + aco_log(program, RADV_COMPILER_DEBUG_LEVEL_ERROR, + "ACO ERROR:\n", file, line, fmt, args); va_end(args); } diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index c3a2b538ab7..16253979b08 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -299,7 +299,7 @@ shared_var_info(const struct glsl_type *type, unsigned *size, unsigned *align) *align = comp_size; } -struct radv_spirv_debug_data { +struct radv_shader_debug_data { struct radv_device *device; const struct radv_shader_module *module; }; @@ -309,7 +309,7 @@ static void radv_spirv_nir_debug(void *private_data, size_t spirv_offset, const char *message) { - struct radv_spirv_debug_data *debug_data = private_data; + struct radv_shader_debug_data *debug_data = private_data; struct radv_instance *instance = debug_data->device->instance; static const VkDebugReportFlagsEXT vk_flags[] = { @@ -329,6 +329,28 @@ static void radv_spirv_nir_debug(void *private_data, 0, 0, "radv", buffer); } +static void radv_compiler_debug(void *private_data, + enum radv_compiler_debug_level level, + const char *message) +{ + struct radv_shader_debug_data *debug_data = private_data; + struct radv_instance *instance = debug_data->device->instance; + + static const VkDebugReportFlagsEXT vk_flags[] = { + [RADV_COMPILER_DEBUG_LEVEL_PERFWARN] = VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, + [RADV_COMPILER_DEBUG_LEVEL_ERROR] = VK_DEBUG_REPORT_ERROR_BIT_EXT, + }; + + /* VK_DEBUG_REPORT_DEBUG_BIT_EXT specifies diagnostic information + * from the implementation and layers. + */ + vk_debug_report(&instance->debug_report_callbacks, + vk_flags[level] | VK_DEBUG_REPORT_DEBUG_BIT_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, + (uint64_t)(uintptr_t)debug_data->module, + 0, 0, "radv", message); +} + nir_shader * radv_shader_compile_to_nir(struct radv_device *device, struct radv_shader_module *module, @@ -390,7 +412,7 @@ radv_shader_compile_to_nir(struct radv_device *device, } } - struct radv_spirv_debug_data spirv_debug_data = { + struct radv_shader_debug_data spirv_debug_data = { .device = device, .module = module, }; @@ -1185,6 +1207,11 @@ shader_variant_compile(struct radv_device *device, enum radeon_family chip_family = device->physical_device->rad_info.family; struct radv_shader_binary *binary = NULL; + struct radv_shader_debug_data debug_data = { + .device = device, + .module = module, + }; + options->family = chip_family; options->chip_class = device->physical_device->rad_info.chip_class; options->dump_shader = radv_can_dump_shader(device, module, gs_copy_shader); @@ -1198,6 +1225,8 @@ shader_variant_compile(struct radv_device *device, options->has_ls_vgpr_init_bug = device->physical_device->rad_info.has_ls_vgpr_init_bug; options->use_ngg_streamout = device->physical_device->use_ngg_streamout; options->enable_mrt_output_nan_fixup = device->instance->enable_mrt_output_nan_fixup; + options->debug.func = radv_compiler_debug; + options->debug.private_data = &debug_data; struct radv_shader_args args = {}; args.options = options; diff --git a/src/amd/vulkan/radv_shader.h b/src/amd/vulkan/radv_shader.h index adf5620ef23..cb76e635dc5 100644 --- a/src/amd/vulkan/radv_shader.h +++ b/src/amd/vulkan/radv_shader.h @@ -129,6 +129,11 @@ struct radv_shader_variant_key { bool has_multiview_view_index; }; +enum radv_compiler_debug_level { + RADV_COMPILER_DEBUG_LEVEL_PERFWARN, + RADV_COMPILER_DEBUG_LEVEL_ERROR, +}; + struct radv_nir_compiler_options { struct radv_pipeline_layout *layout; struct radv_shader_variant_key key; @@ -147,6 +152,13 @@ struct radv_nir_compiler_options { enum chip_class chip_class; uint32_t tess_offchip_block_dw_size; uint32_t address32_hi; + + struct { + void (*func)(void *private_data, + enum radv_compiler_debug_level level, + const char *message); + void *private_data; + } debug; }; enum radv_ud_index {