[dxvk] Simplify pipeline object locking

Any more complex approach is not very useful at the moment
because we have to put a lock around the actual compile
function anyway.
This commit is contained in:
Philip Rebohle 2018-09-25 18:22:58 +02:00
parent 0be291e123
commit 8bcd47d6dc
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 22 additions and 56 deletions

View File

@ -48,34 +48,18 @@ namespace dxvk {
VkPipeline DxvkComputePipeline::getPipelineHandle(
const DxvkComputePipelineStateInfo& state) {
VkPipeline pipeline = VK_NULL_HANDLE;
{ std::lock_guard<sync::Spinlock> lock(m_mutex);
if (this->findPipeline(state, pipeline))
return pipeline;
}
// If no pipeline instance exists with the given state
// vector, create a new one and add it to the list.
VkPipeline newPipelineBase = m_basePipeline.load();
VkPipeline newPipelineBase = VK_NULL_HANDLE;
VkPipeline newPipelineHandle = VK_NULL_HANDLE;
// FIXME for some reason, compiling the exact
// same pipeline crashes inside driver code
{ std::lock_guard<sync::Spinlock> lock(m_mutex);
newPipelineHandle = this->compilePipeline(
state, newPipelineBase);
}
if (this->findPipeline(state, newPipelineHandle))
return newPipelineHandle;
{ std::lock_guard<sync::Spinlock> lock(m_mutex);
// Discard the pipeline if another thread
// was faster compiling the same pipeline
if (this->findPipeline(state, pipeline)) {
this->destroyPipeline(newPipelineHandle);
return pipeline;
}
// If no pipeline instance exists with the given state
// vector, create a new one and add it to the list.
newPipelineBase = m_basePipeline.load();
newPipelineHandle = this->compilePipeline(state, newPipelineBase);
// Add new pipeline to the set
m_pipelines.push_back({ state, newPipelineHandle });

View File

@ -85,45 +85,27 @@ namespace dxvk {
const DxvkGraphicsPipelineStateInfo& state,
const DxvkRenderPass& renderPass) {
VkRenderPass renderPassHandle = renderPass.getDefaultHandle();
VkPipeline newPipelineBase = VK_NULL_HANDLE;
VkPipeline newPipelineHandle = VK_NULL_HANDLE;
{ std::lock_guard<sync::Spinlock> lock(m_mutex);
const DxvkGraphicsPipelineInstance* instance =
this->findInstance(state, renderPassHandle);
auto instance = this->findInstance(state, renderPassHandle);
if (instance != nullptr)
return instance->pipeline();
}
// If the pipeline state vector is invalid, don't try
// to create a new pipeline, it won't work anyway.
if (!this->validatePipelineState(state))
return VK_NULL_HANDLE;
// If no pipeline instance exists with the given state
// vector, create a new one and add it to the list.
VkPipeline newPipelineBase = m_basePipeline.load();
VkPipeline newPipelineHandle = VK_NULL_HANDLE;
// FIXME for some reason, compiling the exact
// same pipeline crashes inside driver code
{ std::lock_guard<sync::Spinlock> lock(m_mutex);
newPipelineHandle = this->compilePipeline(
state, renderPassHandle, newPipelineBase);
}
// If the pipeline state vector is invalid, don't try
// to create a new pipeline, it won't work anyway.
if (!this->validatePipelineState(state))
return VK_NULL_HANDLE;
// If no pipeline instance exists with the given state
// vector, create a new one and add it to the list.
newPipelineBase = m_basePipeline.load();
newPipelineHandle = this->compilePipeline(state, renderPassHandle, newPipelineBase);
{ std::lock_guard<sync::Spinlock> lock(m_mutex);
// Discard the pipeline if another thread
// was faster compiling the same pipeline
const DxvkGraphicsPipelineInstance* instance =
this->findInstance(state, renderPassHandle);
if (instance != nullptr) {
this->destroyPipeline(newPipelineHandle);
return instance->pipeline();
}
// Add new pipeline to the set
m_pipelines.emplace_back(state, renderPassHandle, newPipelineHandle);
m_pipeMgr->m_numGraphicsPipelines += 1;