Skip to content

Commit

Permalink
Try to eliminate another shutdown deadlock (drain shader compile queue)
Browse files Browse the repository at this point in the history
See #18705
  • Loading branch information
hrydgard committed Jan 15, 2024
1 parent 3deabae commit 7b738ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions Common/GPU/Vulkan/VulkanRenderManager.cpp
Expand Up @@ -511,17 +511,25 @@ void VulkanRenderManager::CompileThreadFunc() {
}

void VulkanRenderManager::DrainAndBlockCompileQueue() {
std::unique_lock<std::mutex> lock(compileMutex_);
compileBlocked_ = true;
compileCond_.notify_all();
while (!compileQueue_.empty()) {
queueRunner_.WaitForCompileNotification();
while (true) {
bool anyInQueue = false;
{
std::unique_lock<std::mutex> lock(compileMutex_);
anyInQueue = !compileQueue_.empty();
}
if (anyInQueue) {
queueRunner_.WaitForCompileNotification();
} else {
break;
}
}
// At this point, no more tasks can be queued to the threadpool. So wait for them all to go away.
CreateMultiPipelinesTask::WaitForAll();
}

void VulkanRenderManager::ReleaseCompileQueue() {
std::unique_lock<std::mutex> lock(compileMutex_);
compileBlocked_ = false;
}

Expand Down Expand Up @@ -791,11 +799,11 @@ VKRGraphicsPipeline *VulkanRenderManager::CreateGraphicsPipeline(VKRGraphicsPipe
VKRRenderPassStoreAction::STORE, VKRRenderPassStoreAction::DONT_CARE, VKRRenderPassStoreAction::DONT_CARE,
};
VKRRenderPass *compatibleRenderPass = queueRunner_.GetRenderPass(key);
std::lock_guard<std::mutex> lock(compileMutex_);
if (compileBlocked_) {
delete pipeline;
return nullptr;
}
std::lock_guard<std::mutex> lock(compileMutex_);
bool needsCompile = false;
for (size_t i = 0; i < (size_t)RenderPassType::TYPE_COUNT; i++) {
if (!(variantBitmask & (1 << i)))
Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/Vulkan/VulkanRenderManager.h
Expand Up @@ -601,7 +601,7 @@ class VulkanRenderManager {
std::condition_variable compileCond_;
std::mutex compileMutex_;
std::vector<CompileQueueEntry> compileQueue_;
bool compileBlocked_ = false;
std::atomic<bool> compileBlocked_{};

// Thread for measuring presentation delay.
std::thread presentWaitThread_;
Expand Down

0 comments on commit 7b738ed

Please sign in to comment.