Skip to content

Commit

Permalink
Add transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
solidpixel committed Dec 12, 2024
1 parent 829a39f commit 9446e54
Show file tree
Hide file tree
Showing 12 changed files with 937 additions and 56 deletions.
2 changes: 0 additions & 2 deletions layer_example/source/layer_device_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* ----------------------------------------------------------------------------
*/

#include <vulkan/vulkan.h>

#include "framework/utils.hpp"

/* See Vulkan API for documentation. */
Expand Down
1 change: 1 addition & 0 deletions layer_gpu_timeline/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ add_library(
layer_device_functions_queue.cpp
layer_device_functions_render_pass.cpp
layer_device_functions_trace_rays.cpp
layer_device_functions_transfer.cpp
timeline_comms.cpp)

target_include_directories(
Expand Down
120 changes: 120 additions & 0 deletions layer_gpu_timeline/source/layer_device_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,126 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysKHR<user_tag>(
uint32_t height,
uint32_t depth);


// Commands for transfers

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer<user_tag>(
VkCommandBuffer commandBuffer,
VkBuffer dstBuffer,
VkDeviceSize dstOffset,
VkDeviceSize size,
uint32_t data);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage<user_tag>(
VkCommandBuffer commandBuffer,
VkImage image,
VkImageLayout imageLayout,
const VkClearColorValue* pColor,
uint32_t rangeCount,
const VkImageSubresourceRange* pRanges);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage<user_tag>(
VkCommandBuffer commandBuffer,
VkImage image,
VkImageLayout imageLayout,
const VkClearDepthStencilValue* pDepthStencil,
uint32_t rangeCount,
const VkImageSubresourceRange* pRanges);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer<user_tag>(
VkCommandBuffer commandBuffer,
VkBuffer srcBuffer,
VkBuffer dstBuffer,
uint32_t regionCount,
const VkBufferCopy* pRegions);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2<user_tag>(
VkCommandBuffer commandBuffer,
const VkCopyBufferInfo2* pCopyBufferInfo);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR<user_tag>(
VkCommandBuffer commandBuffer,
const VkCopyBufferInfo2* pCopyBufferInfo);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage<user_tag>(
VkCommandBuffer commandBuffer,
VkBuffer srcBuffer,
VkImage dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkBufferImageCopy* pRegions);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2<user_tag>(
VkCommandBuffer commandBuffer,
const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2KHR<user_tag>(
VkCommandBuffer commandBuffer,
const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage<user_tag>(
VkCommandBuffer commandBuffer,
VkImage srcImage,
VkImageLayout srcImageLayout,
VkImage dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkImageCopy* pRegions);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2<user_tag>(
VkCommandBuffer commandBuffer,
const VkCopyImageInfo2* pCopyImageInfo);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR<user_tag>(
VkCommandBuffer commandBuffer,
const VkCopyImageInfo2* pCopyImageInfo);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer<user_tag>(
VkCommandBuffer commandBuffer,
VkImage srcImage,
VkImageLayout srcImageLayout,
VkBuffer dstBuffer,
uint32_t regionCount,
const VkBufferImageCopy* pRegions);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2<user_tag>(
VkCommandBuffer commandBuffer,
const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo);

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2KHR<user_tag>(
VkCommandBuffer commandBuffer,
const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo);

// Functions for debug

/* See Vulkan API for documentation. */
Expand Down
61 changes: 21 additions & 40 deletions layer_gpu_timeline/source/layer_device_functions_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ static uint64_t registerDispatch(
return cb.dispatch(groupX, groupY, groupZ);
}

static void emitStartTag(
Device* layer,
VkCommandBuffer commandBuffer,
uint64_t tagID
) {
// Emit the unique workload tag into the command stream
std::string tagLabel = formatString("t%" PRIu64, tagID);
VkDebugUtilsLabelEXT tagInfo {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
.pNext = nullptr,
.pLabelName = tagLabel.c_str(),
.color = { 0.0f, 0.0f, 0.0f, 0.0f }
};

layer->driver.vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &tagInfo);
}

/* See Vulkan API for documentation. */
template <>
VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch<user_tag>(
Expand All @@ -65,18 +82,9 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch<user_tag>(
static_cast<int64_t>(groupCountY),
static_cast<int64_t>(groupCountZ));

// Emit the unique workload tag into the command stream
std::string tagLabel = formatString("t%" PRIu64, tagID);
VkDebugUtilsLabelEXT tagInfo {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
.pNext = nullptr,
.pLabelName = tagLabel.c_str(),
.color = { 0.0f, 0.0f, 0.0f, 0.0f }
};

// Release the lock to call into the driver
lock.unlock();
layer->driver.vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &tagInfo);
emitStartTag(layer, commandBuffer, tagID);
layer->driver.vkCmdDispatch(commandBuffer, groupCountX, groupCountY, groupCountZ);
layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer);
}
Expand Down Expand Up @@ -105,18 +113,9 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBase<user_tag>(
static_cast<int64_t>(groupCountY),
static_cast<int64_t>(groupCountZ));

