Skip to content

Commit

Permalink
Create render pass metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
solidpixel committed Dec 5, 2024
1 parent 4d37b69 commit 46e146f
Show file tree
Hide file tree
Showing 11 changed files with 732 additions and 33 deletions.
4 changes: 2 additions & 2 deletions layer_gpu_timeline/source/layer_device_functions_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerBeginEXT<user_tag>(

// Note that we do not call the driver for user labels - they are
// emitted via the comms side-channel for each workload to avoid
// polluting the driver tag labelling
// polluting the layer's use of the driver for tag labelling
}

/* See Vulkan API for documentation. */
Expand All @@ -74,5 +74,5 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerEndEXT<user_tag>(

// Note that we do not call the driver for user labels - they are
// emitted via the comms side-channel for each workload to avoid
// polluting the driver tag labelling
// polluting the layer's use of the driver for tag labelling
}
75 changes: 67 additions & 8 deletions layer_gpu_timeline/source/layer_device_functions_render_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

#include "device.hpp"
#include "layer_device_functions.hpp"

#include "framework/utils.hpp"
#include "trackers/render_pass.hpp"

extern std::mutex g_vulkanLock;

Expand All @@ -49,7 +51,17 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass<user_tag>(

// Release the lock to call into the driver
lock.unlock();
return layer->driver.vkCreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
VkResult ret = layer->driver.vkCreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
if (ret != VK_SUCCESS)
{
return ret;
}

// Retake the lock to access layer-wide global store
lock.lock();
auto& tracker = layer->getStateTracker();
tracker.createRenderPass(*pRenderPass, *pCreateInfo);
return VK_SUCCESS;
}

/* See Vulkan API for documentation. */
Expand All @@ -68,7 +80,17 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2<user_tag>(

// Release the lock to call into the driver
lock.unlock();
return layer->driver.vkCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass);
VkResult ret = layer->driver.vkCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass);
if (ret != VK_SUCCESS)
{
return ret;
}

// Retake the lock to access layer-wide global store
lock.lock();
auto& tracker = layer->getStateTracker();
tracker.createRenderPass(*pRenderPass, *pCreateInfo);
return VK_SUCCESS;
}

/* See Vulkan API for documentation. */
Expand All @@ -87,7 +109,17 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2KHR<user_tag>(

// Release the lock to call into the driver
lock.unlock();
return layer->driver.vkCreateRenderPass2KHR(device, pCreateInfo, pAllocator, pRenderPass);
VkResult ret = layer->driver.vkCreateRenderPass2KHR(device, pCreateInfo, pAllocator, pRenderPass);
if (ret != VK_SUCCESS)
{
return ret;
}

// Retake the lock to access layer-wide global store
lock.lock();
auto& tracker = layer->getStateTracker();
tracker.createRenderPass(*pRenderPass, *pCreateInfo);
return VK_SUCCESS;
}

