Skip to content

Commit

Permalink
Make vulkan validation layers not complain
Browse files Browse the repository at this point in the history
  • Loading branch information
qbojj committed Dec 21, 2022
1 parent 7fc412c commit 418d8c2
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/optick_gpu.vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace Optick
VkResult r;
for (uint32_t i = 0; i < nodeCount; ++i)
{
VkPhysicalDeviceProperties properties = { 0 };
VkPhysicalDeviceProperties properties{};
(*vulkanFunctions.vkGetPhysicalDeviceProperties)(physicalDevices[i], &properties);
GPUProfiler::InitNode(properties.deviceName, i);

Expand Down Expand Up @@ -207,6 +207,8 @@ namespace Optick
(*vulkanFunctions.vkQueueSubmit)(nodePayload->queue, 1, &submitInfo, frame.fence);
(*vulkanFunctions.vkWaitForFences)(nodePayload->device, 1, &frame.fence, 1, (uint64_t)-1);
(*vulkanFunctions.vkResetCommandBuffer)(frame.commandBuffer, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);


}
}
}
Expand All @@ -217,6 +219,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);
}
}
Expand Down Expand Up @@ -257,7 +260,10 @@ namespace Optick
std::lock_guard<std::recursive_mutex> lock(updateLock);

if (currentState == STATE_STARTING)
{
nodes[currentNode]->queryGpuframes[0].queryIndexStart = 0;
currentState = STATE_RUNNING;
}

if (currentState == STATE_RUNNING)
{
Expand Down Expand Up @@ -294,26 +300,14 @@ 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));

uint32_t queryBegin = currentFrame.queryIndexStart;
uint32_t queryEnd = node.queryIndex;

if (queryBegin != (uint32_t)-1)
{
currentFrame.queryIndexCount = queryEnd - queryBegin;
}

// Preparing Next Frame
// Try resolve timestamps for the current frame
if (nextFrame.queryIndexStart != (uint32_t)-1)
Expand All @@ -332,6 +326,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 +365,11 @@ 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);

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,7 +385,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();

Expand Down

0 comments on commit 418d8c2

Please sign in to comment.