radv: fix dumping SPIR-V into hang reports
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 28 Oct 2019 15:56:15 +0000 (16:56 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 30 Oct 2019 13:02:08 +0000 (13:02 +0000)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_debug.c
src/amd/vulkan/radv_debug.h
src/amd/vulkan/radv_shader.c
src/amd/vulkan/radv_shader.h

index 60a386e48642c7da2fdb070a355bf77ff3deb631..68d361f41dd6c12063f4b12aadf61357e3abcb3b 100644 (file)
@@ -643,7 +643,7 @@ radv_check_gpu_hangs(struct radv_queue *queue, struct radeon_cmdbuf *cs)
 }
 
 void
-radv_print_spirv(uint32_t *data, uint32_t size, FILE *fp)
+radv_print_spirv(const char *data, uint32_t size, FILE *fp)
 {
        char path[] = "/tmp/fileXXXXXX";
        char line[2048], command[128];
index 2ec460ec15a16e55c66ed768916b29f6383a2b15..1a8de6a6ba483c18976c9420ae21f1bad60de431 100644 (file)
@@ -82,7 +82,7 @@ void
 radv_check_gpu_hangs(struct radv_queue *queue, struct radeon_cmdbuf *cs);
 
 void
-radv_print_spirv(uint32_t *data, uint32_t size, FILE *fp);
+radv_print_spirv(const char *data, uint32_t size, FILE *fp);
 
 void
 radv_dump_enabled_options(struct radv_device *device, FILE *f);
index a5ad594207d990d472ab7ebdb8510c1619988a87..c841a2f072623aab55372437d716eaf39f654d44 100644 (file)
@@ -312,7 +312,7 @@ radv_shader_compile_to_nir(struct radv_device *device,
                assert(module->size % 4 == 0);
 
                if (device->instance->debug_flags & RADV_DEBUG_DUMP_SPIRV)
-                       radv_print_spirv(spirv, module->size, stderr);
+                       radv_print_spirv(module->data, module->size, stderr);
 
                uint32_t num_spec_entries = 0;
                struct nir_spirv_specialization *spec_entries = NULL;
@@ -1145,7 +1145,14 @@ shader_variant_compile(struct radv_device *device,
        if (keep_shader_info) {
                variant->nir_string = radv_dump_nir_shaders(shaders, shader_count);
                if (!gs_copy_shader && !module->nir) {
-                       variant->spirv = (uint32_t *)module->data;
+                       variant->spirv = malloc(module->size);
+                       if (!variant->spirv) {
+                               free(variant);
+                               free(binary);
+                               return NULL;
+                       }
+
+                       memcpy(variant->spirv, module->data, module->size);
                        variant->spirv_size = module->size;
                }
        }
@@ -1211,6 +1218,7 @@ radv_shader_variant_destroy(struct radv_device *device,
        list_del(&variant->slab_list);
        mtx_unlock(&device->shader_slab_mutex);
 
+       free(variant->spirv);
        free(variant->nir_string);
        free(variant->disasm_string);
        free(variant->ir_string);
index 5af3296150e3cc5a4f1945d0966b56dd8d5d46c0..0eca6ef0e79b36feefe540641db77ff936e54d25 100644 (file)
@@ -366,7 +366,7 @@ struct radv_shader_variant {
 
        /* debug only */
        bool aco_used;
-       uint32_t *spirv;
+       char *spirv;
        uint32_t spirv_size;
        char *nir_string;
        char *disasm_string;