[Mesa-dev] [PATCH 1/2] radv: move RADV_TRACE_FILE functions to radv_debug.c

Samuel Pitoiset samuel.pitoiset at gmail.com
Wed Aug 30 13:12:20 UTC 2017


At the moment, debugging radv is not really easy because the
driver doesn't report enough information when it hangs. This
new file will be the main location for all debug tools.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/amd/vulkan/Makefile.sources      |  1 +
 src/amd/vulkan/radv_debug.c          | 62 ++++++++++++++++++++++++++++++++++++
 src/amd/vulkan/radv_debug.h          |  7 ++++
 src/amd/vulkan/radv_device.c         | 24 ++------------
 src/amd/vulkan/radv_image.c          |  1 +
 src/amd/vulkan/radv_meta_clear.c     |  1 +
 src/amd/vulkan/radv_pipeline.c       |  1 +
 src/amd/vulkan/radv_pipeline_cache.c |  1 +
 src/amd/vulkan/radv_private.h        |  1 -
 9 files changed, 76 insertions(+), 23 deletions(-)
 create mode 100644 src/amd/vulkan/radv_debug.c

diff --git a/src/amd/vulkan/Makefile.sources b/src/amd/vulkan/Makefile.sources
index d3e0c81e9a..96399a246e 100644
--- a/src/amd/vulkan/Makefile.sources
+++ b/src/amd/vulkan/Makefile.sources
@@ -33,6 +33,7 @@ RADV_WS_AMDGPU_FILES := \
 VULKAN_FILES := \
 	radv_cmd_buffer.c \
 	radv_cs.h \
+	radv_debug.c \
 	radv_debug.h \
 	radv_device.c \
 	radv_descriptor_set.c \
diff --git a/src/amd/vulkan/radv_debug.c b/src/amd/vulkan/radv_debug.c
new file mode 100644
index 0000000000..8105d1f47e
--- /dev/null
+++ b/src/amd/vulkan/radv_debug.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright © 2016 Red Hat.
+ * Copyright © 2016 Bas Nieuwenhuizen
+ *
+ * based in part on anv driver which is:
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "radv_debug.h"
+
+bool radv_init_trace(struct radv_device *device)
+{
+	struct radeon_winsys *ws = device->ws;
+
+	device->trace_bo = ws->buffer_create(ws, 4096, 8, RADEON_DOMAIN_VRAM,
+					     RADEON_FLAG_CPU_ACCESS);
+	if (!device->trace_bo)
+		return false;
+
+	device->trace_id_ptr = ws->buffer_map(device->trace_bo);
+	if (!device->trace_id_ptr)
+		return false;
+
+	return true;
+}
+
+void radv_dump_trace(struct radv_device *device, struct radeon_winsys_cs *cs)
+{
+	const char *filename = getenv("RADV_TRACE_FILE");
+	FILE *f = fopen(filename, "w");
+
+	if (!f) {
+		fprintf(stderr, "Failed to write trace dump to %s\n", filename);
+		return;
+	}
+
+	fprintf(f, "Trace ID: %x\n", *device->trace_id_ptr);
+	device->ws->cs_dump(cs, f, (const int*)device->trace_id_ptr, 2);
+	fclose(f);
+}
diff --git a/src/amd/vulkan/radv_debug.h b/src/amd/vulkan/radv_debug.h
index c345d040c5..c9d5fcc73f 100644
--- a/src/amd/vulkan/radv_debug.h
+++ b/src/amd/vulkan/radv_debug.h
@@ -24,6 +24,8 @@
 #ifndef RADV_DEBUG_H
 #define RADV_DEBUG_H
 
