vulkan/rmv,radv: Use common trace trigger
authorKonstantin Seurer <konstantin.seurer@gmail.com>
Sat, 14 Jan 2023 14:18:09 +0000 (15:18 +0100)
committerMarge Bot <emma+marge@anholt.net>
Tue, 27 Jun 2023 06:25:56 +0000 (06:25 +0000)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20573>

src/amd/vulkan/layers/radv_rmv_layer.c
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_physical_device.c
src/vulkan/runtime/rmv/vk_rmv_common.c
src/vulkan/runtime/rmv/vk_rmv_common.h
src/vulkan/runtime/vk_instance.c
src/vulkan/runtime/vk_instance.h

index a7b7266..90a1c6a 100644 (file)
@@ -39,11 +39,6 @@ rmv_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)
 
    vk_rmv_log_misc_token(&device->vk, VK_RMV_MISC_EVENT_TYPE_PRESENT);
 
-   simple_mtx_lock(&device->vk.memory_trace_data.token_mtx);
-   radv_rmv_collect_trace_events(device);
-   vk_rmv_handle_present_locked(&device->vk);
-   simple_mtx_unlock(&device->vk.memory_trace_data.token_mtx);
-
    return VK_SUCCESS;
 }
 
index 4922d4d..d1f0053 100644 (file)
@@ -561,7 +561,7 @@ init_dispatch_tables(struct radv_device *device, struct radv_physical_device *ph
       add_entrypoints(&b, &rra_device_entrypoints, RADV_RRA_DISPATCH_TABLE);
 
 #ifndef _WIN32
-   if (vk_memory_trace_enabled())
+   if (physical_device->instance->vk.trace_mode & VK_TRACE_MODE_RMV)
       add_entrypoints(&b, &rmv_device_entrypoints, RADV_RMV_DISPATCH_TABLE);
 #endif
 
@@ -626,6 +626,13 @@ capture_trace(VkQueue _queue)
       }
    }
 
+   if (queue->device->vk.memory_trace_data.is_enabled) {
+      simple_mtx_lock(&queue->device->vk.memory_trace_data.token_mtx);
+      radv_rmv_collect_trace_events(queue->device);
+      vk_dump_rmv_capture(&queue->device->vk.memory_trace_data);
+      simple_mtx_unlock(&queue->device->vk.memory_trace_data.token_mtx);
+   }
+
    if (queue->device->instance->vk.trace_mode & RADV_TRACE_MODE_RGP)
       queue->device->sqtt_triggered = true;
 
@@ -963,7 +970,7 @@ radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCr
    }
 
 #ifndef _WIN32