// Emit the unique workload tag into the command stream
std::string tagLabel = formatString("t%" PRIu64, tagID);
VkDebugUtilsLabelEXT tagInfo {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
.pNext = nullptr,
.pLabelName = tagLabel.c_str(),
.color = { 0.0f, 0.0f, 0.0f, 0.0f }
};

// Release the lock to call into the driver
lock.unlock();
layer->driver.vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &tagInfo);
emitStartTag(layer, commandBuffer, tagID);
layer->driver.vkCmdDispatchBase(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ);
layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer);
}
Expand Down Expand Up @@ -145,18 +144,9 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBaseKHR<user_tag>(
static_cast<int64_t>(groupCountY),
static_cast<int64_t>(groupCountZ));

// Emit the unique workload tag into the command stream
std::string tagLabel = formatString("t%" PRIu64, tagID);
VkDebugUtilsLabelEXT tagInfo {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
.pNext = nullptr,
.pLabelName = tagLabel.c_str(),
.color = { 0.0f, 0.0f, 0.0f, 0.0f }
};

// Release the lock to call into the driver
lock.unlock();
layer->driver.vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &tagInfo);
emitStartTag(layer, commandBuffer, tagID);
layer->driver.vkCmdDispatchBaseKHR(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ);
layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer);
}
Expand All @@ -176,18 +166,9 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchIndirect<user_tag>(

uint64_t tagID = registerDispatch(layer, commandBuffer, -1, -1, -1);

// Emit the unique workload tag into the command stream
std::string tagLabel = formatString("t%" PRIu64, tagID);
VkDebugUtilsLabelEXT tagInfo {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
.pNext = nullptr,
.pLabelName = tagLabel.c_str(),
.color = { 0.0f, 0.0f, 0.0f, 0.0f }
};

// Release the lock to call into the driver
lock.unlock();
layer->driver.vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &tagInfo);
emitStartTag(layer, commandBuffer, tagID);
layer->driver.vkCmdDispatchIndirect(commandBuffer, buffer, offset);
layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer);
}
40 changes: 32 additions & 8 deletions layer_gpu_timeline/source/layer_device_functions_trace_rays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,33 @@

extern std::mutex g_vulkanLock;

static void registerTraceRays(
static uint64_t registerTraceRays(
Device* layer,
VkCommandBuffer commandBuffer
VkCommandBuffer commandBuffer,
int64_t itemsX,
int64_t itemsY,
int64_t itemsZ
) {
auto& tracker = layer->getStateTracker();
auto& cb = tracker.getCommandBuffer(commandBuffer);
return cb.traceRays(itemsX, itemsY, itemsZ);
}

static void emitStartTag(
Device* layer,
VkCommandBuffer commandBuffer,
uint64_t tagID
) {
auto& state = layer->getStateTracker();
auto& stats = state.getCommandBuffer(commandBuffer).getStats();
stats.incTraceRaysCount();
// Emit the unique workload tag into the command stream
std::string tagLabel = formatString("t%" PRIu64, tagID);
VkDebugUtilsLabelEXT tagInfo {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
.pNext = nullptr,
.pLabelName = tagLabel.c_str(),
.color = { 0.0f, 0.0f, 0.0f, 0.0f }
};

layer->driver.vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &tagInfo);
}

/* See Vulkan API for documentation. */
Expand All @@ -53,11 +73,13 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR<user_tag>(
std::unique_lock<std::mutex> lock { g_vulkanLock };
auto* layer = Device::retrieve(commandBuffer);

registerTraceRays(layer, commandBuffer);
uint64_t tagID = registerTraceRays(layer, commandBuffer, -1, -1, -1);

// Release the lock to call into the driver
lock.unlock();
emitStartTag(layer, commandBuffer, tagID);
layer->driver.vkCmdTraceRaysIndirect2KHR(commandBuffer, indirectDeviceAddress);
layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer);
}

/* See Vulkan API for documentation. */
Expand All @@ -76,10 +98,11 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirectKHR<user_tag>(
std::unique_lock<std::mutex> lock { g_vulkanLock };
auto* layer = Device::retrieve(commandBuffer);

registerTraceRays(layer, commandBuffer);
uint64_t tagID = registerTraceRays(layer, commandBuffer, -1, -1, -1);

// Release the lock to call into the driver
lock.unlock();
emitStartTag(layer, commandBuffer, tagID);
layer->driver.vkCmdTraceRaysIndirectKHR(commandBuffer, pRaygenShaderBindingTable, pMissShaderBindingTable, pHitShaderBindingTable, pCallableShaderBindingTable, indirectDeviceAddress);
}

Expand All @@ -101,9 +124,10 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysKHR<user_tag>(
std::unique_lock<std::mutex> lock { g_vulkanLock };
auto* layer = Device::retrieve(commandBuffer);

registerTraceRays(layer, commandBuffer);
uint64_t tagID = registerTraceRays(layer, commandBuffer, width, height, depth);

// Release the lock to call into the driver
lock.unlock();
emitStartTag(layer, commandBuffer, tagID);
layer->driver.vkCmdTraceRaysKHR(commandBuffer, pRaygenShaderBindingTable, pMissShaderBindingTable, pHitShaderBindingTable, pCallableShaderBindingTable, width, height, depth);
}
Loading

0 comments on commit 9446e54

Please sign in to comment.