+#include "radv_private.h"
+
 enum {
 	RADV_DEBUG_NO_FAST_CLEARS    =   0x1,
 	RADV_DEBUG_NO_DCC            =   0x2,
@@ -41,4 +43,9 @@ enum {
 	RADV_PERFTEST_BATCHCHAIN     =   0x1,
 	RADV_PERFTEST_SISCHED        =   0x2,
 };
+
+bool radv_init_trace(struct radv_device *device);
+
+void radv_dump_trace(struct radv_device *device, struct radeon_winsys_cs *cs);
+
 #endif
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 1e3148a043..aae3488318 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include "radv_debug.h"
 #include "radv_private.h"
 #include "radv_cs.h"
 #include "util/disk_cache.h"
@@ -1214,13 +1215,7 @@ VkResult radv_CreateDevice(
 	}
 
 	if (getenv("RADV_TRACE_FILE")) {
-		device->trace_bo = device->ws->buffer_create(device->ws, 4096, 8,
-							     RADEON_DOMAIN_VRAM, RADEON_FLAG_CPU_ACCESS);
-		if (!device->trace_bo)
-			goto fail;
-
-		device->trace_id_ptr = device->ws->buffer_map(device->trace_bo);
-		if (!device->trace_id_ptr)
+		if (!radv_init_trace(device))
 			goto fail;
 	}
 
@@ -1378,21 +1373,6 @@ void radv_GetDeviceQueue(
 	*pQueue = radv_queue_to_handle(&device->queues[queueFamilyIndex][queueIndex]);
 }
 
-static void radv_dump_trace(struct radv_device *device,
-			    struct radeon_winsys_cs *cs)
-{
-	const char *filename = getenv("RADV_TRACE_FILE");
-	FILE *f = fopen(filename, "w");
-	if (!f) {
-		fprintf(stderr, "Failed to write trace dump to %s\n", filename);
-		return;
-	}
-
-	fprintf(f, "Trace ID: %x\n", *device->trace_id_ptr);
-	device->ws->cs_dump(cs, f, (const int*)device->trace_id_ptr, 2);
-	fclose(f);
-}
-
 static void
 fill_geom_tess_rings(struct radv_queue *queue,
 		     uint32_t *map,
diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c
index e915d675fd..c9e8bb3d43 100644
--- a/src/amd/vulkan/radv_image.c
+++ b/src/amd/vulkan/radv_image.c
@@ -25,6 +25,7 @@
  * IN THE SOFTWARE.
  */
 
+#include "radv_debug.h"
 #include "radv_private.h"
 #include "vk_format.h"
 #include "vk_util.h"
diff --git a/src/amd/vulkan/radv_meta_clear.c b/src/amd/vulkan/radv_meta_clear.c
index 28c16c5672..b3eb3893d8 100644
--- a/src/amd/vulkan/radv_meta_clear.c
+++ b/src/amd/vulkan/radv_meta_clear.c
@@ -21,6 +21,7 @@
  * IN THE SOFTWARE.
  */
 
+#include "radv_debug.h"
 #include "radv_meta.h"
 #include "radv_private.h"
 #include "nir/nir_builder.h"
diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c
index e3a8dff992..ef5c646317 100644
--- a/src/amd/vulkan/radv_pipeline.c
+++ b/src/amd/vulkan/radv_pipeline.c
@@ -27,6 +27,7 @@
 
 #include "util/mesa-sha1.h"
 #include "util/u_atomic.h"
+#include "radv_debug.h"
 #include "radv_private.h"
 #include "nir/nir.h"
 #include "nir/nir_builder.h"
diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c
index 99a614dc10..98f2c3aded 100644
--- a/src/amd/vulkan/radv_pipeline_cache.c
+++ b/src/amd/vulkan/radv_pipeline_cache.c
@@ -24,6 +24,7 @@
 #include "util/mesa-sha1.h"
 #include "util/debug.h"
 #include "util/u_atomic.h"
+#include "radv_debug.h"
 #include "radv_private.h"
 
 #include "ac_nir_to_llvm.h"
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index cf5c853278..73f7bdbe8a 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -55,7 +55,6 @@
 #include "ac_nir_to_llvm.h"
 #include "ac_gpu_info.h"
 #include "ac_surface.h"
-#include "radv_debug.h"
 #include "radv_descriptor_set.h"
 
 #include <llvm-c/TargetMachine.h>
-- 
2.14.1



More information about the mesa-dev mailing list