-   if (vk_memory_trace_enabled()) {
+   if (physical_device->instance->vk.trace_mode & VK_TRACE_MODE_RMV) {
       struct vk_rmv_device_info info;
       memset(&info, 0, sizeof(struct vk_rmv_device_info));
       radv_rmv_fill_device_info(physical_device, &info);
index 43ab4a3..f53d835 100644 (file)
@@ -2490,7 +2490,7 @@ radv_GetPhysicalDeviceToolProperties(VkPhysicalDevice physicalDevice, uint32_t *
       tool_count++;
 
    /* RMV */
-   rmv_enabled = vk_memory_trace_enabled();
+   rmv_enabled = pdevice->instance->vk.trace_mode & VK_TRACE_MODE_RMV;
    if (rmv_enabled)
       tool_count++;
 
index 2dc6ba5..0473e8e 100644 (file)
@@ -33,10 +33,6 @@ vk_memory_trace_init(struct vk_device *device, const struct vk_rmv_device_info *
    util_dynarray_init(&device->memory_trace_data.tokens, NULL);
    simple_mtx_init(&device->memory_trace_data.token_mtx, mtx_plain);
 
-   device->memory_trace_data.trace_frame_idx = vk_memory_trace_frame();
-   device->memory_trace_data.trigger_file_name = vk_memory_trace_trigger_file();
-
-   device->memory_trace_data.cur_frame_idx = 0;
    device->memory_trace_data.next_resource_id = 1;
    device->memory_trace_data.handle_table = _mesa_hash_table_u64_create(NULL);
 }
@@ -71,36 +67,6 @@ vk_memory_trace_finish(struct vk_device *device)
 }
 
 void
-vk_rmv_handle_present_locked(struct vk_device *device)
-{
-   struct vk_memory_trace_data *trace_data = &device->memory_trace_data;
-
-   if (!trace_data->is_enabled)
-      return;
-   bool frame_trigger = false;
-   bool file_trigger = false;
-
-#ifndef _WIN32
-   if (trace_data->trigger_file_name && access(trace_data->trigger_file_name, W_OK) == 0) {
-      if (unlink(trace_data->trigger_file_name) == 0)
-         file_trigger = true;
-      else
-         /* Do not enable tracing if we cannot remove the file,
-          * because by then we'll trace every frame ... */
-         fprintf(stderr, "mesa: could not remove memory trace trigger "
-                         "file, ignoring\n");
-   }
-#endif
-
-   frame_trigger = trace_data->cur_frame_idx == trace_data->trace_frame_idx;
-   if (trace_data->cur_frame_idx <= trace_data->trace_frame_idx)
-      trace_data->cur_frame_idx++;
-
-   if (file_trigger || frame_trigger)
-      vk_dump_rmv_capture(trace_data);
-}
-
-void
 vk_rmv_emit_token(struct vk_memory_trace_data *data, enum vk_rmv_token_type type, void *token_data)
 {
    struct vk_rmv_token token;
index fd346f3..e6ee8bb 100644 (file)
@@ -106,10 +106,6 @@ struct vk_memory_trace_data {
    struct util_dynarray tokens;
    simple_mtx_t token_mtx;
 
-   int32_t cur_frame_idx;
-   int32_t trace_frame_idx;
-   const char *trigger_file_name;
-
    bool is_enabled;
 
    struct vk_rmv_device_info device_info;
@@ -120,31 +116,10 @@ struct vk_memory_trace_data {
 
 struct vk_device;
 
-static inline int
-vk_memory_trace_frame()
-{
-   return (int)debug_get_num_option("MESA_VK_MEMORY_TRACE", -1);
-}
-
-static inline const char *
-vk_memory_trace_trigger_file()
-{
-   return getenv("MESA_VK_MEMORY_TRACE_TRIGGER");
-}
-
-static inline bool
-vk_memory_trace_enabled()
-{
-   return vk_memory_trace_frame() != -1 || vk_memory_trace_trigger_file();
-}
-
 void vk_memory_trace_init(struct vk_device *device, const struct vk_rmv_device_info *device_info);
 
 void vk_memory_trace_finish(struct vk_device *device);
 
-/* The memory trace mutex should be locked when entering this function. */
-void vk_rmv_handle_present_locked(struct vk_device *device);
-
 int vk_dump_rmv_capture(struct vk_memory_trace_data *data);
 
 void vk_rmv_emit_token(struct vk_memory_trace_data *data, enum vk_rmv_token_type type,
index a2ae6fd..bc5763e 100644 (file)
@@ -39,6 +39,7 @@
    (VK_API_VERSION_MAJOR(version) == 1 && VK_API_VERSION_MINOR(version) == 0)
 
 static const struct debug_control trace_options[] = {
+   {"rmv", VK_TRACE_MODE_RMV},
    {NULL, 0},
 };
 
index f4da86d..1acc808 100644 (file)
@@ -60,8 +60,11 @@ struct _drmDevice;
 struct vk_physical_device;
 
 enum vk_trace_mode {
+   /** Radeon Memory Visualizer */
+   VK_TRACE_MODE_RMV = 1 << 0,
+
    /** Number of common trace modes. */
-   VK_TRACE_MODE_COUNT = 0,
+   VK_TRACE_MODE_COUNT = 1,
 };
 
 /** Base struct for all `VkInstance` implementations