Skip to content

Commit

Permalink
rendervulkan: tracy gpu profiling: fix segfault & other issues that w…
Browse files Browse the repository at this point in the history
…ere preventing the gpu zones from working
  • Loading branch information
sharkautarch committed Jul 14, 2024
1 parent c0afa3d commit b321aac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,14 +1200,16 @@ inline std::unique_ptr<CVulkanCmdBuffer> __attribute__((hot,visibility("internal
{
auto finalize_buf = [this, &loc]<bool bIsRecycled>(std::unique_ptr<CVulkanCmdBuffer> cmdBuf) {
//using this lambda allows for Return Value Optimization w/o duplicating code
if constexpr (bIsRecycled)
if constexpr (bIsRecycled) {
m_unusedCmdBufs.pop_back();

}
cmdBuf->begin();

#ifdef TRACY_ENABLE

static constinit tracy::SourceLocationData source_data{};
assert( !cmdBuf->gpuZoneHolder() );
auto source_data = tracy::SourceLocationData(loc.function_name(), loc.function_name(), loc.file_name(), loc.line());
source_data = tracy::SourceLocationData(loc.function_name(), loc.function_name(), loc.file_name(), loc.line());

//we don't need to worry about dangling pointer to source_data,
//the gpu zone object held in gpuZoneHolder will only touch the pointer during its construction w/ emplace()
Expand Down Expand Up @@ -1347,7 +1349,11 @@ CVulkanCmdBuffer::CVulkanCmdBuffer(CVulkanDevice *parent, VkCommandBuffer cmdBuf
CVulkanCmdBuffer::~CVulkanCmdBuffer()
{
#ifdef TRACY_ENABLE
TracyVkDestroy(m_tracyCtx);
vk_log.infof("~CVulkanCmdBuffer()");
if (m_tracyCtx) {
TracyVkDestroy(m_tracyCtx);
m_tracyCtx=nullptr;
}
#endif

m_device->vk.FreeCommandBuffers(m_device->device(), m_device->commandPool(), 1, &m_cmdBuffer);
Expand All @@ -1358,9 +1364,6 @@ void CVulkanCmdBuffer::reset()
vk_check( m_device->vk.ResetCommandBuffer(m_cmdBuffer, 0) );
m_textureRefs.clear();
m_textureState.clear();
#ifdef TRACY_ENABLE
m_gpuZoneHolder.reset();
#endif
}

void CVulkanCmdBuffer::begin()
Expand All @@ -1380,6 +1383,7 @@ void CVulkanCmdBuffer::end()
insertBarrier(true);
#ifdef TRACY_ENABLE
TracyVkCollect(m_tracyCtx, m_cmdBuffer);
m_gpuZoneHolder.reset();
#endif
vk_check( m_device->vk.EndCommandBuffer(m_cmdBuffer) );
}
Expand Down
5 changes: 4 additions & 1 deletion src/rendervulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,10 @@ class CVulkanCmdBuffer
friend class CVulkanDevice;
#ifdef TRACY_ENABLE
inline std::optional<tracy::VkCtxScope>& gpuZoneHolder() {return m_gpuZoneHolder;}
inline tracy::VkCtx* tracyCtx() {return m_tracyCtx;}
inline tracy::VkCtx*& tracyCtx() {return m_tracyCtx;}
inline tracy::VkCtx* popCtx() {
return std::exchange(m_tracyCtx, nullptr);
}
#endif

private:
Expand Down

0 comments on commit b321aac

Please sign in to comment.