mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-13 07:08:50 +01:00
[dxvk] Don't keep pipeline locked when building optimized variant
Only lock when creating base variant, otherwise we'll have stutter.
This commit is contained in:
parent
cc1575e8b7
commit
7f9a04fd59
@ -566,22 +566,39 @@ namespace dxvk {
|
|||||||
|
|
||||||
void DxvkGraphicsPipeline::compilePipeline(
|
void DxvkGraphicsPipeline::compilePipeline(
|
||||||
const DxvkGraphicsPipelineStateInfo& state) {
|
const DxvkGraphicsPipelineStateInfo& state) {
|
||||||
// Exit early if the state vector is invalid
|
if (m_device->config().enableGraphicsPipelineLibrary == Tristate::True)
|
||||||
if (!this->validatePipelineState(state, false))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Keep the object locked while compiling a pipeline since compiling
|
// Try to find an existing instance that contains a base pipeline
|
||||||
// similar pipelines concurrently is fragile on some drivers
|
DxvkGraphicsPipelineInstance* instance = this->findInstance(state);
|
||||||
std::lock_guard<dxvk::mutex> lock(m_mutex);
|
|
||||||
|
|
||||||
if (!this->findInstance(state))
|
if (!instance) {
|
||||||
this->createInstance(state);
|
// Exit early if the state vector is invalid
|
||||||
|
if (!this->validatePipelineState(state, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Prevent other threads from adding new instances and check again
|
||||||
|
std::lock_guard<dxvk::mutex> lock(m_mutex);
|
||||||
|
instance = this->findInstance(state);
|
||||||
|
|
||||||
|
if (!instance)
|
||||||
|
instance = this->createInstance(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit if another thread is already compiling
|
||||||
|
// an optimized version of this pipeline
|
||||||
|
if (instance->isCompiling.load()
|
||||||
|
|| instance->isCompiling.exchange(VK_TRUE, std::memory_order_acquire))
|
||||||
|
return;
|
||||||
|
|
||||||
|
VkPipeline pipeline = this->createOptimizedPipeline(state);
|
||||||
|
instance->fastHandle.store(pipeline, std::memory_order_release);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DxvkGraphicsPipelineInstance* DxvkGraphicsPipeline::createInstance(
|
DxvkGraphicsPipelineInstance* DxvkGraphicsPipeline::createInstance(
|
||||||
const DxvkGraphicsPipelineStateInfo& state) {
|
const DxvkGraphicsPipelineStateInfo& state) {
|
||||||
VkPipeline pipeline = this->createPipeline(state);
|
VkPipeline pipeline = this->createOptimizedPipeline(state);
|
||||||
|
|
||||||
m_stats->numGraphicsPipelines += 1;
|
m_stats->numGraphicsPipelines += 1;
|
||||||
return &(*m_pipelines.emplace(state, VK_NULL_HANDLE, pipeline));
|
return &(*m_pipelines.emplace(state, VK_NULL_HANDLE, pipeline));
|
||||||
@ -599,7 +616,7 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VkPipeline DxvkGraphicsPipeline::createPipeline(
|
VkPipeline DxvkGraphicsPipeline::createOptimizedPipeline(
|
||||||
const DxvkGraphicsPipelineStateInfo& state) const {
|
const DxvkGraphicsPipelineStateInfo& state) const {
|
||||||
auto vk = m_device->vkd();
|
auto vk = m_device->vkd();
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ namespace dxvk {
|
|||||||
DxvkGraphicsPipelineInstance* findInstance(
|
DxvkGraphicsPipelineInstance* findInstance(
|
||||||
const DxvkGraphicsPipelineStateInfo& state);
|
const DxvkGraphicsPipelineStateInfo& state);
|
||||||
|
|
||||||
VkPipeline createPipeline(
|
VkPipeline createOptimizedPipeline(
|
||||||
const DxvkGraphicsPipelineStateInfo& state) const;
|
const DxvkGraphicsPipelineStateInfo& state) const;
|
||||||
|
|
||||||
void destroyPipeline(
|
void destroyPipeline(
|
||||||
|
Loading…
Reference in New Issue
Block a user