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

Found a bug where we tried to look up queue family -1 when initializing the frame profiler. #16647

Merged
merged 1 commit into from
Dec 23, 2022
Merged
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
21 changes: 12 additions & 9 deletions Common/GPU/Vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,6 @@ VkResult VulkanContext::CreateDevice() {
break;
}


for (int i = 0; i < ARRAY_SIZE(frame_); i++) {
frame_[i].profiler.Init(this);
}

return res;
}

Expand Down Expand Up @@ -909,6 +904,10 @@ VkResult VulkanContext::ReinitSurface() {
return VK_ERROR_INITIALIZATION_FAILED;
}

for (int i = 0; i < ARRAY_SIZE(frame_); i++) {
frame_[i].profiler.Init(this);
}

return VK_SUCCESS;
}

Expand Down Expand Up @@ -938,7 +937,7 @@ bool VulkanContext::ChooseQueue() {
}
if (presentQueueNodeIndex == UINT32_MAX) {
// If didn't find a queue that supports both graphics and present, then
// find a separate present queue.
// find a separate present queue. NOTE: We don't actually currently support this arrangement!
for (uint32_t i = 0; i < queue_count; ++i) {
if (supportsPresent[i] == VK_TRUE) {
presentQueueNodeIndex = i;
Expand Down Expand Up @@ -1236,13 +1235,13 @@ void VulkanContext::DestroyDevice() {
ERROR_LOG(G3D, "DestroyDevice: Surface should have been destroyed.");
}

INFO_LOG(G3D, "VulkanContext::DestroyDevice (performing deletes)");
PerformPendingDeletes();

for (int i = 0; i < ARRAY_SIZE(frame_); i++) {
frame_[i].profiler.Shutdown();
}

INFO_LOG(G3D, "VulkanContext::DestroyDevice (performing deletes)");
PerformPendingDeletes();

vmaDestroyAllocator(allocator_);
allocator_ = VK_NULL_HANDLE;

Expand Down Expand Up @@ -1515,6 +1514,10 @@ void VulkanDeleteList::PerformDeletes(VkDevice device, VmaAllocator allocator) {
vkDestroyDescriptorSetLayout(device, descSetLayout, nullptr);
}
descSetLayouts_.clear();
for (auto &queryPool : queryPools_) {
vkDestroyQueryPool(device, queryPool, nullptr);
}
queryPools_.clear();
}

void VulkanContext::GetImageMemoryRequirements(VkImage image, VkMemoryRequirements *mem_reqs, bool *dedicatedAllocation) {
Expand Down
7 changes: 5 additions & 2 deletions Common/GPU/Vulkan/VulkanContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class VulkanDeleteList {
void QueueDeleteFramebuffer(VkFramebuffer &framebuffer) { _dbg_assert_(framebuffer != VK_NULL_HANDLE); framebuffers_.push_back(framebuffer); framebuffer = VK_NULL_HANDLE; }
void QueueDeletePipelineLayout(VkPipelineLayout &pipelineLayout) { _dbg_assert_(pipelineLayout != VK_NULL_HANDLE); pipelineLayouts_.push_back(pipelineLayout); pipelineLayout = VK_NULL_HANDLE; }
void QueueDeleteDescriptorSetLayout(VkDescriptorSetLayout &descSetLayout) { _dbg_assert_(descSetLayout != VK_NULL_HANDLE); descSetLayouts_.push_back(descSetLayout); descSetLayout = VK_NULL_HANDLE; }
void QueueDeleteQueryPool(VkQueryPool &queryPool) { _dbg_assert_(queryPool != VK_NULL_HANDLE); queryPools_.push_back(queryPool); queryPool = VK_NULL_HANDLE; }
void QueueCallback(void(*func)(void *userdata), void *userdata) { callbacks_.push_back(Callback(func, userdata)); }

void QueueDeleteBufferAllocation(VkBuffer &buffer, VmaAllocation &alloc) {
Expand Down Expand Up @@ -152,6 +153,7 @@ class VulkanDeleteList {
std::vector<VkFramebuffer> framebuffers_;
std::vector<VkPipelineLayout> pipelineLayouts_;
std::vector<VkDescriptorSetLayout> descSetLayouts_;
std::vector<VkQueryPool> queryPools_;
std::vector<Callback> callbacks_;
};

Expand Down Expand Up @@ -386,10 +388,11 @@ class VulkanContext {
bool CheckLayers(const std::vector<LayerProperties> &layer_props, const std::vector<const char *> &layer_names) const;

WindowSystem winsys_;

// Don't use the real types here to avoid having to include platform-specific stuff
// that we really don't want in everything that uses VulkanContext.
void *winsysData1_;
void *winsysData2_;
void *winsysData1_ = nullptr;
void *winsysData2_ = nullptr;
std::function<VkExtent2D()> cbGetDrawSize_;

VkInstance instance_ = VK_NULL_HANDLE;
Expand Down
11 changes: 9 additions & 2 deletions Common/GPU/Vulkan/VulkanProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ using namespace PPSSPP_VK;
void VulkanProfiler::Init(VulkanContext *vulkan) {
vulkan_ = vulkan;

validBits_ = vulkan_->GetQueueFamilyProperties(vulkan_->GetGraphicsQueueFamilyIndex()).timestampValidBits;
int graphicsQueueFamilyIndex = vulkan_->GetGraphicsQueueFamilyIndex();
_assert_(graphicsQueueFamilyIndex >= 0);

if (queryPool_) {
vulkan->Delete().QueueDeleteQueryPool(queryPool_);
}

validBits_ = vulkan_->GetQueueFamilyProperties(graphicsQueueFamilyIndex).timestampValidBits;

if (validBits_) {
VkQueryPoolCreateInfo ci{ VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO };
Expand All @@ -20,7 +27,7 @@ void VulkanProfiler::Init(VulkanContext *vulkan) {

void VulkanProfiler::Shutdown() {
if (queryPool_) {
vkDestroyQueryPool(vulkan_->GetDevice(), queryPool_, nullptr);
vulkan_->Delete().QueueDeleteQueryPool(queryPool_);
}
}

Expand Down