Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vulkan validation #187

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ if(OPTICK_USE_VULKAN)
message(STATUS "Optick uses Vulkan")
find_package(Vulkan REQUIRED)
target_link_libraries(OptickCore PRIVATE Vulkan::Vulkan)
target_compile_definitions(OptickCore PRIVATE OPTICK_ENABLE_GPU_VULKAN=1)
else()
target_compile_definitions(OptickCore PRIVATE OPTICK_ENABLE_GPU_VULKAN=0)
endif()
if(OPTICK_USE_D3D12)
message(STATUS "Optick uses DirectX 12")
target_link_libraries(OptickCore PRIVATE "d3d12.lib" "dxgi.lib")
target_compile_definitions(OptickCore PRIVATE OPTICK_ENABLE_GPU_D3D12=1)
else()
target_compile_definitions(OptickCore PRIVATE OPTICK_ENABLE_GPU_D3D12=0)
endif()
Expand Down
45 changes: 27 additions & 18 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,7 +219,8 @@ 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_BOTTOM_OF_PIPE_BIT, nodePayloads[currentNode]->queryPool, index);
}
}

Expand Down Expand Up @@ -294,26 +297,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 +323,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 +362,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_TOP_OF_PIPE_BIT, nodePayloads[nodeIndex]->queryPool, queryIdx);

(*vulkanFunctions.vkEndCommandBuffer)(CB);

VkSubmitInfo submitInfo = {};
Expand All @@ -376,14 +382,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