diff --git a/src/dxvk/dxvk_pipemanager.cpp b/src/dxvk/dxvk_pipemanager.cpp index 0e112e51..4c5ea32f 100644 --- a/src/dxvk/dxvk_pipemanager.cpp +++ b/src/dxvk/dxvk_pipemanager.cpp @@ -5,7 +5,7 @@ namespace dxvk { DxvkPipelineManager::DxvkPipelineManager( - const DxvkDevice* device, + DxvkDevice* device, DxvkRenderPassPool* passManager) : m_device (device), m_cache (new DxvkPipelineCache(device->vkd())) { diff --git a/src/dxvk/dxvk_pipemanager.h b/src/dxvk/dxvk_pipemanager.h index f32a8913..08c79e0a 100644 --- a/src/dxvk/dxvk_pipemanager.h +++ b/src/dxvk/dxvk_pipemanager.h @@ -38,7 +38,7 @@ namespace dxvk { public: DxvkPipelineManager( - const DxvkDevice* device, + DxvkDevice* device, DxvkRenderPassPool* passManager); ~DxvkPipelineManager(); @@ -97,7 +97,7 @@ namespace dxvk { private: - const DxvkDevice* m_device; + DxvkDevice* m_device; Rc m_cache; Rc m_stateCache; diff --git a/src/dxvk/dxvk_state_cache.cpp b/src/dxvk/dxvk_state_cache.cpp index 15bec171..1dfb26d0 100644 --- a/src/dxvk/dxvk_state_cache.cpp +++ b/src/dxvk/dxvk_state_cache.cpp @@ -150,11 +150,12 @@ namespace dxvk { DxvkStateCache::DxvkStateCache( - const DxvkDevice* device, + DxvkDevice* device, DxvkPipelineManager* pipeManager, DxvkRenderPassPool* passManager) - : m_pipeManager(pipeManager), - m_passManager(passManager) { + : m_device (device), + m_pipeManager (pipeManager), + m_passManager (passManager) { bool newFile = !readCacheFile(); if (newFile) { @@ -184,28 +185,6 @@ namespace dxvk { for (auto& e : m_entries) writeCacheEntry(file, e); } - - // Use half the available CPU cores for pipeline compilation - uint32_t numCpuCores = dxvk::thread::hardware_concurrency(); - uint32_t numWorkers = ((std::max(1u, numCpuCores) - 1) * 5) / 7; - - if (numWorkers < 1) numWorkers = 1; - if (numWorkers > 32) numWorkers = 32; - - if (device->config().numCompilerThreads > 0) - numWorkers = device->config().numCompilerThreads; - - Logger::info(str::format("DXVK: Using ", numWorkers, " compiler threads")); - - // Start the worker threads and the file writer - m_workerBusy.store(numWorkers); - - for (uint32_t i = 0; i < numWorkers; i++) { - m_workerThreads.emplace_back([this] () { workerFunc(); }); - m_workerThreads[i].set_priority(ThreadPriority::Lowest); - } - - m_writerThread = dxvk::thread([this] () { writerFunc(); }); } @@ -238,6 +217,8 @@ namespace dxvk { DxvkComputePipelineStateInfo(), format, g_nullHash }); m_writerCond.notify_one(); + + createWriter(); } @@ -262,6 +243,8 @@ namespace dxvk { DxvkGraphicsPipelineStateInfo(), state, DxvkRenderPassFormat(), g_nullHash }); m_writerCond.notify_one(); + + createWriter(); } @@ -297,8 +280,10 @@ namespace dxvk { m_workerQueue.push(item); } - if (workerLock) + if (workerLock) { m_workerCond.notify_all(); + createWorkers(); + } } @@ -316,7 +301,8 @@ namespace dxvk { for (auto& worker : m_workerThreads) worker.join(); - m_writerThread.join(); + if (m_writerThread.joinable()) + m_writerThread.join(); } @@ -987,6 +973,37 @@ namespace dxvk { } + void DxvkStateCache::createWorkers() { + if (m_workerThreads.empty()) { + // Use half the available CPU cores for pipeline compilation + uint32_t numCpuCores = dxvk::thread::hardware_concurrency(); + uint32_t numWorkers = ((std::max(1u, numCpuCores) - 1) * 5) / 7; + + if (numWorkers < 1) numWorkers = 1; + if (numWorkers > 32) numWorkers = 32; + + if (m_device->config().numCompilerThreads > 0) + numWorkers = m_device->config().numCompilerThreads; + + Logger::info(str::format("DXVK: Using ", numWorkers, " compiler threads")); + + // Start the worker threads and the file writer + m_workerBusy.store(numWorkers); + + for (uint32_t i = 0; i < numWorkers; i++) { + m_workerThreads.emplace_back([this] () { workerFunc(); }); + m_workerThreads[i].set_priority(ThreadPriority::Lowest); + } + } + } + + + void DxvkStateCache::createWriter() { + if (!m_writerThread.joinable()) + m_writerThread = dxvk::thread([this] () { writerFunc(); }); + } + + std::wstring DxvkStateCache::getCacheFileName() const { std::string path = getCacheDir(); diff --git a/src/dxvk/dxvk_state_cache.h b/src/dxvk/dxvk_state_cache.h index a94dbd0e..f23c85f0 100644 --- a/src/dxvk/dxvk_state_cache.h +++ b/src/dxvk/dxvk_state_cache.h @@ -28,7 +28,7 @@ namespace dxvk { public: DxvkStateCache( - const DxvkDevice* device, + DxvkDevice* device, DxvkPipelineManager* pipeManager, DxvkRenderPassPool* passManager); @@ -93,6 +93,7 @@ namespace dxvk { DxvkComputePipelineShaders cp; }; + DxvkDevice* m_device; DxvkPipelineManager* m_pipeManager; DxvkRenderPassPool* m_passManager; @@ -181,6 +182,10 @@ namespace dxvk { void writerFunc(); + void createWorkers(); + + void createWriter(); + std::wstring getCacheFileName() const; std::string getCacheDir() const;