[Mesa-dev] [PATCH 2/2] radv: dump SPIRV when a GPU hang is detected

Samuel Pitoiset samuel.pitoiset at gmail.com
Fri Sep 22 16:21:09 UTC 2017


Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/amd/vulkan/radv_debug.c  | 9 +++++++--
 src/amd/vulkan/radv_debug.h  | 2 +-
 src/amd/vulkan/radv_shader.c | 4 +++-
 src/amd/vulkan/radv_shader.h | 2 ++
 4 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/amd/vulkan/radv_debug.c b/src/amd/vulkan/radv_debug.c
index 08ee54c976..cb9509117e 100644
--- a/src/amd/vulkan/radv_debug.c
+++ b/src/amd/vulkan/radv_debug.c
@@ -497,6 +497,11 @@ radv_dump_shader(struct radv_pipeline *pipeline,
 
 	fprintf(f, "%s:\n\n", radv_get_shader_name(shader, stage));
 
+	if (shader->spirv) {
+		fprintf(f, "SPIRV:\n");
+		radv_print_spirv(shader->spirv, shader->spirv_size, f);
+	}
+
 	if (shader->nir) {
 		fprintf(f, "NIR:\n");
 		nir_print_shader(shader->nir, f);
@@ -700,7 +705,7 @@ radv_check_gpu_hangs(struct radv_queue *queue, struct radeon_winsys_cs *cs)
 }
 
 void
-radv_print_spirv(struct radv_shader_module *module, FILE *fp)
+radv_print_spirv(uint32_t *data, uint32_t size, FILE *fp)
 {
 	char path[] = "/tmp/fileXXXXXX";
 	char line[2048], command[128];
@@ -712,7 +717,7 @@ radv_print_spirv(struct radv_shader_module *module, FILE *fp)
 	if (fd < 0)
 		return;
 
-	if (write(fd, module->data, module->size) == -1)
+	if (write(fd, data, size) == -1)
 		goto fail;
 
 	sprintf(command, "spirv-dis %s", path);
diff --git a/src/amd/vulkan/radv_debug.h b/src/amd/vulkan/radv_debug.h
index 5c9cbade47..193bca5f81 100644
--- a/src/amd/vulkan/radv_debug.h
+++ b/src/amd/vulkan/radv_debug.h
@@ -55,6 +55,6 @@ void
 radv_check_gpu_hangs(struct radv_queue *queue, struct radeon_winsys_cs *cs);
 
 void
-radv_print_spirv(struct radv_shader_module *module, FILE *fp);
+radv_print_spirv(uint32_t *data, uint32_t size, FILE *fp);
 
 #endif
diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c
index 349e291b06..285f42e937 100644
--- a/src/amd/vulkan/radv_shader.c
+++ b/src/amd/vulkan/radv_shader.c
@@ -175,7 +175,7 @@ radv_shader_compile_to_nir(struct radv_device *device,
 		assert(module->size % 4 == 0);
 
 		if (device->debug_flags & RADV_DEBUG_DUMP_SPIRV)
-			radv_print_spirv(module, stderr);
+			radv_print_spirv(spirv, module->size, stderr);
 
 		uint32_t num_spec_entries = 0;
 		struct nir_spirv_specialization *spec_entries = NULL;
@@ -433,6 +433,8 @@ shader_variant_create(struct radv_device *device,
 		variant->disasm_string = binary.disasm_string;
 		if (!gs_copy_shader && !module->nir) {
 			variant->nir = shader;
+			variant->spirv = (uint32_t *)module->data;
+			variant->spirv_size = module->size;
 		}
 	} else {
 		free(binary.disasm_string);
diff --git a/src/amd/vulkan/radv_shader.h b/src/amd/vulkan/radv_shader.h
index 7ad38bf579..1ef13968f9 100644
--- a/src/amd/vulkan/radv_shader.h
+++ b/src/amd/vulkan/radv_shader.h
@@ -51,6 +51,8 @@ struct radv_shader_variant {
 	unsigned rsrc2;
 
 	/* debug only */
+	uint32_t *spirv;
+	uint32_t spirv_size;
 	struct nir_shader *nir;
 	char *disasm_string;
 
-- 
2.14.1



More information about the mesa-dev mailing list