radv/sqtt: describe begin/end command buffers with user markers
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 3 Mar 2020 12:42:41 +0000 (13:42 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 10 Mar 2020 08:58:02 +0000 (09:58 +0100)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4031>

src/amd/vulkan/layers/radv_sqtt_layer.c
src/amd/vulkan/radv_cmd_buffer.c
src/amd/vulkan/radv_private.h

index 18131cc0efbff011e1ae65ab59e3603eddb5d060..a55a2396eac364aca928be45d8a4a79577145fa9 100644 (file)
@@ -45,6 +45,63 @@ enum rgp_sqtt_marker_identifier {
        RGP_SQTT_MARKER_IDENTIFIER_RESERVED6            = 0xF
 };
 
+/**
+ * RGP SQ thread-tracing marker for the start of a command buffer. (Table 2)
+ */
+struct rgp_sqtt_marker_cb_start {
+       union {
+               struct {
+                       uint32_t identifier : 4;
+                       uint32_t ext_dwords : 3;
+                       uint32_t cb_id : 20;
+                       uint32_t queue : 5;
+               };
+               uint32_t dword01;
+       };
+       union {
+               uint32_t device_id_low;
+               uint32_t dword02;
+       };
+       union {
+               uint32_t device_id_high;
+               uint32_t dword03;
+       };
+       union {
+               uint32_t queue_flags;
+               uint32_t dword04;
+       };
+};
+
+static_assert(sizeof(struct rgp_sqtt_marker_cb_start) == 16,
+             "rgp_sqtt_marker_cb_start doesn't match RGP spec");
+
+/**
+ *
+ * RGP SQ thread-tracing marker for the end of a command buffer. (Table 3)
+ */
+struct rgp_sqtt_marker_cb_end {
+       union {
+               struct {
+                       uint32_t identifier : 4;
+                       uint32_t ext_dwords : 3;
+                       uint32_t cb_id : 20;
+                       uint32_t reserved : 5;
+               };
+               uint32_t dword01;
+       };
+       union {
+               uint32_t device_id_low;
+               uint32_t dword02;
+       };
+       union {
+               uint32_t device_id_high;
+               uint32_t dword03;
+       };
+};
+
+static_assert(sizeof(struct rgp_sqtt_marker_cb_end) == 12,
+             "rgp_sqtt_marker_cb_end doesn't match RGP spec");
+
 /**
  * API types used in RGP SQ thread-tracing markers for the "General API"
  * packet.
@@ -145,6 +202,49 @@ radv_write_end_general_api_marker(struct radv_cmd_buffer *cmd_buffer,
        radv_emit_thread_trace_userdata(cs, &marker, sizeof(marker) / 4);
 }
 
+void
+radv_describe_begin_cmd_buffer(struct radv_cmd_buffer *cmd_buffer)
+{
+       uint64_t device_id = (uint64_t)cmd_buffer->device;
+       struct rgp_sqtt_marker_cb_start marker = {};
+       struct radeon_cmdbuf *cs = cmd_buffer->cs;
+
+       if (likely(!cmd_buffer->device->thread_trace_bo))
+               return;
+
+       marker.identifier = RGP_SQTT_MARKER_IDENTIFIER_CB_START;
+       marker.cb_id = 0;
+       marker.device_id_low = device_id;
+       marker.device_id_high = device_id >> 32;
+       marker.queue = cmd_buffer->queue_family_index;
+       marker.queue_flags = VK_QUEUE_COMPUTE_BIT |
+                            VK_QUEUE_TRANSFER_BIT |
+                            VK_QUEUE_SPARSE_BINDING_BIT;
+
+       if (cmd_buffer->queue_family_index == RADV_QUEUE_GENERAL)
+               marker.queue_flags |= VK_QUEUE_GRAPHICS_BIT;
+
+       radv_emit_thread_trace_userdata(cs, &marker, sizeof(marker) / 4);
+}
+
+void
+radv_describe_end_cmd_buffer(struct radv_cmd_buffer *cmd_buffer)
+{
+       uint64_t device_id = (uint64_t)cmd_buffer->device;
+       struct rgp_sqtt_marker_cb_end marker = {};
+       struct radeon_cmdbuf *cs = cmd_buffer->cs;
+
+       if (likely(!cmd_buffer->device->thread_trace_bo))
+               return;
+
+       marker.identifier = RGP_SQTT_MARKER_IDENTIFIER_CB_END;
+       marker.cb_id = 0;
+       marker.device_id_low = device_id;
+       marker.device_id_high = device_id >> 32;
+
+       radv_emit_thread_trace_userdata(cs, &marker, sizeof(marker) / 4);
+}
+
 #define API_MARKER(cmd_name, args...) \
        RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer); \
        radv_write_begin_general_api_marker(cmd_buffer, ApiCmd##cmd_name); \
index 08c7400e820e3332977652c74796183b8cae8896..096c06d3ed0631e8eb07c5bb90d892e1a70b8940 100644 (file)
@@ -3441,6 +3441,8 @@ VkResult radv_BeginCommandBuffer(
        if (unlikely(cmd_buffer->device->trace_bo))
                radv_cmd_buffer_trace_emit(cmd_buffer);
 
+       radv_describe_begin_cmd_buffer(cmd_buffer);
+
        cmd_buffer->status = RADV_CMD_BUFFER_STATUS_RECORDING;
 
        return result;
@@ -3794,6 +3796,8 @@ VkResult radv_EndCommandBuffer(
         */
        si_cp_dma_wait_for_idle(cmd_buffer);
 
+       radv_describe_end_cmd_buffer(cmd_buffer);
+
        vk_free(&cmd_buffer->pool->alloc, cmd_buffer->state.attachments);
        vk_free(&cmd_buffer->pool->alloc, cmd_buffer->state.subpass_sample_locs);
 
index ab056b49821827c1c29cb8b9c76441c3521be8bc..6eedf910bf41d94187988c24097bd32ebc4f78c5 100644 (file)
@@ -2419,6 +2419,10 @@ void radv_emit_thread_trace_userdata(struct radeon_cmdbuf *cs,
 int radv_dump_thread_trace(struct radv_device *device,
                           const struct radv_thread_trace *trace);
 
+/* radv_sqtt_layer_.c */
+void radv_describe_begin_cmd_buffer(struct radv_cmd_buffer *cmd_buffer);
+void radv_describe_end_cmd_buffer(struct radv_cmd_buffer *cmd_buffer);
+
 struct radeon_winsys_sem;
 
 uint64_t radv_get_current_time(void);