diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index 97324f6437..d5ccde1e14 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp @@ -1200,14 +1200,16 @@ inline std::unique_ptr __attribute__((hot,visibility("internal { auto finalize_buf = [this, &loc](std::unique_ptr 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() @@ -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); @@ -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() @@ -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) ); } diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp index 0bbd965986..86762665aa 100644 --- a/src/rendervulkan.hpp +++ b/src/rendervulkan.hpp @@ -906,7 +906,10 @@ class CVulkanCmdBuffer friend class CVulkanDevice; #ifdef TRACY_ENABLE inline std::optional& 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: