From 19a443819bae961acf0d20e01d3cd767ca348449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 21 Aug 2019 09:02:23 +0200 Subject: [PATCH] Bugfixes to VK gpu profiling. Properly get the valid bits. --- Common/Vulkan/VulkanContext.cpp | 8 ++++---- Common/Vulkan/VulkanContext.h | 8 ++++++-- Core/Config.h | 2 +- ext/native/thin3d/VulkanRenderManager.cpp | 7 ++++++- ext/native/thin3d/VulkanRenderManager.h | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Common/Vulkan/VulkanContext.cpp b/Common/Vulkan/VulkanContext.cpp index 297bc72d2f..dc87073214 100644 --- a/Common/Vulkan/VulkanContext.cpp +++ b/Common/Vulkan/VulkanContext.cpp @@ -516,8 +516,8 @@ void VulkanContext::ChooseDevice(int physical_device) { vkGetPhysicalDeviceQueueFamilyProperties(physical_devices_[physical_device_], &queue_count, nullptr); assert(queue_count >= 1); - queue_props.resize(queue_count); - vkGetPhysicalDeviceQueueFamilyProperties(physical_devices_[physical_device_], &queue_count, queue_props.data()); + queueFamilyProperties_.resize(queue_count); + vkGetPhysicalDeviceQueueFamilyProperties(physical_devices_[physical_device_], &queue_count, queueFamilyProperties_.data()); assert(queue_count >= 1); // Detect preferred formats, in this order. @@ -619,7 +619,7 @@ VkResult VulkanContext::CreateDevice() { queue_info.pQueuePriorities = queue_priorities; bool found = false; for (int i = 0; i < (int)queue_count; i++) { - if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { + if (queueFamilyProperties_[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { queue_info.queueFamilyIndex = i; found = true; break; @@ -816,7 +816,7 @@ bool VulkanContext::InitQueue() { uint32_t graphicsQueueNodeIndex = UINT32_MAX; uint32_t presentQueueNodeIndex = UINT32_MAX; for (uint32_t i = 0; i < queue_count; i++) { - if ((queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) { + if ((queueFamilyProperties_[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) { if (graphicsQueueNodeIndex == UINT32_MAX) { graphicsQueueNodeIndex = i; } diff --git a/Common/Vulkan/VulkanContext.h b/Common/Vulkan/VulkanContext.h index 01761aab6b..d3ecb96963 100644 --- a/Common/Vulkan/VulkanContext.h +++ b/Common/Vulkan/VulkanContext.h @@ -201,6 +201,10 @@ public: return physicalDeviceProperties_[i]; } + const VkQueueFamilyProperties &GetQueueFamilyProperties(int family) const { + return queueFamilyProperties_[family]; + } + VkResult GetInstanceLayerExtensionList(const char *layerName, std::vector &extensions); VkResult GetInstanceLayerProperties(); @@ -303,8 +307,8 @@ private: int physical_device_ = -1; uint32_t graphics_queue_family_index_ = -1; - std::vector physicalDeviceProperties_{}; - std::vector queue_props; + std::vector physicalDeviceProperties_; + std::vector queueFamilyProperties_; VkPhysicalDeviceMemoryProperties memory_properties{}; // Custom collection of things that are good to know diff --git a/Core/Config.h b/Core/Config.h index ad39197300..c23a651053 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -237,8 +237,8 @@ public: bool bLogFrameDrops; bool bShowDebugStats; bool bShowAudioDebug; - bool bAudioResampler; bool bShowGpuProfile; + bool bAudioResampler; //Analog stick tilting //the base x and y tilt. this inclination is treated as (0,0) and the tilt input diff --git a/ext/native/thin3d/VulkanRenderManager.cpp b/ext/native/thin3d/VulkanRenderManager.cpp index aff60e85d9..ac584fb71e 100644 --- a/ext/native/thin3d/VulkanRenderManager.cpp +++ b/ext/native/thin3d/VulkanRenderManager.cpp @@ -226,6 +226,9 @@ void VulkanRenderManager::StopThread() { std::unique_lock lock(frameData.pull_mutex); frameData.pull_condVar.notify_all(); } + // Zero the queries so we don't try to pull them later. + frameData.numQueries = 0; + frameData.timestampDescriptions.clear(); } thread_.join(); ILOG("Vulkan submission thread joined. Frame=%d", vulkan_->GetCurFrame()); @@ -378,7 +381,8 @@ void VulkanRenderManager::BeginFrame() { VK_QUERY_RESULT_64_BIT); if (res == VK_SUCCESS) { double timestampConversionFactor = (double)vulkan_->GetPhysicalDeviceProperties().properties.limits.timestampPeriod * (1.0 / 1000000.0); - uint64_t timestampDiffMask = 0xFFFFFFFFFFFFFFFFULL; // TODO: Get from queue family + int validBits = vulkan_->GetQueueFamilyProperties(vulkan_->GetGraphicsQueueFamilyIndex()).timestampValidBits; + uint64_t timestampDiffMask = validBits == 64 ? 0xFFFFFFFFFFFFFFFFULL : ((1ULL << validBits) - 1); std::stringstream str; char line[256]; @@ -409,6 +413,7 @@ void VulkanRenderManager::BeginFrame() { insideFrame_ = true; + frameData.timestampDescriptions.clear(); if (gpuProfilingEnabled_) { // For various reasons, we need to always use an init cmd buffer in this case to perform the vkCmdResetQueryPool, // unless we want to limit ourselves to only measure the main cmd buffer. diff --git a/ext/native/thin3d/VulkanRenderManager.h b/ext/native/thin3d/VulkanRenderManager.h index 50c86a92bc..393efd21d4 100644 --- a/ext/native/thin3d/VulkanRenderManager.h +++ b/ext/native/thin3d/VulkanRenderManager.h @@ -314,7 +314,7 @@ private: VKRStep *curRenderStep_ = nullptr; std::vector steps_; bool splitSubmit_ = false; - bool gpuProfilingEnabled_ = true; + bool gpuProfilingEnabled_ = false; // Execution time state bool run_ = true;