radv: add code for exposing compiler statistics
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 4 Dec 2019 14:46:31 +0000 (14:46 +0000)
committerMarge Bot <eric+marge@anholt.net>
Fri, 3 Apr 2020 12:12:08 +0000 (12:12 +0000)
Statistics will be added to ACO in later commits.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2965>

src/amd/compiler/aco_interface.cpp
src/amd/vulkan/radv_pipeline.c
src/amd/vulkan/radv_shader.c
src/amd/vulkan/radv_shader.h

index 686fdca14e9e3c908366f672cf268c9790af5b80..378a138d245440ac352b673b8c8b235f8c460cd9 100644 (file)
@@ -168,6 +168,8 @@ void aco_compile_shader(unsigned shader_count,
    legacy_binary->base.is_gs_copy_shader = args->is_gs_copy_shader;
    legacy_binary->base.total_size = size;
 
+   legacy_binary->stats_size = 0;
+
    memcpy(legacy_binary->data, code.data(), code.size() * sizeof(uint32_t));
    legacy_binary->exec_size = exec_size;
    legacy_binary->code_size = code.size() * sizeof(uint32_t);
index c992fce953762883534644fbf49a2d280efe6677..f78043bf39e86d09d4fa1d9b0fa67d363c3f7545 100644 (file)
@@ -5625,6 +5625,20 @@ VkResult radv_GetPipelineExecutableStatisticsKHR(
        }
        ++s;
 
+       if (shader->statistics) {
+               for (unsigned i = 0; i < shader->statistics->count; i++) {
+                       struct radv_compiler_statistic_info *info = &shader->statistics->infos[i];
+                       uint32_t value = shader->statistics->values[i];
+                       if (s < end) {
+                               desc_copy(s->name, info->name);
+                               desc_copy(s->description, info->desc);
+                               s->format = VK_PIPELINE_EXECUTABLE_STATISTIC_FORMAT_UINT64_KHR;
+                               s->value.u64 = value;
+                       }
+                       ++s;
+               }
+       }
+
        if (!pStatistics)
                *pStatisticCount = s - pStatistics;
        else if (s > end) {
index 70a51ee01d06614246176f70472f1113e6560d6f..797c90159b822d4701ee18f3aed56e61750eb894 100644 (file)
@@ -1026,15 +1026,20 @@ radv_shader_variant_create(struct radv_device *device,
                ac_rtld_close(&rtld_binary);
        } else {
                struct radv_shader_binary_legacy* bin = (struct radv_shader_binary_legacy *)binary;
-               memcpy(dest_ptr, bin->data, bin->code_size);
+               memcpy(dest_ptr, bin->data + bin->stats_size, bin->code_size);
 
                /* Add end-of-code markers for the UMR disassembler. */
                uint32_t *ptr32 = (uint32_t *)dest_ptr + bin->code_size / 4;
                for (unsigned i = 0; i < DEBUGGER_NUM_MARKERS; i++)
                        ptr32[i] = DEBUGGER_END_OF_CODE_MARKER;
 
-               variant->ir_string = bin->ir_size ? strdup((const char*)(bin->data + bin->code_size)) : NULL;
-               variant->disasm_string = bin->disasm_size ? strdup((const char*)(bin->data + bin->code_size + bin->ir_size)) : NULL;
+               variant->ir_string = bin->ir_size ? strdup((const char*)(bin->data + bin->stats_size + bin->code_size)) : NULL;
+               variant->disasm_string = bin->disasm_size ? strdup((const char*)(bin->data + bin->stats_size + bin->code_size + bin->ir_size)) : NULL;
+
+               if (bin->stats_size) {
+                       variant->statistics = calloc(bin->stats_size, 1);
+                       memcpy(variant->statistics, bin->data, bin->stats_size);
+               }
        }
        return variant;
 }
@@ -1203,6 +1208,7 @@ radv_shader_variant_destroy(struct radv_device *device,
        free(variant->nir_string);
        free(variant->disasm_string);
        free(variant->ir_string);
+       free(variant->statistics);
        free(variant);
 }
 
@@ -1332,13 +1338,23 @@ generate_shader_stats(struct radv_device *device,
                                   "Code Size: %d bytes\n"
                                   "LDS: %d blocks\n"
                                   "Scratch: %d bytes per wave\n"
-                                  "Max Waves: %d\n"
-                                  "********************\n\n\n",
+                                  "Max Waves: %d\n",
                                   conf->num_sgprs, conf->num_vgprs,
                                   conf->spilled_sgprs, conf->spilled_vgprs,
                                   variant->info.private_mem_vgprs, variant->exec_size,
                                   conf->lds_size, conf->scratch_bytes_per_wave,
                                   max_simd_waves);
+
+       if (variant->statistics) {
+               _mesa_string_buffer_printf(buf, "*** COMPILER STATS ***\n");
+               for (unsigned i = 0; i < variant->statistics->count; i++) {
+                       struct radv_compiler_statistic_info *info = &variant->statistics->infos[i];
+                       uint32_t value = variant->statistics->values[i];
+                       _mesa_string_buffer_printf(buf, "%s: %lu\n", info->name, value);
+               }
+       }
+
+       _mesa_string_buffer_printf(buf, "********************\n\n\n");
 }
 
 void
index 99644b1ebf016bd3448b6b7e520e0f64b8d41eec..eb414829d96f95751ab37d10c3895241893814d1 100644 (file)
@@ -349,9 +349,10 @@ struct radv_shader_binary_legacy {
        unsigned exec_size;
        unsigned ir_size;
        unsigned disasm_size;
+       unsigned stats_size;
        
-       /* data has size of code_size + ir_size + disasm_size + 2, where
-        * the +2 is for 0 of the ir strings. */
+       /* data has size of stats_size + code_size + ir_size + disasm_size + 2,
+        * where the +2 is for 0 of the ir strings. */
        uint8_t data[0];
 };
 
@@ -362,6 +363,17 @@ struct radv_shader_binary_rtld {
        uint8_t data[0];
 };
 
+struct radv_compiler_statistic_info {
+       char name[32];
+       char desc[64];
+};
+
+struct radv_compiler_statistics {
+       unsigned count;
+       struct radv_compiler_statistic_info *infos;
+       uint32_t values[];
+};
+
 struct radv_shader_variant {
        uint32_t ref_count;
 
@@ -378,6 +390,7 @@ struct radv_shader_variant {
        char *nir_string;
        char *disasm_string;
        char *ir_string;
+       struct radv_compiler_statistics *statistics;
 
        struct list_head slab_list;
 };