diff --git a/layer_gpu_timeline/source/layer_device_functions_trace_rays.cpp b/layer_gpu_timeline/source/layer_device_functions_trace_rays.cpp index d453a29..e6df5e3 100644 --- a/layer_gpu_timeline/source/layer_device_functions_trace_rays.cpp +++ b/layer_gpu_timeline/source/layer_device_functions_trace_rays.cpp @@ -99,6 +99,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirectKHR( lock.unlock(); emitStartTag(layer, commandBuffer, tagID); layer->driver.vkCmdTraceRaysIndirectKHR(commandBuffer, pRaygenShaderBindingTable, pMissShaderBindingTable, pHitShaderBindingTable, pCallableShaderBindingTable, indirectDeviceAddress); + layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer); } /* See Vulkan API for documentation. */ @@ -125,4 +126,5 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysKHR( lock.unlock(); emitStartTag(layer, commandBuffer, tagID); layer->driver.vkCmdTraceRaysKHR(commandBuffer, pRaygenShaderBindingTable, pMissShaderBindingTable, pHitShaderBindingTable, pCallableShaderBindingTable, width, height, depth); + layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer); } \ No newline at end of file diff --git a/source_common/trackers/layer_command_stream.cpp b/source_common/trackers/layer_command_stream.cpp index e3df7d8..3a54bc0 100644 --- a/source_common/trackers/layer_command_stream.cpp +++ b/source_common/trackers/layer_command_stream.cpp @@ -75,8 +75,7 @@ LCSRenderPass::LCSRenderPass( /* See header for details. */ std::string LCSRenderPass::getBeginMetadata( - const std::string* debugLabel, - uint64_t submitID) const + const std::string* debugLabel) const { // Draw count for a multi-submit command buffer cannot be reliably // associated with a single tagID if restartable across command buffer @@ -96,11 +95,6 @@ std::string LCSRenderPass::getBeginMetadata( { "drawCallCount", drawCount } }; - if (submitID != 0) - { - metadata["sid"] = submitID; - } - if (debugLabel && debugLabel->size()) { metadata["label"] = *debugLabel; @@ -147,8 +141,7 @@ std::string LCSRenderPass::getBeginMetadata( /* See header for details. */ std::string LCSRenderPass::getContinuationMetadata( const std::string* debugLabel, - uint64_t tagIDContinuation, - uint64_t submitID) const + uint64_t tagIDContinuation) const { json metadata = { { "type", "renderpass" }, @@ -161,28 +154,22 @@ std::string LCSRenderPass::getContinuationMetadata( metadata["label"] = *debugLabel; } - if (submitID != 0) - { - metadata["sid"] = submitID; - } - return metadata.dump(); } /* See header for details. */ std::string LCSRenderPass::getMetadata( const std::string* debugLabel, - uint64_t tagIDContinuation, - uint64_t submitID) const + uint64_t tagIDContinuation) const { if (tagID) { assert(tagIDContinuation == 0); - return getBeginMetadata(debugLabel, submitID); + return getBeginMetadata(debugLabel); } assert(tagIDContinuation != 0); - return getContinuationMetadata(debugLabel, tagIDContinuation, submitID); + return getContinuationMetadata(debugLabel, tagIDContinuation); } /* See header for details. */ @@ -203,11 +190,9 @@ LCSDispatch::LCSDispatch( /* See header for details. */ std::string LCSDispatch::getMetadata( const std::string* debugLabel, - uint64_t tagIDContinuation, - uint64_t submitID + uint64_t tagIDContinuation ) const { UNUSED(tagIDContinuation); - UNUSED(submitID); json metadata = { { "type", "dispatch" }, @@ -243,11 +228,9 @@ LCSTraceRays::LCSTraceRays( /* See header for details. */ std::string LCSTraceRays::getMetadata( const std::string* debugLabel, - uint64_t tagIDContinuation, - uint64_t submitID + uint64_t tagIDContinuation ) const { UNUSED(tagIDContinuation); - UNUSED(submitID); json metadata = { { "type", "tracerays" }, @@ -281,11 +264,9 @@ LCSImageTransfer::LCSImageTransfer( /* See header for details. */ std::string LCSImageTransfer::getMetadata( const std::string* debugLabel, - uint64_t tagIDContinuation, - uint64_t submitID + uint64_t tagIDContinuation ) const { UNUSED(tagIDContinuation); - UNUSED(submitID); json metadata = { { "type", "imagetransfer" }, @@ -318,11 +299,9 @@ LCSBufferTransfer::LCSBufferTransfer( /* See header for details. */ std::string LCSBufferTransfer::getMetadata( const std::string* debugLabel, - uint64_t tagIDContinuation, - uint64_t submitID + uint64_t tagIDContinuation ) const { UNUSED(tagIDContinuation); - UNUSED(submitID); json metadata = { { "type", "buffertransfer" }, diff --git a/source_common/trackers/layer_command_stream.hpp b/source_common/trackers/layer_command_stream.hpp index 29acdd6..ac9a331 100644 --- a/source_common/trackers/layer_command_stream.hpp +++ b/source_common/trackers/layer_command_stream.hpp @@ -25,20 +25,15 @@ /** * \file - * The declaration of Vulkan command pool and command buffer use trackers. + * The declaration of a replayable layer command stream. * * Role summary * ============s * - * These trackers are used to monitor the use of command buffers in a frame, - * allowing us to monitor command buffer payloads submitted to a queue. - * - * Key properties - * ============== - * - * Command pools and Command buffers are both lock-free from a single app - * thread, relying on external synchronization above the API if multi-threaded - * use is required. + * These trackers are used to monitor to submission of workloads inside a + * command buffers in a way that they can be iterated by a queue tracker at + * submit time, allowing us to associate workloads with per-queue state such + * as the dynamic debug label stack. */ #pragma once @@ -46,13 +41,11 @@ #include #include #include -#include #include #include #include #include "trackers/render_pass.hpp" -#include "trackers/stats.hpp" #include "utils/misc.hpp" namespace Tracker @@ -73,23 +66,36 @@ enum class LCSOpcode }; /** - * @brief Baseclass representing a GPU workload in the command stream. + * @brief Base class representing a GPU workload in the command stream. */ class LCSWorkload { public: + /** + * @brief Create a new workload. + * + * @param tagID The assigned tagID. + */ LCSWorkload( uint64_t tagID); + /** + * @brief Destroy a workload. + */ virtual ~LCSWorkload() = default; + /** + * @brief Get the metadata for this workload + * + * @param debugLabel The debug label state of the VkQueue at submit time. + * @param tagIDContinuation The ID of the workload if this is a continuation of it. + */ virtual std::string getMetadata( const std::string* debugLabel=nullptr, - uint64_t tagIDContinuation=0, - uint64_t submitID=0) const = 0; + uint64_t tagIDContinuation=0) const = 0; /** - * @brief Get this workloads tagID. + * @brief Get this workload's tagID. * * @return The assigned ID. */ @@ -124,11 +130,21 @@ class LCSWorkload }; /** - * @brief Baseclass representing a GPU workload in the command stream. + * @brief Class representing a render pass workload in the command stream. */ class LCSRenderPass : public LCSWorkload { public: + /** + * @brief Create a new workload representing a single render pass. + * + * @param tagID The assigned tagID. + * @param renderPass The render pass creation information. + * @param width The width of this submit in pixels. + * @param height The height of this submit in pixels. + * @param suspending Is this a render pass part that suspends later? + * @param oneTimeSubmit Is this recorded into a one-time-submit command buffer? + */ LCSRenderPass( uint64_t tagID, const RenderPass& renderPass, @@ -137,167 +153,313 @@ class LCSRenderPass : public LCSWorkload bool suspending, bool oneTimeSubmit); + /** + * @brief Destroy a workload. + */ virtual ~LCSRenderPass() = default; + /** + * @brief Is this a suspending render pass? + * + * @return @c true if this instance suspends rather than ends. + */ bool isSuspending() const { return suspending; }; + /** + * @brief Update this workload with the final draw count. + * + * @param count The number of draw calls tracked by the command buffer. + */ void setDrawCallCount(uint64_t count) { drawCallCount = count; }; + /* See base class for documentation. */ virtual std::string getMetadata( const std::string* debugLabel=nullptr, - uint64_t tagIDContinuation=0, - uint64_t submitID=0) const; + uint64_t tagIDContinuation=0) const; private: + /** + * @brief Get the metadata for this workload if beginning a new render pass. + * + * @param debugLabel The debug label state of the VkQueue at submit time. + */ std::string getBeginMetadata( - const std::string* debugLabel=nullptr, - uint64_t submitID=0) const; + const std::string* debugLabel=nullptr) const; + /** + * @brief Get the metadata for this workload if continuing an existing render pass. + * + * @param debugLabel The debug label state of the VkQueue at submit time. + * @param tagIDContinuation The ID of the workload if this is a continuation of it. + */ std::string getContinuationMetadata( const std::string* debugLabel=nullptr, - uint64_t tagIDContinuation=0, - uint64_t submitID=0) const; + uint64_t tagIDContinuation=0) const; + /** + * @brief Width of this workload, in pixels. + */ uint32_t width; + /** + * @brief Height of this workload, in pixels. + */ uint32_t height; + /** + * @brief Is this workload suspending rather than ending? + */ bool suspending; + /** + * @brief Is this workload in a one-time-submit command buffer? + */ bool oneTimeSubmit; + /** + * @brief The number of subpasses in the render pass. + */ uint32_t subpassCount; + /** + * @brief The number of draw calls in the render pass. + * + * Note: This is updated by ther command buffer tracker when the render + * pass is suspended or ended. + */ uint64_t drawCallCount { 0 }; + /** + * @brief The attachments for this render pass. + */ std::vector attachments; }; /** - * @brief Baseclass representing a GPU workload in the command stream. + * @brief Class representing a compute dispatch workload in the command stream. */ class LCSDispatch : public LCSWorkload { public: + /** + * @brief Create a new dispatch workload. + * + * Workloads of unknown dimension (e.g. if indirect) should use -1. + * + * @param tagID The assigned tagID. + * @param xGroups The number of work groups in the X dimension. + * @param yGroups The number of work groups in the Y dimension. + * @param zGroups The number of work groups in the Z dimension. + */ LCSDispatch( uint64_t tagID, int64_t xGroups, int64_t yGroups, int64_t zGroups); + /** + * @brief Destroy a workload. + */ virtual ~LCSDispatch() = default; + /* See base class for documentation. */ virtual std::string getMetadata( const std::string* debugLabel=nullptr, - uint64_t tagIDContinuation=0, - uint64_t submitID=0) const; + uint64_t tagIDContinuation=0) const; private: + /** + * @brief The number of work groups in the X dimension, or -1 if unknown. + */ int64_t xGroups; + + /** + * @brief The number of work groups in the Y dimension, or -1 if unknown. + */ int64_t yGroups; + + /** + * @brief The number of work groups in the Z dimension, or -1 if unknown. + */ int64_t zGroups; }; /** - * @brief Baseclass representing a GPU workload in the command stream. + * @brief Class representing a trace rays workload in the command stream. */ class LCSTraceRays : public LCSWorkload { public: + /** + * @brief Create a new trace rays workload. + * + * Workloads of unknown dimension (e.g. if indirect) should use -1. + * + * @param tagID The assigned tagID. + * @param xItems The number of work items in the X dimension. + * @param yItems The number of work items in the Y dimension. + * @param zItems The number of work items in the Z dimension. + */ LCSTraceRays( uint64_t tagID, int64_t xItems, int64_t yItems, int64_t zItems); + /** + * @brief Destroy a workload. + */ virtual ~LCSTraceRays() = default; + /* See base class for documentation. */ virtual std::string getMetadata( const std::string* debugLabel=nullptr, - uint64_t tagIDContinuation=0, - uint64_t submitID=0) const; + uint64_t tagIDContinuation=0) const; private: + /** + * @brief The number of work items in the X dimension, or -1 if unknown. + */ int64_t xItems; + + /** + * @brief The number of work items in the Y dimension, or -1 if unknown. + */ int64_t yItems; + + /** + * @brief The number of work items in the Z dimension, or -1 if unknown. + */ int64_t zItems; }; /** - * @brief Baseclass representing a GPU workload in the command stream. + * @brief Class representing an image transfer workload in the command stream. */ class LCSImageTransfer : public LCSWorkload { public: + /** + * @brief Create a new image transfer workload. + * + * Workloads of unknown dimension should use @c pixelCount of -1. + * + * @param tagID The assigned tagID. + * @param transferType The subtype of the transfer. + * @param pixelCount The size of the transfer, in pixels. + */ LCSImageTransfer( uint64_t tagID, const std::string& transferType, int64_t pixelCount); + /** + * @brief Destroy a workload. + */ virtual ~LCSImageTransfer() = default; + /* See base class for documentation. */ virtual std::string getMetadata( const std::string* debugLabel=nullptr, - uint64_t tagIDContinuation=0, - uint64_t submitID=0) const; + uint64_t tagIDContinuation=0) const; private: + /** + * @brief The subtype of the transfer. + */ std::string transferType; + + /** + * @brief The number of pixels transferred, or -1 if unknown. + */ int64_t pixelCount; }; /** - * @brief Baseclass representing a GPU workload in the command stream. + * @brief Class representing a buffer transfer workload in the command stream. */ class LCSBufferTransfer : public LCSWorkload { public: + /** + * @brief Create a new buffer transfer workload. + * + * Workloads of unknown dimension should use @c byteCount of -1. Workloads + * using symbolic "whole buffer" dimension should use @c byteCount of -2. + * + * @param tagID The assigned tagID. + * @param transferType The subtype of the transfer. + * @param byteCount The size of the transfer, in bytes. + */ LCSBufferTransfer( uint64_t tagID, const std::string& transferType, int64_t byteCount); + /** + * @brief Destroy a workload. + */ virtual ~LCSBufferTransfer() = default; + /* See base class for documentation. */ virtual std::string getMetadata( const std::string* debugLabel=nullptr, - uint64_t tagIDContinuation=0, - uint64_t submitID=0) const; + uint64_t tagIDContinuation=0) const; private: + /** + * @brief The subtype of the transfer. + */ std::string transferType; + + /** + * @brief The number of bytes transferred, -1 if unknown, -2 if whole buffer. + */ int64_t byteCount; }; /** - * @brief Baseclass representing a GPU workload in the command stream. + * @brief Class representing a marker workload in the command stream. + * + * Note there is no class for a marker end, as is has no payload and can use + * just the opcode to indicate behavior. */ class LCSMarker : public LCSWorkload { public: + /** + * @brief Create a new debug marker workload. + * + * @param label The application debug label. + */ LCSMarker( const std::string& label); + /** + * @brief Destroy a workload. + */ virtual ~LCSMarker() = default; + /* See base class for documentation. */ virtual std::string getMetadata( const std::string* debugLabel=nullptr, - uint64_t tagIDContinuation=0, - uint64_t submitID=0) const + uint64_t tagIDContinuation=0) const { UNUSED(debugLabel); UNUSED(tagIDContinuation); - UNUSED(submitID); return label; }; private: + /** + * @brief The application debug label. + */ std::string label; }; diff --git a/source_common/trackers/queue.cpp b/source_common/trackers/queue.cpp index 7b79606..e9a57d2 100644 --- a/source_common/trackers/queue.cpp +++ b/source_common/trackers/queue.cpp @@ -29,13 +29,14 @@ namespace Tracker { -/* See header for details. */ -std::atomic Queue::nextSubmitID { 1 }; - /* See header for details. */ Queue::Queue( - VkQueue _handle): - handle(_handle) { }; + VkQueue _handle +): + handle(_handle) +{ + +}; /* See header for details. */ void Queue::runSubmitCommandStream( diff --git a/source_common/trackers/queue.hpp b/source_common/trackers/queue.hpp index b57a07b..7f39b05 100644 --- a/source_common/trackers/queue.hpp +++ b/source_common/trackers/queue.hpp @@ -72,16 +72,6 @@ class Queue const std::vector& stream, std::function callback); - /** - * @brief Get a unique submitID to label a command buffer submit. - * - * @return The assigned ID. - */ - static uint64_t assignSubmitID() - { - return nextSubmitID.fetch_add(1, std::memory_order_relaxed); - } - private: /** * The handle of the native queue we are wrapping. @@ -97,11 +87,6 @@ class Queue * @brief The last non-zero render pass tagID submitted. */ uint64_t lastRenderPassTagID { 0 }; - - /** - * @brief The command buffer submitID allocator. - */ - static std::atomic nextSubmitID; }; }