From 87f59b18cf438fb468c64363d95f94dc5c86314a Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Tue, 8 Mar 2022 16:56:50 +0200 Subject: [PATCH] anv: don't lazy allocate surface states in descriptor sets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 4001d9ce1a6e we started lazily allocating surface states in the descriptor sets rather than upfront in the descriptor pool. This was to workaround vkd3d-proton allocating more than we could handle at the HW level. The issue introduced in that change is that we didn't protect the descriptor pool free list as well as the anv_state_stream which are now potentially used from different threads through the descriptor set write functions. This reverts the lazy allocation part of that change. Host only descriptor sets changes remain. Signed-off-by: Lionel Landwerlin Fixes: 4001d9ce1a6e ("anv: Handle VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_VALVE for descriptor sets") Reviewed-by: Rohan Garg Reviewed-by: Tapani Pälli Part-of: --- src/intel/vulkan/anv_descriptor_set.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c index 22d6dc5a906..733cea867ba 100644 --- a/src/intel/vulkan/anv_descriptor_set.c +++ b/src/intel/vulkan/anv_descriptor_set.c @@ -1230,9 +1230,11 @@ anv_descriptor_set_create(struct anv_device *device, /* Allocate null surface state for the buffer views since * we lazy allocate this in the write anyway. */ - for (uint32_t b = 0; b < set->buffer_view_count; b++) { - set->buffer_views[b].surface_state = ANV_STATE_NULL; - set->buffer_views[b].range = 0; + if (pool->allocate_surface_states) { + for (uint32_t b = 0; b < set->buffer_view_count; b++) { + set->buffer_views[b].surface_state = + anv_descriptor_pool_alloc_state(pool); + } } list_addtail(&set->pool_link, &pool->desc_sets); @@ -1257,9 +1259,11 @@ anv_descriptor_set_destroy(struct anv_device *device, anv_descriptor_pool_free_state(pool, set->desc_surface_state); } - for (uint32_t b = 0; b < set->buffer_view_count; b++) { - if (set->buffer_views[b].surface_state.alloc_size) - anv_descriptor_pool_free_state(pool, set->buffer_views[b].surface_state); + if (pool->allocate_surface_states) { + for (uint32_t b = 0; b < set->buffer_view_count; b++) { + if (set->buffer_views[b].surface_state.alloc_size) + anv_descriptor_pool_free_state(pool, set->buffer_views[b].surface_state); + } } list_del(&set->pool_link); @@ -1637,10 +1641,10 @@ anv_descriptor_set_write_buffer(struct anv_device *device, * vkAllocateDescriptorSets. */ if (alloc_stream) { bview->surface_state = anv_state_stream_alloc(alloc_stream, 64, 64); - } else if (bview->surface_state.alloc_size == 0) { - bview->surface_state = anv_descriptor_pool_alloc_state(set->pool); } + assert(bview->surface_state.alloc_size); + isl_surf_usage_flags_t usage = (type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ?