diff --git a/src/amd/vulkan/layers/radv_rmv_layer.c b/src/amd/vulkan/layers/radv_rmv_layer.c index a7b7266fc06..90a1c6a9dcd 100644 --- a/src/amd/vulkan/layers/radv_rmv_layer.c +++ b/src/amd/vulkan/layers/radv_rmv_layer.c @@ -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; } diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 4922d4de6b6..d1f0053ebf2 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -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); diff --git a/src/amd/vulkan/radv_physical_device.c b/src/amd/vulkan/radv_physical_device.c index 43ab4a3a81e..f53d835b66d 100644 --- a/src/amd/vulkan/radv_physical_device.c +++ b/src/amd/vulkan/radv_physical_device.c @@ -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++; diff --git a/src/vulkan/runtime/rmv/vk_rmv_common.c b/src/vulkan/runtime/rmv/vk_rmv_common.c index 2dc6ba5a736..0473e8e1c37 100644 --- a/src/vulkan/runtime/rmv/vk_rmv_common.c +++ b/src/vulkan/runtime/rmv/vk_rmv_common.c @@ -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); } @@ -70,36 +66,6 @@ vk_memory_trace_finish(struct vk_device *device) device->memory_trace_data.is_enabled = false; } -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) { diff --git a/src/vulkan/runtime/rmv/vk_rmv_common.h b/src/vulkan/runtime/rmv/vk_rmv_common.h index fd346f3ee67..e6ee8bb5beb 100644 --- a/src/vulkan/runtime/rmv/vk_rmv_common.h +++ b/src/vulkan/runtime/rmv/vk_rmv_common.h @@ -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, diff --git a/src/vulkan/runtime/vk_instance.c b/src/vulkan/runtime/vk_instance.c index a2ae6fd6d97..bc5763e7659 100644 --- a/src/vulkan/runtime/vk_instance.c +++ b/src/vulkan/runtime/vk_instance.c @@ -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}, }; diff --git a/src/vulkan/runtime/vk_instance.h b/src/vulkan/runtime/vk_instance.h index f4da86d4001..1acc80870c0 100644 --- a/src/vulkan/runtime/vk_instance.h +++ b/src/vulkan/runtime/vk_instance.h @@ -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