mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-13 07:08:50 +01:00
[dxvk] Create state cache threads on demand
This commit is contained in:
parent
279b4b7ec2
commit
9e5c61bf88
@ -5,7 +5,7 @@
|
||||
namespace dxvk {
|
||||
|
||||
DxvkPipelineManager::DxvkPipelineManager(
|
||||
const DxvkDevice* device,
|
||||
DxvkDevice* device,
|
||||
DxvkRenderPassPool* passManager)
|
||||
: m_device (device),
|
||||
m_cache (new DxvkPipelineCache(device->vkd())) {
|
||||
|
@ -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<DxvkPipelineCache> m_cache;
|
||||
Rc<DxvkStateCache> m_stateCache;
|
||||
|
||||
|
@ -150,10 +150,11 @@ namespace dxvk {
|
||||
|
||||
|
||||
DxvkStateCache::DxvkStateCache(
|
||||
const DxvkDevice* device,
|
||||
DxvkDevice* device,
|
||||
DxvkPipelineManager* pipeManager,
|
||||
DxvkRenderPassPool* passManager)
|
||||
: m_pipeManager(pipeManager),
|
||||
: m_device (device),
|
||||
m_pipeManager (pipeManager),
|
||||
m_passManager (passManager) {
|
||||
bool newFile = !readCacheFile();
|
||||
|
||||
@ -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,6 +301,7 @@ namespace dxvk {
|
||||
for (auto& worker : m_workerThreads)
|
||||
worker.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();
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user