From: Konstantin Seurer Date: Sun, 8 Jan 2023 20:25:59 +0000 (+0100) Subject: radv/rra: Use common trace trigger X-Git-Tag: upstream/23.3.3~6480 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3e11640127a268271f62e5e7c061712f685632af;p=platform%2Fupstream%2Fmesa.git radv/rra: Use common trace trigger Reviewed-by: Samuel Pitoiset Part-of: --- diff --git a/src/amd/vulkan/layers/radv_rra_layer.c b/src/amd/vulkan/layers/radv_rra_layer.c index bb5abf8..84ffcd1 100644 --- a/src/amd/vulkan/layers/radv_rra_layer.c +++ b/src/amd/vulkan/layers/radv_rra_layer.c @@ -28,63 +28,6 @@ #include "vk_common_entrypoints.h" #include "wsi_common_entrypoints.h" -static void -radv_rra_handle_trace(VkQueue _queue) -{ - RADV_FROM_HANDLE(radv_queue, queue, _queue); - - simple_mtx_lock(&queue->device->rra_trace.data_mtx); - /* - * TODO: This code is shared with RGP tracing and could be merged in a common helper. - */ - bool frame_trigger = queue->device->rra_trace.elapsed_frames == queue->device->rra_trace.trace_frame; - if (queue->device->rra_trace.elapsed_frames <= queue->device->rra_trace.trace_frame) - ++queue->device->rra_trace.elapsed_frames; - - bool file_trigger = false; -#ifndef _WIN32 - if (queue->device->rra_trace.trigger_file && access(queue->device->rra_trace.trigger_file, W_OK) == 0) { - if (unlink(queue->device->rra_trace.trigger_file) == 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, "radv: could not remove RRA trace trigger file, ignoring\n"); - } - } -#endif - - if (!frame_trigger && !file_trigger) { - simple_mtx_unlock(&queue->device->rra_trace.data_mtx); - return; - } - - if (_mesa_hash_table_num_entries(queue->device->rra_trace.accel_structs) == 0) { - fprintf(stderr, "radv: No acceleration structures captured, not saving RRA trace.\n"); - simple_mtx_unlock(&queue->device->rra_trace.data_mtx); - return; - } - - char filename[2048]; - struct tm now; - time_t t; - - t = time(NULL); - now = *localtime(&t); - - snprintf(filename, sizeof(filename), "/tmp/%s_%04d.%02d.%02d_%02d.%02d.%02d.rra", util_get_process_name(), - 1900 + now.tm_year, now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec); - - VkResult result = radv_rra_dump_trace(_queue, filename); - - if (result == VK_SUCCESS) - fprintf(stderr, "radv: RRA capture saved to '%s'\n", filename); - else - fprintf(stderr, "radv: Failed to save RRA capture!\n"); - - simple_mtx_unlock(&queue->device->rra_trace.data_mtx); -} - VKAPI_ATTR VkResult VKAPI_CALL rra_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo) { @@ -93,8 +36,6 @@ rra_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo) if (result != VK_SUCCESS) return result; - radv_rra_handle_trace(_queue); - if (!queue->device->rra_trace.copy_after_build) return VK_SUCCESS; diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index df2ece0..14db8d6 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -68,6 +68,7 @@ typedef void *drmDevicePtr; #include "util/os_time.h" #include "util/timespec.h" #include "util/u_atomic.h" +#include "util/u_process.h" #include "vulkan/vk_icd.h" #include "winsys/null/radv_null_winsys_public.h" #include "git_sha1.h" @@ -555,7 +556,7 @@ init_dispatch_tables(struct radv_device *device, struct radv_physical_device *ph if (radv_sqtt_enabled()) add_entrypoints(&b, &sqtt_device_entrypoints, RADV_RGP_DISPATCH_TABLE); - if (radv_rra_trace_enabled() && radv_enable_rt(physical_device, false)) + if ((physical_device->instance->vk.trace_mode & RADV_TRACE_MODE_RRA) && radv_enable_rt(physical_device, false)) add_entrypoints(&b, &rra_device_entrypoints, RADV_RRA_DISPATCH_TABLE); #ifndef _WIN32 @@ -594,6 +595,39 @@ radv_check_status(struct vk_device *vk_device) return VK_SUCCESS; } +static VkResult +capture_trace(VkQueue _queue) +{ + RADV_FROM_HANDLE(radv_queue, queue, _queue); + + VkResult result = VK_SUCCESS; + + char filename[2048]; + struct tm now; + time_t t; + + t = time(NULL); + now = *localtime(&t); + + if (queue->device->instance->vk.trace_mode & RADV_TRACE_MODE_RRA) { + if (_mesa_hash_table_num_entries(queue->device->rra_trace.accel_structs) == 0) { + fprintf(stderr, "radv: No acceleration structures captured, not saving RRA trace.\n"); + } else { + snprintf(filename, sizeof(filename), "/tmp/%s_%04d.%02d.%02d_%02d.%02d.%02d.rra", util_get_process_name(), + 1900 + now.tm_year, now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec); + + result = radv_rra_dump_trace(_queue, filename); + + if (result == VK_SUCCESS) + fprintf(stderr, "radv: RRA capture saved to '%s'\n", filename); + else + fprintf(stderr, "radv: Failed to save RRA capture!\n"); + } + } + + return result; +} + VKAPI_ATTR VkResult VKAPI_CALL radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) @@ -740,6 +774,8 @@ radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCr init_dispatch_tables(device, physical_device); + device->vk.capture_trace = capture_trace; + device->vk.command_buffer_ops = &radv_cmd_buffer_ops; device->vk.check_status = radv_check_status; @@ -1032,7 +1068,7 @@ radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCr } } - if (radv_rra_trace_enabled() && radv_enable_rt(physical_device, false)) { + if ((device->instance->vk.trace_mode & RADV_TRACE_MODE_RRA) && radv_enable_rt(physical_device, false)) { radv_rra_trace_init(device); } diff --git a/src/amd/vulkan/radv_physical_device.c b/src/amd/vulkan/radv_physical_device.c index c201e9c..2b2f536 100644 --- a/src/amd/vulkan/radv_physical_device.c +++ b/src/amd/vulkan/radv_physical_device.c @@ -2484,6 +2484,8 @@ VKAPI_ATTR VkResult VKAPI_CALL radv_GetPhysicalDeviceToolProperties(VkPhysicalDevice physicalDevice, uint32_t *pToolCount, VkPhysicalDeviceToolProperties *pToolProperties) { + VK_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice); + VK_OUTARRAY_MAKE_TYPED(VkPhysicalDeviceToolProperties, out, pToolProperties, pToolCount); bool rgp_enabled, rmv_enabled, rra_enabled; uint32_t tool_count = 0; @@ -2499,7 +2501,7 @@ radv_GetPhysicalDeviceToolProperties(VkPhysicalDevice physicalDevice, uint32_t * tool_count++; /* RRA */ - rra_enabled = radv_rra_trace_enabled(); + rra_enabled = pdevice->instance->vk.trace_mode & RADV_TRACE_MODE_RRA; if (rra_enabled) tool_count++; diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index bd2b8cf..3ce207e 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -920,9 +920,6 @@ struct radv_rra_accel_struct_data { void radv_destroy_rra_accel_struct_data(VkDevice device, struct radv_rra_accel_struct_data *data); struct radv_rra_trace_data { - int elapsed_frames; - int trace_frame; - char *trigger_file; struct hash_table *accel_structs; struct hash_table_u64 *accel_struct_vas; simple_mtx_t data_mtx; @@ -3036,10 +3033,6 @@ bool radv_sqtt_sample_clocks(struct radv_device *device); void radv_emit_inhibit_clockgating(const struct radv_device *device, struct radeon_cmdbuf *cs, bool inhibit); void radv_emit_spi_config_cntl(const struct radv_device *device, struct radeon_cmdbuf *cs, bool enable); -int radv_rra_trace_frame(void); -char *radv_rra_trace_trigger_file(void); -bool radv_rra_trace_enabled(void); - void radv_rra_trace_init(struct radv_device *device); VkResult radv_rra_dump_trace(VkQueue vk_queue, char *filename); diff --git a/src/amd/vulkan/radv_rra.c b/src/amd/vulkan/radv_rra.c index 769a784..9c19578 100644 --- a/src/amd/vulkan/radv_rra.c +++ b/src/amd/vulkan/radv_rra.c @@ -872,30 +872,9 @@ exit: return result; } -int -radv_rra_trace_frame() -{ - return (int)debug_get_num_option("RADV_RRA_TRACE", -1); -} - -char * -radv_rra_trace_trigger_file() -{ - return getenv("RADV_RRA_TRACE_TRIGGER"); -} - -bool -radv_rra_trace_enabled() -{ - return radv_rra_trace_frame() != -1 || radv_rra_trace_trigger_file(); -} - void radv_rra_trace_init(struct radv_device *device) { - device->rra_trace.trace_frame = radv_rra_trace_frame(); - device->rra_trace.elapsed_frames = 0; - device->rra_trace.trigger_file = radv_rra_trace_trigger_file(); device->rra_trace.validate_as = debug_get_bool_option("RADV_RRA_TRACE_VALIDATE", false); device->rra_trace.copy_after_build = debug_get_bool_option("RADV_RRA_TRACE_COPY_AFTER_BUILD", false); device->rra_trace.accel_structs = _mesa_pointer_hash_table_create(NULL);