vkd3d: Use rwlock instead of spinlock in PSO fallback cache.

If we defer SPIR-V compilation we risk holding the lock for quite a long
time.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
This commit is contained in:
Hans-Kristian Arntzen 2022-03-21 13:54:09 +01:00
parent 191214899d
commit 3a1e6de93d
2 changed files with 14 additions and 5 deletions

View File

@ -1971,6 +1971,7 @@ void d3d12_pipeline_state_dec_ref(struct d3d12_pipeline_state *state)
if (state->vk_bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) if (state->vk_bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS)
d3d12_pipeline_state_free_cached_desc(&state->graphics.cached_desc); d3d12_pipeline_state_free_cached_desc(&state->graphics.cached_desc);
rwlock_destroy(&state->lock);
vkd3d_free(state); vkd3d_free(state);
} }
} }
@ -3759,6 +3760,12 @@ HRESULT d3d12_pipeline_state_create(struct d3d12_device *device, VkPipelineBindP
memset(object, 0, sizeof(*object)); memset(object, 0, sizeof(*object));
if (rwlock_init(&object->lock))
{
vkd3d_free(object);
return E_FAIL;
}
if (!desc->root_signature) if (!desc->root_signature)
{ {
if (FAILED(hr = d3d12_pipeline_create_private_root_signature(device, if (FAILED(hr = d3d12_pipeline_create_private_root_signature(device,
@ -3788,6 +3795,7 @@ HRESULT d3d12_pipeline_state_create(struct d3d12_device *device, VkPipelineBindP
{ {
if (object->root_signature) if (object->root_signature)
d3d12_root_signature_dec_ref(object->root_signature); d3d12_root_signature_dec_ref(object->root_signature);
rwlock_destroy(&object->lock);
vkd3d_free(object); vkd3d_free(object);
return hr; return hr;
} }
@ -3837,6 +3845,7 @@ HRESULT d3d12_pipeline_state_create(struct d3d12_device *device, VkPipelineBindP
if (object->vk_bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) if (object->vk_bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS)
d3d12_pipeline_state_free_cached_desc(&object->graphics.cached_desc); d3d12_pipeline_state_free_cached_desc(&object->graphics.cached_desc);
VK_CALL(vkDestroyPipelineCache(device->vk_device, object->vk_pso_cache, NULL)); VK_CALL(vkDestroyPipelineCache(device->vk_device, object->vk_pso_cache, NULL));
rwlock_destroy(&object->lock);
vkd3d_free(object); vkd3d_free(object);
return hr; return hr;
@ -3978,7 +3987,7 @@ static VkPipeline d3d12_pipeline_state_find_compiled_pipeline(struct d3d12_pipel
struct vkd3d_compiled_pipeline *current; struct vkd3d_compiled_pipeline *current;
VkPipeline vk_pipeline = VK_NULL_HANDLE; VkPipeline vk_pipeline = VK_NULL_HANDLE;
rw_spinlock_acquire_read(&state->lock); rwlock_lock_read(&state->lock);
LIST_FOR_EACH_ENTRY(current, &graphics->compiled_fallback_pipelines, struct vkd3d_compiled_pipeline, entry) LIST_FOR_EACH_ENTRY(current, &graphics->compiled_fallback_pipelines, struct vkd3d_compiled_pipeline, entry)
{ {
if (!memcmp(&current->key, key, sizeof(*key))) if (!memcmp(&current->key, key, sizeof(*key)))
@ -3988,7 +3997,7 @@ static VkPipeline d3d12_pipeline_state_find_compiled_pipeline(struct d3d12_pipel
break; break;
} }
} }
rw_spinlock_release_read(&state->lock); rwlock_unlock_read(&state->lock);
return vk_pipeline; return vk_pipeline;
} }
@ -4006,7 +4015,7 @@ static bool d3d12_pipeline_state_put_pipeline_to_cache(struct d3d12_pipeline_sta
compiled_pipeline->vk_pipeline = vk_pipeline; compiled_pipeline->vk_pipeline = vk_pipeline;
compiled_pipeline->dynamic_state_flags = dynamic_state_flags; compiled_pipeline->dynamic_state_flags = dynamic_state_flags;
rw_spinlock_acquire_write(&state->lock); rwlock_lock_write(&state->lock);
LIST_FOR_EACH_ENTRY(current, &graphics->compiled_fallback_pipelines, struct vkd3d_compiled_pipeline, entry) LIST_FOR_EACH_ENTRY(current, &graphics->compiled_fallback_pipelines, struct vkd3d_compiled_pipeline, entry)
{ {
@ -4021,7 +4030,7 @@ static bool d3d12_pipeline_state_put_pipeline_to_cache(struct d3d12_pipeline_sta
if (compiled_pipeline) if (compiled_pipeline)
list_add_tail(&graphics->compiled_fallback_pipelines, &compiled_pipeline->entry); list_add_tail(&graphics->compiled_fallback_pipelines, &compiled_pipeline->entry);
rw_spinlock_release_write(&state->lock); rwlock_unlock_write(&state->lock);
return compiled_pipeline; return compiled_pipeline;
} }

View File

@ -1554,7 +1554,7 @@ struct d3d12_pipeline_state
}; };
VkPipelineBindPoint vk_bind_point; VkPipelineBindPoint vk_bind_point;
VkPipelineCache vk_pso_cache; VkPipelineCache vk_pso_cache;
spinlock_t lock; rwlock_t lock;
struct vkd3d_pipeline_cache_compatibility pipeline_cache_compat; struct vkd3d_pipeline_cache_compatibility pipeline_cache_compat;
struct d3d12_root_signature *root_signature; struct d3d12_root_signature *root_signature;