-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vulkan multithread: Fix race condition.
- Loading branch information
Showing
2 changed files
with
9 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,11 +187,14 @@ void VulkanRenderManager::CreateBackbuffers() { | |
curWidth_ = -1; | ||
curHeight_ = -1; | ||
|
||
VLOG("Backbuffers Created"); | ||
|
||
// Start the thread. | ||
if (useThread) { | ||
run_ = true; | ||
// Won't necessarily be 0. | ||
threadInitFrame_ = vulkan_->GetCurFrame(); | ||
VLOG("starting thread"); | ||
thread_ = std::thread(&VulkanRenderManager::ThreadFunc, this); | ||
} | ||
} | ||
|
@@ -212,6 +215,7 @@ void VulkanRenderManager::StopThread(bool shutdown) { | |
} | ||
} | ||
thread_.join(); | ||
VLOG("thread joined."); | ||
|
||
// Resignal fences for next time around - must be done after join. | ||
for (int i = 0; i < vulkan_->GetInflightFrames(); i++) { | ||
|
@@ -243,6 +247,7 @@ void VulkanRenderManager::DestroyBackbuffers() { | |
framebuffers_.clear(); | ||
|
||
swapchainImages_.clear(); | ||
VLOG("Backbuffers Destroyed"); | ||
} | ||
|
||
VulkanRenderManager::~VulkanRenderManager() { | ||
|
@@ -283,8 +288,8 @@ void VulkanRenderManager::ThreadFunc() { | |
} | ||
VLOG("PULL: frame[%d].readyForRun = false", threadFrame); | ||
frameData.readyForRun = false; | ||
if (!run_) // quick exit if bailing. | ||
return; | ||
// Previously we had a quick exit here that avoided calling Run() if run_ was suddenly false, | ||
// but that created a race condition where frames could end up not finished properly on resize etc. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
hrydgard
Author
Owner
|
||
|
||
// Only increment next time if we're done. | ||
nextFrame = frameData.type == VKRRunType::END; | ||
|
@@ -298,6 +303,7 @@ void VulkanRenderManager::ThreadFunc() { | |
} | ||
|
||
void VulkanRenderManager::BeginFrame() { | ||
VLOG("BeginFrame"); | ||
VkDevice device = vulkan_->GetDevice(); | ||
|
||
int curFrame = vulkan_->GetCurFrame(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You're right, this is probably better, probably never end up recreating the fences now.
Though, I wonder how far away we are from DeviceLost in Vulkan...
-[Unknown]