From e1b08b55ff461677f05e827ebeab02918096ba0a Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 13 Mar 2020 10:39:41 +0100 Subject: [PATCH] radv/sqtt: handle thread trace capture in sqtt_QueuePresentKHR() To avoid wasting CPU cycles when thread trace is not enabled. Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Tested-by: Marge Bot Part-of: --- src/amd/vulkan/layers/radv_sqtt_layer.c | 44 ++++++++++++++++++++++ src/amd/vulkan/radv_wsi.c | 49 +++---------------------- 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/amd/vulkan/layers/radv_sqtt_layer.c b/src/amd/vulkan/layers/radv_sqtt_layer.c index 0e0551faf81..04909b20224 100644 --- a/src/amd/vulkan/layers/radv_sqtt_layer.c +++ b/src/amd/vulkan/layers/radv_sqtt_layer.c @@ -571,6 +571,50 @@ radv_describe_layout_transition(struct radv_cmd_buffer *cmd_buffer, cmd_buffer->state.num_layout_transitions++; } +/* TODO: Improve the way to trigger capture (overlay, etc). */ +static void +radv_handle_thread_trace(VkQueue _queue) +{ + RADV_FROM_HANDLE(radv_queue, queue, _queue); + static bool thread_trace_enabled = false; + static uint64_t num_frames = 0; + + if (thread_trace_enabled) { + struct radv_thread_trace thread_trace = {}; + + radv_end_thread_trace(queue); + thread_trace_enabled = false; + + /* TODO: Do something better than this whole sync. */ + radv_QueueWaitIdle(_queue); + + if (radv_get_thread_trace(queue, &thread_trace)) + radv_dump_thread_trace(queue->device, &thread_trace); + } else { + if (num_frames == queue->device->thread_trace_start_frame) { + radv_begin_thread_trace(queue); + assert(!thread_trace_enabled); + thread_trace_enabled = true; + } + } + num_frames++; +} + +VkResult sqtt_QueuePresentKHR( + VkQueue _queue, + const VkPresentInfoKHR* pPresentInfo) +{ + VkResult result; + + result = radv_QueuePresentKHR(_queue, pPresentInfo); + if (result != VK_SUCCESS) + return result; + + radv_handle_thread_trace(_queue); + + return VK_SUCCESS; +} + #define EVENT_MARKER(cmd_name, args...) \ RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer); \ radv_write_begin_general_api_marker(cmd_buffer, ApiCmd##cmd_name); \ diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c index 66a8d002f85..960b09700bb 100644 --- a/src/amd/vulkan/radv_wsi.c +++ b/src/amd/vulkan/radv_wsi.c @@ -269,55 +269,16 @@ VkResult radv_AcquireNextImage2KHR( return result; } -/* TODO: Improve the way to trigger capture (overlay, etc). */ -static void -radv_handle_thread_trace(VkQueue _queue) -{ - RADV_FROM_HANDLE(radv_queue, queue, _queue); - static bool thread_trace_enabled = false; - static uint64_t num_frames = 0; - - if (thread_trace_enabled) { - struct radv_thread_trace thread_trace = {}; - - radv_end_thread_trace(queue); - thread_trace_enabled = false; - - /* TODO: Do something better than this whole sync. */ - radv_QueueWaitIdle(_queue); - - if (radv_get_thread_trace(queue, &thread_trace)) - radv_dump_thread_trace(queue->device, &thread_trace); - } else { - if (num_frames == queue->device->thread_trace_start_frame) { - radv_begin_thread_trace(queue); - assert(!thread_trace_enabled); - thread_trace_enabled = true; - } - } - num_frames++; -} - VkResult radv_QueuePresentKHR( VkQueue _queue, const VkPresentInfoKHR* pPresentInfo) { RADV_FROM_HANDLE(radv_queue, queue, _queue); - VkResult result; - - result = wsi_common_queue_present(&queue->device->physical_device->wsi_device, - radv_device_to_handle(queue->device), - _queue, - queue->queue_family_index, - pPresentInfo); - if (result != VK_SUCCESS) - return result; - - if (unlikely(queue->device->thread_trace_bo)) { - radv_handle_thread_trace(_queue); - } - - return VK_SUCCESS; + return wsi_common_queue_present(&queue->device->physical_device->wsi_device, + radv_device_to_handle(queue->device), + _queue, + queue->queue_family_index, + pPresentInfo); } -- 2.30.2