vkd3d: Add VKD3D_CONFIG option for command pool recycling.

Normal behaving apps should not benefit from any of this.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
This commit is contained in:
Hans-Kristian Arntzen 2022-02-25 12:08:20 +01:00
parent 54fbadcc94
commit c19eaac376
3 changed files with 36 additions and 26 deletions

View File

@ -84,6 +84,7 @@ enum vkd3d_config_flags
VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_IGNORE_SPIRV = 0x00200000,
VKD3D_CONFIG_FLAG_MUTABLE_SINGLE_SET = 0x00400000,
VKD3D_CONFIG_FLAG_MEMORY_ALLOCATOR_SKIP_CLEAR = 0x00800000,
VKD3D_CONFIG_FLAG_RECYCLE_COMMAND_POOLS = 0x01000000,
};
typedef HRESULT (*PFN_vkd3d_signal_event)(HANDLE event);

View File

@ -1587,6 +1587,10 @@ static ULONG STDMETHODCALLTYPE d3d12_command_allocator_Release(ID3D12CommandAllo
vkd3d_free(allocator->framebuffers);
vkd3d_free(allocator->passes);
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_RECYCLE_COMMAND_POOLS)
{
/* Don't want to do this unless we have to, so hide it behind a config.
* For well-behaving apps, we'll just bloat memory. */
if (pthread_mutex_lock(&device->mutex) == 0)
{
if (device->cached_command_allocator_count < ARRAY_SIZE(device->cached_command_allocators))
@ -1610,6 +1614,7 @@ static ULONG STDMETHODCALLTYPE d3d12_command_allocator_Release(ID3D12CommandAllo
pthread_mutex_unlock(&device->mutex);
}
}
/* Command buffers are implicitly freed when destroying the pool. */
vkd3d_free(allocator->command_buffers);
@ -1843,6 +1848,8 @@ static HRESULT d3d12_command_allocator_init(struct d3d12_command_allocator *allo
allocator->vk_command_pool = VK_NULL_HANDLE;
allocator->vk_family_index = queue_family->vk_family_index;
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_RECYCLE_COMMAND_POOLS)
{
/* Try to recycle command allocators. Some games spam free/allocate pools. */
if (pthread_mutex_lock(&device->mutex) == 0)
{
@ -1858,6 +1865,7 @@ static HRESULT d3d12_command_allocator_init(struct d3d12_command_allocator *allo
}
pthread_mutex_unlock(&device->mutex);
}
}
if (allocator->vk_command_pool == VK_NULL_HANDLE)
{

View File

@ -611,6 +611,7 @@ static const struct vkd3d_debug_option vkd3d_config_options[] =
{"pipeline_library_ignore_spirv", VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_IGNORE_SPIRV},
{"mutable_single_set", VKD3D_CONFIG_FLAG_MUTABLE_SINGLE_SET},
{"memory_allocator_skip_clear", VKD3D_CONFIG_FLAG_MEMORY_ALLOCATOR_SKIP_CLEAR},
{"recycle_command_pools", VKD3D_CONFIG_FLAG_RECYCLE_COMMAND_POOLS},
};
static void vkd3d_config_flags_init_once(void)