From d2723d6bf378598e25faae9f4efd75c6558e9950 Mon Sep 17 00:00:00 2001 From: "j.kong" Date: Wed, 27 Sep 2023 01:43:31 +0800 Subject: [PATCH] Fixed optick command pool bug source: https://github.com/bombomby/optick/pull/187 --- OO_Vulkan/src/optick/optick_gpu.vulkan.cpp | 50 +++++++++++++++------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/OO_Vulkan/src/optick/optick_gpu.vulkan.cpp b/OO_Vulkan/src/optick/optick_gpu.vulkan.cpp index ba46cfb..ccd87b4 100644 --- a/OO_Vulkan/src/optick/optick_gpu.vulkan.cpp +++ b/OO_Vulkan/src/optick/optick_gpu.vulkan.cpp @@ -217,7 +217,7 @@ namespace Optick if (currentState == STATE_RUNNING) { uint32_t index = nodes[currentNode]->QueryTimestamp(outCpuTimestamp); - (*vulkanFunctions.vkCmdWriteTimestamp)(commandBuffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, nodePayloads[currentNode]->queryPool, index); + (*vulkanFunctions.vkCmdWriteTimestamp)(commandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, nodePayloads[currentNode]->queryPool, index); } } @@ -294,17 +294,17 @@ namespace Optick QueryTimestamp(commandBuffer, &AddFrameTag().timestamp); nextFrame.frameEvent = &event; - OPTICK_VK_CHECK((VkResult)(*vulkanFunctions.vkEndCommandBuffer)(commandBuffer)); - VkSubmitInfo submitInfo = {}; - submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submitInfo.pNext = nullptr; - submitInfo.waitSemaphoreCount = 0; - submitInfo.pWaitSemaphores = nullptr; - submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = &commandBuffer; - submitInfo.signalSemaphoreCount = 0; - submitInfo.pSignalSemaphores = nullptr; - OPTICK_VK_CHECK((VkResult)(*vulkanFunctions.vkQueueSubmit)(queue, 1, &submitInfo, fence)); + //OPTICK_VK_CHECK((VkResult)(*vulkanFunctions.vkEndCommandBuffer)(commandBuffer)); + //VkSubmitInfo submitInfo = {}; + //submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + //submitInfo.pNext = nullptr; + //submitInfo.waitSemaphoreCount = 0; + //submitInfo.pWaitSemaphores = nullptr; + //submitInfo.commandBufferCount = 1; + //submitInfo.pCommandBuffers = &commandBuffer; + //submitInfo.signalSemaphoreCount = 0; + //submitInfo.pSignalSemaphores = nullptr; + //OPTICK_VK_CHECK((VkResult)(*vulkanFunctions.vkQueueSubmit)(queue, 1, &submitInfo, fence)); uint32_t queryBegin = currentFrame.queryIndexStart; uint32_t queryEnd = node.queryIndex; @@ -332,6 +332,18 @@ namespace Optick } } + OPTICK_VK_CHECK((VkResult)(*vulkanFunctions.vkEndCommandBuffer)(commandBuffer)); + VkSubmitInfo submitInfo = {}; + submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submitInfo.pNext = nullptr; + submitInfo.waitSemaphoreCount = 0; + submitInfo.pWaitSemaphores = nullptr; + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &commandBuffer; + submitInfo.signalSemaphoreCount = 0; + submitInfo.pSignalSemaphores = nullptr; + OPTICK_VK_CHECK((VkResult)(*vulkanFunctions.vkQueueSubmit)(queue, 1, &submitInfo, fence)); + nextFrame.queryIndexStart = queryEnd; nextFrame.queryIndexCount = 0; } @@ -359,8 +371,13 @@ namespace Optick (*vulkanFunctions.vkResetFences)(Device, 1, &Fence); (*vulkanFunctions.vkResetCommandBuffer)(CB, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); (*vulkanFunctions.vkBeginCommandBuffer)(CB, &commandBufferBeginInfo); - (*vulkanFunctions.vkCmdResetQueryPool)(CB, nodePayloads[nodeIndex]->queryPool, 0, 1); - (*vulkanFunctions.vkCmdWriteTimestamp)(CB, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, nodePayloads[nodeIndex]->queryPool, 0); + //(*vulkanFunctions.vkCmdResetQueryPool)(CB, nodePayloads[nodeIndex]->queryPool, 0, 1); + //(*vulkanFunctions.vkCmdWriteTimestamp)(CB, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, nodePayloads[nodeIndex]->queryPool, 0); + + int64_t unusedTimestap; + uint32_t queryIdx = nodes[nodeIndex]->QueryTimestamp( &unusedTimestap ); + (*vulkanFunctions.vkCmdWriteTimestamp)(CB, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, nodePayloads[nodeIndex]->queryPool, queryIdx); + (*vulkanFunctions.vkEndCommandBuffer)(CB); VkSubmitInfo submitInfo = {}; @@ -376,7 +393,7 @@ namespace Optick (*vulkanFunctions.vkWaitForFences)(Device, 1, &Fence, 1, (uint64_t)-1); clock.timestampGPU = 0; - (*vulkanFunctions.vkGetQueryPoolResults)(Device, nodePayloads[nodeIndex]->queryPool, 0, 1, 8, &clock.timestampGPU, 8, VK_QUERY_RESULT_64_BIT); + (*vulkanFunctions.vkGetQueryPoolResults)(Device, nodePayloads[nodeIndex]->queryPool, queryIdx, 1, 8, &clock.timestampGPU, 8, VK_QUERY_RESULT_64_BIT); clock.timestampCPU = GetHighPrecisionTime(); clock.frequencyCPU = GetHighPrecisionFrequency(); @@ -384,6 +401,9 @@ namespace Optick (*vulkanFunctions.vkGetPhysicalDeviceProperties)(nodePayloads[nodeIndex]->physicalDevice, &Properties); clock.frequencyGPU = (uint64_t)(1000000000ll / Properties.limits.timestampPeriod); + // make so vkCmdResetQueryPool is called for initialization and first frame's queues + nodes[nodeIndex]->queryGpuframes[frameNumber % NUM_FRAMES_DELAY].queryIndexStart = queryIdx; + return clock; }