mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-12 04:08:52 +01:00
[dxvk] Explicitly stop state cache worker threads on device destruction
Otherwise, the workers may access objects that are being destroyed an app thread.
This commit is contained in:
parent
24eb875f02
commit
3e64e1b3f5
@ -29,6 +29,10 @@ namespace dxvk {
|
||||
// Wait for all pending Vulkan commands to be
|
||||
// executed before we destroy any resources.
|
||||
this->waitForIdle();
|
||||
|
||||
// Stop workers explicitly in order to prevent
|
||||
// access to structures that are being destroyed.
|
||||
m_objects.pipelineManager().stopWorkerThreads();
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,5 +78,11 @@ namespace dxvk {
|
||||
return m_stateCache != nullptr
|
||||
&& m_stateCache->isCompilingShaders();
|
||||
}
|
||||
|
||||
|
||||
void DxvkPipelineManager::stopWorkerThreads() const {
|
||||
if (m_stateCache != nullptr)
|
||||
m_stateCache->stopWorkerThreads();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -89,6 +89,11 @@ namespace dxvk {
|
||||
* \returns \c true if shaders are being compiled
|
||||
*/
|
||||
bool isCompilingShaders() const;
|
||||
|
||||
/**
|
||||
* \brief Stops async compiler threads
|
||||
*/
|
||||
void stopWorkerThreads() const;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -210,19 +210,7 @@ namespace dxvk {
|
||||
|
||||
|
||||
DxvkStateCache::~DxvkStateCache() {
|
||||
{ std::lock_guard<dxvk::mutex> workerLock(m_workerLock);
|
||||
std::lock_guard<dxvk::mutex> writerLock(m_writerLock);
|
||||
|
||||
m_stopThreads.store(true);
|
||||
|
||||
m_workerCond.notify_all();
|
||||
m_writerCond.notify_all();
|
||||
}
|
||||
|
||||
for (auto& worker : m_workerThreads)
|
||||
worker.join();
|
||||
|
||||
m_writerThread.join();
|
||||
this->stopWorkerThreads();
|
||||
}
|
||||
|
||||
|
||||
@ -314,6 +302,24 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
void DxvkStateCache::stopWorkerThreads() {
|
||||
{ std::lock_guard<dxvk::mutex> workerLock(m_workerLock);
|
||||
std::lock_guard<dxvk::mutex> writerLock(m_writerLock);
|
||||
|
||||
if (m_stopThreads.exchange(true))
|
||||
return;
|
||||
|
||||
m_workerCond.notify_all();
|
||||
m_writerCond.notify_all();
|
||||
}
|
||||
|
||||
for (auto& worker : m_workerThreads)
|
||||
worker.join();
|
||||
|
||||
m_writerThread.join();
|
||||
}
|
||||
|
||||
|
||||
DxvkShaderKey DxvkStateCache::getShaderKey(const Rc<DxvkShader>& shader) const {
|
||||
return shader != nullptr ? shader->getShaderKey() : g_nullShaderKey;
|
||||
}
|
||||
|
@ -70,7 +70,12 @@ namespace dxvk {
|
||||
*/
|
||||
void registerShader(
|
||||
const Rc<DxvkShader>& shader);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Explicitly stops worker threads
|
||||
*/
|
||||
void stopWorkerThreads();
|
||||
|
||||
/**
|
||||
* \brief Checks whether compiler threads are busy
|
||||
* \returns \c true if we're compiling shaders
|
||||
|
Loading…
Reference in New Issue
Block a user