Skip to content

Commit

Permalink
Merge pull request #18816 from hrydgard/more-fixes
Browse files Browse the repository at this point in the history
Try to resolve another race condition. Improve an assert.
  • Loading branch information
hrydgard committed Feb 3, 2024
2 parents 16d1d55 + 3802d4e commit 6e676b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Common/GPU/Vulkan/VulkanRenderManager.cpp
Expand Up @@ -459,6 +459,7 @@ VulkanRenderManager::~VulkanRenderManager() {
void VulkanRenderManager::CompileThreadFunc() {
SetCurrentThreadName("ShaderCompile");
while (true) {
bool exitAfterCompile = false;
std::vector<CompileQueueEntry> toCompile;
{
std::unique_lock<std::mutex> lock(compileMutex_);
Expand All @@ -467,6 +468,9 @@ void VulkanRenderManager::CompileThreadFunc() {
}
toCompile = std::move(compileQueue_);
compileQueue_.clear();
if (!runCompileThread_) {
exitAfterCompile = true;
}
}

int countToCompile = (int)toCompile.size();
Expand Down Expand Up @@ -509,7 +513,7 @@ void VulkanRenderManager::CompileThreadFunc() {
g_threadManager.EnqueueTask(task);
}

if (!runCompileThread_) {
if (exitAfterCompile) {
break;
}

Expand Down
3 changes: 2 additions & 1 deletion Common/GPU/Vulkan/VulkanRenderManager.h
Expand Up @@ -569,7 +569,8 @@ class VulkanRenderManager {
int curHeight_ = -1;

bool insideFrame_ = false;
bool runCompileThread_ = false;
// probably doesn't need to be atomic.
std::atomic<bool> runCompileThread_;

bool useRenderThread_ = true;
bool measurePresentTime_ = false;
Expand Down
6 changes: 4 additions & 2 deletions Common/Thread/Promise.h
Expand Up @@ -88,7 +88,8 @@ class Promise {
// Returns T if the data is ready, nullptr if it's not.
// Obviously, can only be used if T is nullable, otherwise it won't compile.
T Poll() {
_assert_(sentinel_ == 0xffc0ffee);
uint32_t sentinel = sentinel_;
_assert_msg_(sentinel == 0xffc0ffee, "%08x", sentinel);
std::lock_guard<std::mutex> guard(readyMutex_);
if (ready_) {
return data_;
Expand All @@ -105,7 +106,8 @@ class Promise {
}

T BlockUntilReady() {
_assert_(sentinel_ == 0xffc0ffee);
uint32_t sentinel = sentinel_;
_assert_msg_(sentinel == 0xffc0ffee, "%08x", sentinel);
std::lock_guard<std::mutex> guard(readyMutex_);
if (ready_) {
return data_;
Expand Down

0 comments on commit 6e676b9

Please sign in to comment.