Skip to content

Commit

Permalink
Fixed optick command pool bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Supercomet committed Sep 26, 2023
1 parent d817657 commit d2723d6
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions OO_Vulkan/src/optick/optick_gpu.vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 = {};
Expand All @@ -376,14 +393,17 @@ 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();

VkPhysicalDeviceProperties Properties;
(*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;
}

Expand Down

0 comments on commit d2723d6

Please sign in to comment.