radv: Add RADV_DEBUG=nirdebuginfo

Annotates the shader with source locations into the nir shader.

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29298>
This commit is contained in:
Konstantin Seurer 2024-08-28 09:49:22 +02:00 committed by Marge Bot
parent cf447c5da1
commit e3cf6290e0
7 changed files with 46 additions and 7 deletions

View file

@ -59,6 +59,7 @@ enum {
RADV_DEBUG_NO_NGG_GS = 1ull << 43,
RADV_DEBUG_NO_ESO = 1ull << 44,
RADV_DEBUG_PSO_CACHE_STATS = 1ull << 45,
RADV_DEBUG_NIR_DEBUG_INFO = 1ull << 46,
};
enum {

View file

@ -72,6 +72,7 @@ static const struct debug_control radv_debug_options[] = {{"nofastclears", RADV_
{"nongg_gs", RADV_DEBUG_NO_NGG_GS},
{"noeso", RADV_DEBUG_NO_ESO},
{"psocachestats", RADV_DEBUG_PSO_CACHE_STATS},
{"nirdebuginfo", RADV_DEBUG_NIR_DEBUG_INFO},
{NULL, 0}};
const char *

View file

@ -127,7 +127,7 @@ radv_compile_cs(struct radv_device *device, struct vk_pipeline_cache *cache, str
char *nir_string = NULL;
if (keep_executable_info || dump_shader)
nir_string = radv_dump_nir_shaders(&cs_stage->nir, 1);
nir_string = radv_dump_nir_shaders(instance, &cs_stage->nir, 1);
/* Compile NIR shader to AMD assembly. */
*cs_binary =

View file

@ -2277,7 +2277,7 @@ radv_create_gs_copy_shader(struct radv_device *device, struct vk_pipeline_cache
char *nir_string = NULL;
if (keep_executable_info || dump_shader)
nir_string = radv_dump_nir_shaders(&nir, 1);
nir_string = radv_dump_nir_shaders(instance, &nir, 1);
*gs_copy_binary = radv_shader_nir_to_asm(device, &gs_copy_stage, &nir, 1, &key.gfx_state, keep_executable_info,
keep_statistic_info);
@ -2344,7 +2344,7 @@ radv_graphics_shaders_nir_to_asm(struct radv_device *device, struct vk_pipeline_
char *nir_string = NULL;
if (keep_executable_info || dump_shader)
nir_string = radv_dump_nir_shaders(nir_shaders, shader_count);
nir_string = radv_dump_nir_shaders(instance, nir_shaders, shader_count);
binaries[s] = radv_shader_nir_to_asm(device, &stages[s], nir_shaders, shader_count, gfx_state,
keep_executable_info, keep_statistic_info);

View file

@ -446,7 +446,7 @@ radv_rt_nir_to_asm(struct radv_device *device, struct vk_pipeline_cache *cache,
char *nir_string = NULL;
if (keep_executable_info || dump_shader)
nir_string = radv_dump_nir_shaders(shaders, num_shaders);
nir_string = radv_dump_nir_shaders(instance, shaders, num_shaders);
/* Compile NIR shader to AMD assembly. */
binary =

View file

@ -2851,9 +2851,45 @@ radv_shader_part_cache_get(struct radv_device *device, struct radv_shader_part_c
return shader_part;
}
char *
radv_dump_nir_shaders(struct nir_shader *const *shaders, int shader_count)
static char *
radv_gather_nir_debug_info(struct nir_shader *const *shaders, int shader_count)
{
char **strings = malloc(shader_count * sizeof(char *));
uint32_t total_size = 1;
uint32_t first_line = 1;
for (uint32_t i = 0; i < shader_count; i++) {
char *string = nir_shader_gather_debug_info(shaders[i], "", first_line);
strings[i] = string;
uint32_t length = strlen(string);
total_size += length;
for (uint32_t c = 0; c < length; c++) {
if (string[c] == '\n')
first_line++;
}
}
char *ret = calloc(total_size, sizeof(char));
if (ret) {
for (uint32_t i = 0; i < shader_count; i++)
strcat(ret, strings[i]);
}
for (uint32_t i = 0; i < shader_count; i++)
ralloc_free(strings[i]);
free(strings);
return ret;
}
char *
radv_dump_nir_shaders(const struct radv_instance *instance, struct nir_shader *const *shaders, int shader_count)
{
if (instance->debug_flags & RADV_DEBUG_NIR_DEBUG_INFO)
return radv_gather_nir_debug_info(shaders, shader_count);
char *data = NULL;
char *ret = NULL;
size_t size = 0;

View file

@ -547,7 +547,8 @@ void radv_shader_generate_debug_info(struct radv_device *device, bool dump_shade
struct nir_shader *const *shaders, int shader_count,
struct radv_shader_info *info);
char *radv_dump_nir_shaders(struct nir_shader *const *shaders, int shader_count);
struct radv_instance;
char *radv_dump_nir_shaders(const struct radv_instance *instance, struct nir_shader *const *shaders, int shader_count);
VkResult radv_shader_wait_for_upload(struct radv_device *device, uint64_t seq);