radv: make the SQTT BO a resident buffer
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 3 Mar 2021 08:32:55 +0000 (09:32 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 21 Sep 2021 07:08:47 +0000 (09:08 +0200)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12854>

src/amd/vulkan/radv_sqtt.c

index b4e3757..04a67af 100644 (file)
@@ -391,6 +391,7 @@ radv_thread_trace_init_bo(struct radv_device *device)
 {
    unsigned max_se = device->physical_device->rad_info.max_se;
    struct radeon_winsys *ws = device->ws;
+   VkResult result;
    uint64_t size;
 
    /* The buffer size and address need to be aligned in HW regs. Align the
@@ -404,7 +405,7 @@ radv_thread_trace_init_bo(struct radv_device *device)
    size += device->thread_trace.buffer_size * (uint64_t)max_se;
 
    struct radeon_winsys_bo *bo = NULL;
-   VkResult result = ws->buffer_create(
+   result = ws->buffer_create(
       ws, size, 4096, RADEON_DOMAIN_VRAM,
       RADEON_FLAG_CPU_ACCESS | RADEON_FLAG_NO_INTERPROCESS_SHARING | RADEON_FLAG_ZERO_VRAM,
       RADV_BO_PRIORITY_SCRATCH, 0, &bo);
@@ -412,6 +413,10 @@ radv_thread_trace_init_bo(struct radv_device *device)
    if (result != VK_SUCCESS)
       return false;
 
+   result = ws->buffer_make_resident(ws, device->thread_trace.bo, true);
+   if (result != VK_SUCCESS)
+      return false;
+
    device->thread_trace.ptr = ws->buffer_map(device->thread_trace.bo);
    if (!device->thread_trace.ptr)
       return false;
@@ -419,6 +424,17 @@ radv_thread_trace_init_bo(struct radv_device *device)
    return true;
 }
 
+static void
+radv_thread_trace_finish_bo(struct radv_device *device)
+{
+   struct radeon_winsys *ws = device->ws;
+
+   if (unlikely(device->thread_trace.bo)) {
+      ws->buffer_make_resident(ws, device->thread_trace.bo, false);
+      ws->buffer_destroy(ws, device->thread_trace.bo);
+   }
+}
+
 bool
 radv_thread_trace_init(struct radv_device *device)
 {
@@ -454,8 +470,7 @@ radv_thread_trace_finish(struct radv_device *device)
    struct ac_thread_trace_data *thread_trace_data = &device->thread_trace;
    struct radeon_winsys *ws = device->ws;
 
-   if (unlikely(device->thread_trace.bo))
-      ws->buffer_destroy(ws, device->thread_trace.bo);
+   radv_thread_trace_finish_bo(device);
 
    for (unsigned i = 0; i < 2; i++) {
       if (device->thread_trace.start_cs[i])
@@ -477,10 +492,8 @@ radv_thread_trace_finish(struct radv_device *device)
 static bool
 radv_thread_trace_resize_bo(struct radv_device *device)
 {
-   struct radeon_winsys *ws = device->ws;
-
    /* Destroy the previous thread trace BO. */
-   ws->buffer_destroy(ws, device->thread_trace.bo);
+   radv_thread_trace_finish_bo(device);
 
    /* Double the size of the thread trace buffer per SE. */
    device->thread_trace.buffer_size *= 2;