Try to eliminate another shutdown deadlock (drain shader compile queue)

See #18705
This commit is contained in:
Henrik Rydgård 2024-01-15 23:36:47 +01:00
parent 3deabaeb04
commit 7b738edfc9
2 changed files with 14 additions and 6 deletions

View file

@ -511,17 +511,25 @@ void VulkanRenderManager::CompileThreadFunc() {
} }
void VulkanRenderManager::DrainAndBlockCompileQueue() { void VulkanRenderManager::DrainAndBlockCompileQueue() {
std::unique_lock<std::mutex> lock(compileMutex_);
compileBlocked_ = true; compileBlocked_ = true;
compileCond_.notify_all(); compileCond_.notify_all();
while (!compileQueue_.empty()) { while (true) {
queueRunner_.WaitForCompileNotification(); 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(); CreateMultiPipelinesTask::WaitForAll();
} }
void VulkanRenderManager::ReleaseCompileQueue() { void VulkanRenderManager::ReleaseCompileQueue() {
std::unique_lock<std::mutex> lock(compileMutex_);
compileBlocked_ = false; compileBlocked_ = false;
} }
@ -791,11 +799,11 @@ VKRGraphicsPipeline *VulkanRenderManager::CreateGraphicsPipeline(VKRGraphicsPipe
VKRRenderPassStoreAction::STORE, VKRRenderPassStoreAction::DONT_CARE, VKRRenderPassStoreAction::DONT_CARE, VKRRenderPassStoreAction::STORE, VKRRenderPassStoreAction::DONT_CARE, VKRRenderPassStoreAction::DONT_CARE,
}; };
VKRRenderPass *compatibleRenderPass = queueRunner_.GetRenderPass(key); VKRRenderPass *compatibleRenderPass = queueRunner_.GetRenderPass(key);
std::lock_guard<std::mutex> lock(compileMutex_);
if (compileBlocked_) { if (compileBlocked_) {
delete pipeline; delete pipeline;
return nullptr; return nullptr;
} }
std::lock_guard<std::mutex> lock(compileMutex_);
bool needsCompile = false; bool needsCompile = false;
for (size_t i = 0; i < (size_t)RenderPassType::TYPE_COUNT; i++) { for (size_t i = 0; i < (size_t)RenderPassType::TYPE_COUNT; i++) {
if (!(variantBitmask & (1 << i))) if (!(variantBitmask & (1 << i)))

View file

@ -601,7 +601,7 @@ private:
std::condition_variable compileCond_; std::condition_variable compileCond_;
std::mutex compileMutex_; std::mutex compileMutex_;
std::vector<CompileQueueEntry> compileQueue_; std::vector<CompileQueueEntry> compileQueue_;
bool compileBlocked_ = false; std::atomic<bool> compileBlocked_{};
// Thread for measuring presentation delay. // Thread for measuring presentation delay.
std::thread presentWaitThread_; std::thread presentWaitThread_;