radv: initial implementation of the driver internal layer SQTT
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 26 Feb 2020 13:05:15 +0000 (14:05 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 10 Mar 2020 08:57:59 +0000 (09:57 +0100)
This layer is used to emit SQTT user markers to command buffers. It
currently only emits API markers but it will consolidated soon with
barrier markers and more.

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/Makefile.sources
src/amd/vulkan/layers/radv_sqtt_layer.c [new file with mode: 0644]
src/amd/vulkan/meson.build

index 11bd6e4aa67b5d4d52e4c350601d1814fbb4eeee..4035ca52dee7b41205051759165fbedded4ac1f2 100644 (file)
@@ -39,6 +39,9 @@ RADV_WS_NULL_FILES := \
        winsys/null/radv_null_winsys.h \
        winsys/null/radv_null_winsys_public.h
 
+RADV_LAYER_SQTT_FILES := \
+       layers/radv_sqtt_layer.c
+
 VULKAN_FILES := \
        radv_cmd_buffer.c \
        radv_cs.h \
@@ -85,6 +88,7 @@ VULKAN_FILES := \
        radv_wsi.c \
        si_cmd_buffer.c \
        vk_format.h \
+       $(RADV_LAYER_SQTT_FILES) \
        $(RADV_WS_AMDGPU_FILES) \
        $(RADV_WS_NULL_FILES)
 
diff --git a/src/amd/vulkan/layers/radv_sqtt_layer.c b/src/amd/vulkan/layers/radv_sqtt_layer.c
new file mode 100644 (file)
index 0000000..18131cc
--- /dev/null
@@ -0,0 +1,342 @@
+/*
+ * Copyright © 2020 Valve Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "radv_private.h"
+
+/**
+ * Identifiers for RGP SQ thread-tracing markers (Table 1)
+ */
+enum rgp_sqtt_marker_identifier {
+       RGP_SQTT_MARKER_IDENTIFIER_EVENT                = 0x0,
+       RGP_SQTT_MARKER_IDENTIFIER_CB_START             = 0x1,
+       RGP_SQTT_MARKER_IDENTIFIER_CB_END               = 0x2,
+       RGP_SQTT_MARKER_IDENTIFIER_BARRIER_START        = 0x3,
+       RGP_SQTT_MARKER_IDENTIFIER_BARRIER_END          = 0x4,
+       RGP_SQTT_MARKER_IDENTIFIER_USER_EVENT           = 0x5,
+       RGP_SQTT_MARKER_IDENTIFIER_GENERAL_API          = 0x6,
+       RGP_SQTT_MARKER_IDENTIFIER_SYNC                 = 0x7,
+       RGP_SQTT_MARKER_IDENTIFIER_PRESENT              = 0x8,
+       RGP_SQTT_MARKER_IDENTIFIER_LAYOUT_TRANSITION    = 0x9,
+       RGP_SQTT_MARKER_IDENTIFIER_RENDER_PASS          = 0xA,
+       RGP_SQTT_MARKER_IDENTIFIER_RESERVED2            = 0xB,
+       RGP_SQTT_MARKER_IDENTIFIER_BIND_PIPELINE        = 0xC,
+       RGP_SQTT_MARKER_IDENTIFIER_RESERVED4            = 0xD,
+       RGP_SQTT_MARKER_IDENTIFIER_RESERVED5            = 0xE,
+       RGP_SQTT_MARKER_IDENTIFIER_RESERVED6            = 0xF
+};
+
+/**
+ * API types used in RGP SQ thread-tracing markers for the "General API"
+ * packet.
+ */
+enum rgp_sqtt_marker_general_api_type {
+       ApiCmdBindPipeline                     = 0,
+       ApiCmdBindDescriptorSets               = 1,
+       ApiCmdBindIndexBuffer                  = 2,
+       ApiCmdBindVertexBuffers                = 3,
+       ApiCmdDraw                             = 4,
+       ApiCmdDrawIndexed                      = 5,
+       ApiCmdDrawIndirect                     = 6,
+       ApiCmdDrawIndexedIndirect              = 7,
+       ApiCmdDrawIndirectCountAMD             = 8,
+       ApiCmdDrawIndexedIndirectCountAMD      = 9,
+       ApiCmdDispatch                         = 10,
+       ApiCmdDispatchIndirect                 = 11,
+       ApiCmdCopyBuffer                       = 12,
+       ApiCmdCopyImage                        = 13,
+       ApiCmdBlitImage                        = 14,
+       ApiCmdCopyBufferToImage                = 15,
+       ApiCmdCopyImageToBuffer                = 16,
+       ApiCmdUpdateBuffer                     = 17,
+       ApiCmdFillBuffer                       = 18,
+       ApiCmdClearColorImage                  = 19,
+       ApiCmdClearDepthStencilImage           = 20,
+       ApiCmdClearAttachments                 = 21,
+       ApiCmdResolveImage                     = 22,
+       ApiCmdWaitEvents                       = 23,
+       ApiCmdPipelineBarrier                  = 24,
+       ApiCmdBeginQuery                       = 25,
+       ApiCmdEndQuery                         = 26,
+       ApiCmdResetQueryPool                   = 27,
+       ApiCmdWriteTimestamp                   = 28,
+       ApiCmdCopyQueryPoolResults             = 29,
+       ApiCmdPushConstants                    = 30,
+       ApiCmdBeginRenderPass                  = 31,
+       ApiCmdNextSubpass                      = 32,
+       ApiCmdEndRenderPass                    = 33,
+       ApiCmdExecuteCommands                  = 34,
+       ApiCmdSetViewport                      = 35,
+       ApiCmdSetScissor                       = 36,
+       ApiCmdSetLineWidth                     = 37,
+       ApiCmdSetDepthBias                     = 38,
+       ApiCmdSetBlendConstants                = 39,
+       ApiCmdSetDepthBounds                   = 40,
+       ApiCmdSetStencilCompareMask            = 41,
+       ApiCmdSetStencilWriteMask              = 42,
+       ApiCmdSetStencilReference              = 43,
+       ApiCmdDrawIndirectCountKHR             = 44,
+       ApiCmdDrawIndexedIndirectCountKHR      = 45,
+       ApiInvalid                             = 0xffffffff
+};
+
+/**
+ * RGP SQ thread-tracing marker for a "General API" instrumentation packet.
+ */
+struct rgp_sqtt_marker_general_api {
+       union {
+               struct {
+                       uint32_t identifier : 4;
+                       uint32_t ext_dwords : 3;
+                       uint32_t api_type : 20;
+                       uint32_t is_end : 1;
+                       uint32_t reserved : 4;
+               };
+               uint32_t dword01;
+       };
+};
+
+static_assert(sizeof(struct rgp_sqtt_marker_general_api) == 4,
+             "rgp_sqtt_marker_general_api doesn't match RGP spec");
+
+static void
+radv_write_begin_general_api_marker(struct radv_cmd_buffer *cmd_buffer,
+                                   enum rgp_sqtt_marker_general_api_type api_type)
+{
+       struct rgp_sqtt_marker_general_api marker = {};
+       struct radeon_cmdbuf *cs = cmd_buffer->cs;
+
+       marker.identifier = RGP_SQTT_MARKER_IDENTIFIER_GENERAL_API;
+       marker.api_type = api_type;
+
+       radv_emit_thread_trace_userdata(cs, &marker, sizeof(marker) / 4);
+}
+
+static void
+radv_write_end_general_api_marker(struct radv_cmd_buffer *cmd_buffer,
+                                 enum rgp_sqtt_marker_general_api_type api_type)
+{
+       struct rgp_sqtt_marker_general_api marker = {};
+       struct radeon_cmdbuf *cs = cmd_buffer->cs;
+
+       marker.identifier = RGP_SQTT_MARKER_IDENTIFIER_GENERAL_API;
+       marker.api_type = api_type;
+       marker.is_end = 1;
+
+       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); \
+       radv_Cmd##cmd_name(args); \
+       radv_write_end_general_api_marker(cmd_buffer, ApiCmd##cmd_name);
+
+void sqtt_CmdBindPipeline(
+       VkCommandBuffer                             commandBuffer,
+       VkPipelineBindPoint                         pipelineBindPoint,
+       VkPipeline                                  pipeline)
+{
+       API_MARKER(BindPipeline, commandBuffer, pipelineBindPoint, pipeline);
+}
+
+void sqtt_CmdBindDescriptorSets(
+       VkCommandBuffer                             commandBuffer,
+       VkPipelineBindPoint                         pipelineBindPoint,
+       VkPipelineLayout                            layout,
+       uint32_t                                    firstSet,
+       uint32_t                                    descriptorSetCount,
+       const VkDescriptorSet*                      pDescriptorSets,
+       uint32_t                                    dynamicOffsetCount,
+       const uint32_t*                             pDynamicOffsets)
+{
+       API_MARKER(BindDescriptorSets, commandBuffer, pipelineBindPoint,
+                  layout, firstSet, descriptorSetCount,
+                  pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
+}
+
+void sqtt_CmdBindIndexBuffer(
+       VkCommandBuffer                             commandBuffer,
+       VkBuffer                                    buffer,
+       VkDeviceSize                                offset,
+       VkIndexType                                 indexType)
+{
+       API_MARKER(BindIndexBuffer, commandBuffer, buffer, offset, indexType);
+}
+
+void sqtt_CmdBindVertexBuffers(
+       VkCommandBuffer                             commandBuffer,
+       uint32_t                                    firstBinding,
+       uint32_t                                    bindingCount,
+       const VkBuffer*                             pBuffers,
+       const VkDeviceSize*                         pOffsets)
+{
+       API_MARKER(BindVertexBuffers, commandBuffer, firstBinding, bindingCount,
+                  pBuffers, pOffsets);
+}
+
+void sqtt_CmdBeginQuery(
+       VkCommandBuffer                             commandBuffer,
+       VkQueryPool                                 queryPool,
+       uint32_t                                    query,
+       VkQueryControlFlags                         flags)
+{
+       API_MARKER(BeginQuery, commandBuffer, queryPool, query, flags);
+}
+
+void sqtt_CmdEndQuery(
+       VkCommandBuffer                             commandBuffer,
+       VkQueryPool                                 queryPool,
+       uint32_t                                    query)
+{
+       API_MARKER(EndQuery, commandBuffer, queryPool, query);
+}
+
+void sqtt_CmdWriteTimestamp(
+       VkCommandBuffer                             commandBuffer,
+       VkPipelineStageFlagBits                     pipelineStage,
+       VkQueryPool                                 queryPool,
+       uint32_t                                    flags)
+{
+       API_MARKER(WriteTimestamp, commandBuffer, pipelineStage, queryPool, flags);
+}
+
+void sqtt_CmdPushConstants(
+       VkCommandBuffer                             commandBuffer,
+       VkPipelineLayout                            layout,
+       VkShaderStageFlags                          stageFlags,
+       uint32_t                                    offset,
+       uint32_t                                    size,
+       const void*                                 pValues)
+{
+       API_MARKER(PushConstants, commandBuffer, layout, stageFlags, offset,
+                  size, pValues);
+}
+
+void sqtt_CmdBeginRenderPass(
+       VkCommandBuffer                             commandBuffer,
+       const VkRenderPassBeginInfo*                pRenderPassBegin,
+       VkSubpassContents                           contents)
+{
+       API_MARKER(BeginRenderPass, commandBuffer, pRenderPassBegin, contents);
+}
+
+void sqtt_CmdNextSubpass(
+       VkCommandBuffer                             commandBuffer,
+       VkSubpassContents                           contents)
+{
+       API_MARKER(NextSubpass, commandBuffer, contents);
+}
+
+void sqtt_CmdEndRenderPass(
+       VkCommandBuffer                             commandBuffer)
+{
+       API_MARKER(EndRenderPass, commandBuffer);
+}
+
+void sqtt_CmdExecuteCommands(
+       VkCommandBuffer                             commandBuffer,
+       uint32_t                                    commandBufferCount,
+       const VkCommandBuffer*                      pCmdBuffers)
+{
+       API_MARKER(ExecuteCommands, commandBuffer, commandBufferCount,
+                  pCmdBuffers);
+}
+
+void sqtt_CmdSetViewport(
+       VkCommandBuffer                             commandBuffer,
+       uint32_t                                    firstViewport,
+       uint32_t                                    viewportCount,
+       const VkViewport*                           pViewports)
+{
+       API_MARKER(SetViewport, commandBuffer, firstViewport, viewportCount,
+                  pViewports);
+}
+
+void sqtt_CmdSetScissor(
+       VkCommandBuffer                             commandBuffer,
+       uint32_t                                    firstScissor,
+       uint32_t                                    scissorCount,
+       const VkRect2D*                             pScissors)
+{
+       API_MARKER(SetScissor, commandBuffer, firstScissor, scissorCount,
+                  pScissors);
+}
+
+void sqtt_CmdSetLineWidth(
+       VkCommandBuffer                             commandBuffer,
+       float                                       lineWidth)
+{
+       API_MARKER(SetLineWidth, commandBuffer, lineWidth);
+}
+
+void sqtt_CmdSetDepthBias(
+       VkCommandBuffer                             commandBuffer,
+       float                                       depthBiasConstantFactor,
+       float                                       depthBiasClamp,
+       float                                       depthBiasSlopeFactor)
+{
+       API_MARKER(SetDepthBias, commandBuffer, depthBiasConstantFactor,
+                  depthBiasClamp, depthBiasSlopeFactor);
+}
+
+void sqtt_CmdSetBlendConstants(
+       VkCommandBuffer                             commandBuffer,
+       const float                                 blendConstants[4])
+{
+       API_MARKER(SetBlendConstants, commandBuffer, blendConstants);
+}
+
+void sqtt_CmdSetDepthBounds(
+       VkCommandBuffer                             commandBuffer,
+       float                                       minDepthBounds,
+       float                                       maxDepthBounds)
+{
+       API_MARKER(SetDepthBounds, commandBuffer, minDepthBounds,
+                  maxDepthBounds);
+}
+
+void sqtt_CmdSetStencilCompareMask(
+       VkCommandBuffer                             commandBuffer,
+       VkStencilFaceFlags                          faceMask,
+       uint32_t                                    compareMask)
+{
+       API_MARKER(SetStencilCompareMask, commandBuffer, faceMask, compareMask);
+}
+
+void sqtt_CmdSetStencilWriteMask(
+       VkCommandBuffer                             commandBuffer,
+       VkStencilFaceFlags                          faceMask,
+       uint32_t                                    writeMask)
+{
+       API_MARKER(SetStencilWriteMask, commandBuffer, faceMask, writeMask);
+}
+
+void sqtt_CmdSetStencilReference(
+       VkCommandBuffer                             commandBuffer,
+       VkStencilFaceFlags                          faceMask,
+       uint32_t                                    reference)
+{
+       API_MARKER(SetStencilReference, commandBuffer, faceMask, reference);
+}
+
+#undef API_MARKER
index 6f89b433513fdeba92f9cf07bcb862c837782783..2a3df6803d5ce40e85df1e36d138cf7a8f542fe7 100644 (file)
@@ -58,6 +58,7 @@ radv_gfx10_format_table_h = custom_target(
 )
 
 libradv_files = files(
+  'layers/radv_sqtt_layer.c',
   'winsys/amdgpu/radv_amdgpu_bo.c',
   'winsys/amdgpu/radv_amdgpu_bo.h',
   'winsys/amdgpu/radv_amdgpu_cs.c',