mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-14 00:48:44 +01:00
[dxvk] Create state cache threads on demand
This commit is contained in:
parent
279b4b7ec2
commit
9e5c61bf88
@ -5,7 +5,7 @@
|
|||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
DxvkPipelineManager::DxvkPipelineManager(
|
DxvkPipelineManager::DxvkPipelineManager(
|
||||||
const DxvkDevice* device,
|
DxvkDevice* device,
|
||||||
DxvkRenderPassPool* passManager)
|
DxvkRenderPassPool* passManager)
|
||||||
: m_device (device),
|
: m_device (device),
|
||||||
m_cache (new DxvkPipelineCache(device->vkd())) {
|
m_cache (new DxvkPipelineCache(device->vkd())) {
|
||||||
|
@ -38,7 +38,7 @@ namespace dxvk {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
DxvkPipelineManager(
|
DxvkPipelineManager(
|
||||||
const DxvkDevice* device,
|
DxvkDevice* device,
|
||||||
DxvkRenderPassPool* passManager);
|
DxvkRenderPassPool* passManager);
|
||||||
|
|
||||||
~DxvkPipelineManager();
|
~DxvkPipelineManager();
|
||||||
@ -97,7 +97,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const DxvkDevice* m_device;
|
DxvkDevice* m_device;
|
||||||
Rc<DxvkPipelineCache> m_cache;
|
Rc<DxvkPipelineCache> m_cache;
|
||||||
Rc<DxvkStateCache> m_stateCache;
|
Rc<DxvkStateCache> m_stateCache;
|
||||||
|
|
||||||
|
@ -150,11 +150,12 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
DxvkStateCache::DxvkStateCache(
|
DxvkStateCache::DxvkStateCache(
|
||||||
const DxvkDevice* device,
|
DxvkDevice* device,
|
||||||
DxvkPipelineManager* pipeManager,
|
DxvkPipelineManager* pipeManager,
|
||||||
DxvkRenderPassPool* passManager)
|
DxvkRenderPassPool* passManager)
|
||||||
: m_pipeManager(pipeManager),
|
: m_device (device),
|
||||||
m_passManager(passManager) {
|
m_pipeManager (pipeManager),
|
||||||
|
m_passManager (passManager) {
|
||||||
bool newFile = !readCacheFile();
|
bool newFile = !readCacheFile();
|
||||||
|
|
||||||
if (newFile) {
|
if (newFile) {
|
||||||
@ -184,28 +185,6 @@ namespace dxvk {
|
|||||||
for (auto& e : m_entries)
|
for (auto& e : m_entries)
|
||||||
writeCacheEntry(file, e);
|
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(),
|
DxvkComputePipelineStateInfo(),
|
||||||
format, g_nullHash });
|
format, g_nullHash });
|
||||||
m_writerCond.notify_one();
|
m_writerCond.notify_one();
|
||||||
|
|
||||||
|
createWriter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -262,6 +243,8 @@ namespace dxvk {
|
|||||||
DxvkGraphicsPipelineStateInfo(), state,
|
DxvkGraphicsPipelineStateInfo(), state,
|
||||||
DxvkRenderPassFormat(), g_nullHash });
|
DxvkRenderPassFormat(), g_nullHash });
|
||||||
m_writerCond.notify_one();
|
m_writerCond.notify_one();
|
||||||
|
|
||||||
|
createWriter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -297,8 +280,10 @@ namespace dxvk {
|
|||||||
m_workerQueue.push(item);
|
m_workerQueue.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (workerLock)
|
if (workerLock) {
|
||||||
m_workerCond.notify_all();
|
m_workerCond.notify_all();
|
||||||
|
createWorkers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -316,7 +301,8 @@ namespace dxvk {
|
|||||||
for (auto& worker : m_workerThreads)
|
for (auto& worker : m_workerThreads)
|
||||||
worker.join();
|
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::wstring DxvkStateCache::getCacheFileName() const {
|
||||||
std::string path = getCacheDir();
|
std::string path = getCacheDir();
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ namespace dxvk {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
DxvkStateCache(
|
DxvkStateCache(
|
||||||
const DxvkDevice* device,
|
DxvkDevice* device,
|
||||||
DxvkPipelineManager* pipeManager,
|
DxvkPipelineManager* pipeManager,
|
||||||
DxvkRenderPassPool* passManager);
|
DxvkRenderPassPool* passManager);
|
||||||
|
|
||||||
@ -93,6 +93,7 @@ namespace dxvk {
|
|||||||
DxvkComputePipelineShaders cp;
|
DxvkComputePipelineShaders cp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DxvkDevice* m_device;
|
||||||
DxvkPipelineManager* m_pipeManager;
|
DxvkPipelineManager* m_pipeManager;
|
||||||
DxvkRenderPassPool* m_passManager;
|
DxvkRenderPassPool* m_passManager;
|
||||||
|
|
||||||
@ -181,6 +182,10 @@ namespace dxvk {
|
|||||||
|
|
||||||
void writerFunc();
|
void writerFunc();
|
||||||
|
|
||||||
|
void createWorkers();
|
||||||
|
|
||||||
|
void createWriter();
|
||||||
|
|
||||||
std::wstring getCacheFileName() const;
|
std::wstring getCacheFileName() const;
|
||||||
|
|
||||||
std::string getCacheDir() const;
|
std::string getCacheDir() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user