/* See Vulkan API for documentation. */
Expand All @@ -103,6 +135,9 @@ VKAPI_ATTR void VKAPI_CALL layer_vkDestroyRenderPass<user_tag>(
std::unique_lock<std::mutex> lock { g_vulkanLock };
auto* layer = Device::retrieve(device);

auto& tracker = layer->getStateTracker();
tracker.destroyRenderPass(renderPass);

// Release the lock to call into the driver
lock.unlock();
layer->driver.vkDestroyRenderPass(device, renderPass, pAllocator);
Expand All @@ -124,8 +159,12 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass<user_tag>(
auto& tracker = layer->getStateTracker();
auto& cb = tracker.getCommandBuffer(commandBuffer);

auto& rp = tracker.getRenderPass(pRenderPassBegin->renderPass);
uint32_t width = pRenderPassBegin->renderArea.extent.width;
uint32_t height = pRenderPassBegin->renderArea.extent.height;

// Notify the command buffer we are starting a new render pass
uint64_t tagID = cb.renderPassBegin();
uint64_t tagID = cb.renderPassBegin(rp, width, height);

// Emit the unique workload tag into the command stream
std::string tagLabel = formatString("t%" PRIu64, tagID);
Expand Down Expand Up @@ -158,8 +197,12 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2<user_tag>(
auto& tracker = layer->getStateTracker();
auto& cb = tracker.getCommandBuffer(commandBuffer);

auto& rp = tracker.getRenderPass(pRenderPassBegin->renderPass);
uint32_t width = pRenderPassBegin->renderArea.extent.width;
uint32_t height = pRenderPassBegin->renderArea.extent.height;

// Notify the command buffer we are starting a new render pass
uint64_t tagID = cb.renderPassBegin();
uint64_t tagID = cb.renderPassBegin(rp, width, height);

// Emit the unique workload tag into the command stream
std::string tagLabel = formatString("t%" PRIu64, tagID);
Expand Down Expand Up @@ -192,8 +235,12 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR<user_tag>(
auto& tracker = layer->getStateTracker();
auto& cb = tracker.getCommandBuffer(commandBuffer);

auto& rp = tracker.getRenderPass(pRenderPassBegin->renderPass);
uint32_t width = pRenderPassBegin->renderArea.extent.width;
uint32_t height = pRenderPassBegin->renderArea.extent.height;

// Notify the command buffer we are starting a new render pass
uint64_t tagID = cb.renderPassBegin();
uint64_t tagID = cb.renderPassBegin(rp, width, height);

// Emit the unique workload tag into the command stream
std::string tagLabel = formatString("t%" PRIu64, tagID);
Expand Down Expand Up @@ -228,8 +275,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering<user_tag>(
bool resuming = pRenderingInfo->flags & VK_RENDERING_RESUMING_BIT;
bool suspending = pRenderingInfo->flags & VK_RENDERING_SUSPENDING_BIT;

// Extract metadata for later use ...
Tracker::RenderPass rp(*pRenderingInfo);
uint32_t width = pRenderingInfo->renderArea.extent.width;
uint32_t height = pRenderingInfo->renderArea.extent.height;

// Notify the command buffer we are starting a new render pass
uint64_t tagID = cb.renderPassBegin(resuming, suspending);
uint64_t tagID = cb.renderPassBegin(
rp, width, height, resuming, suspending);

// Release the lock to call into the driver
lock.unlock();
Expand Down Expand Up @@ -270,8 +323,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR<user_tag>(
bool resuming = pRenderingInfo->flags & VK_RENDERING_RESUMING_BIT;
bool suspending = pRenderingInfo->flags & VK_RENDERING_SUSPENDING_BIT;

// Extract metadata for later use ...
Tracker::RenderPass rp(*pRenderingInfo);
uint32_t width = pRenderingInfo->renderArea.extent.width;
uint32_t height = pRenderingInfo->renderArea.extent.height;

// Notify the command buffer we are starting a new render pass
uint64_t tagID = cb.renderPassBegin(resuming, suspending);
uint64_t tagID = cb.renderPassBegin(
rp, width, height, resuming, suspending);

// Release the lock to call into the driver
lock.unlock();
Expand Down
3 changes: 2 additions & 1 deletion source_common/trackers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ add_library(
command_buffer.cpp
device.cpp
layer_command_stream.cpp
queue.cpp)
queue.cpp
render_pass.cpp)

target_include_directories(
${LIB_BINARY} PRIVATE
Expand Down
6 changes: 4 additions & 2 deletions source_common/trackers/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ void CommandBuffer::debugMarkerEnd()
* @brief End a user render pass.
*/
uint64_t CommandBuffer::renderPassBegin(
const RenderPass& renderPass,
uint32_t width,
uint32_t height,
bool resuming,
bool suspending
) {
Expand All @@ -91,8 +94,7 @@ uint64_t CommandBuffer::renderPassBegin(

// TODO: Populate render pass with config information
auto workload = std::make_shared<LCSRenderPass>(
tagID,
suspending);
tagID, renderPass, width, height, suspending);
workloads.push_back(workload);

auto instr = std::make_pair(LCSOpcode::RENDERPASS_BEGIN, workload);
Expand Down
6 changes: 6 additions & 0 deletions source_common/trackers/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,19 @@ class CommandBuffer
/**
* @brief Begin recording a render pass.
*
* @param renderPass Render pass creation info.
* @param width Render pass extent width in pixels.
* @param height Render pass extent height in pixels.
* @param resuming If @c true this recording starts with a resume.
* @param suspending If @c true this recording ends with a suspend.
*
* @return Returns the tagID assigned to this workload. Always returns 0
* if @c resuming an existing workload.
*/
uint64_t renderPassBegin(
const RenderPass& renderPass,
uint32_t width,
uint32_t height,
bool resuming=false,
bool suspending=false);

Expand Down
43 changes: 40 additions & 3 deletions source_common/trackers/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ CommandPool& Device::getCommandPool(
return *commandPools.at(commandPool);
}

/* See header for documentation. */
void Device::destroyCommandPool(
VkCommandPool commandPool
) {
commandPools.erase(commandPool);
}

/* See header for documentation. */
void Device::allocateCommandBuffer(
VkCommandPool commandPool,
Expand Down Expand Up @@ -93,10 +100,40 @@ CommandBuffer& Device::getCommandBuffer(
}

/* See header for documentation. */
void Device::destroyCommandPool(
VkCommandPool commandPool
void Device::createRenderPass(
VkRenderPass renderPass,
const VkRenderPassCreateInfo& createInfo
) {
commandPools.erase(commandPool);
renderPasses.insert({
renderPass,
std::make_unique<RenderPass>(renderPass, createInfo)
});
}

/* See header for documentation. */
void Device::createRenderPass(
VkRenderPass renderPass,
const VkRenderPassCreateInfo2& createInfo
) {
renderPasses.insert({
renderPass,
std::make_unique<RenderPass>(renderPass, createInfo)
});
}

/* See header for documentation. */
RenderPass& Device::getRenderPass(
VkRenderPass renderPass
) {
assert(isInMap(renderPass, renderPasses));
return *renderPasses.at(renderPass);
}

/* See header for documentation. */
void Device::destroyRenderPass(
VkRenderPass renderPass
) {
renderPasses.erase(renderPass);
}

/* See header for documentation. */
Expand Down
Loading

0 comments on commit 46e146f

Please sign in to comment.