From acebea9cf1f8ce2e71f6cd3404d3a2760a2efc66 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Mon, 17 Jan 2022 14:02:30 +0200 Subject: [PATCH] anv: fix missing descriptor copy of bufferview/surfacestate content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When doing copies of descriptors from one set to another, that contain either a UNIFORM_BUFFER or STORAGE_BUFFER, both the buffer view & surface state are allocated from the source descriptor. Therefore we need to copy their content otherwise we could run into lifecycle issues when the source descriptor is destroyed. Signed-off-by: Lionel Landwerlin Cc: mesa-stable Reviewed-by: Tapani Pälli Part-of: --- src/intel/vulkan/anv_descriptor_set.c | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c index 401fabcdae3..6be068d0b70 100644 --- a/src/intel/vulkan/anv_descriptor_set.c +++ b/src/intel/vulkan/anv_descriptor_set.c @@ -1702,8 +1702,36 @@ void anv_UpdateDescriptorSets( copy->srcArrayElement, copy->descriptorCount); } else { - for (uint32_t j = 0; j < copy->descriptorCount; j++) - dst_desc[j] = src_desc[j]; + struct anv_buffer_view *dst_bview = + &dst->buffer_views[dst_layout->buffer_view_index + + copy->dstArrayElement]; + struct anv_buffer_view *src_bview = + &src->buffer_views[src_layout->buffer_view_index + + copy->srcArrayElement]; + /* If ANV_DESCRIPTOR_BUFFER_VIEW is present in the source descriptor, + * it means we're using an anv_buffer_view allocated by the source + * descriptor set. In that case we want to careful copy it because + * his lifecycle is tied to the source descriptor set, not the + * destination descriptor set. + */ + if (src_layout->data & ANV_DESCRIPTOR_BUFFER_VIEW) { + assert(dst_layout->data & ANV_DESCRIPTOR_BUFFER_VIEW); + for (uint32_t j = 0; j < copy->descriptorCount; j++) { + dst_bview[j].format = src_bview[j].format; + dst_bview[j].range = src_bview[j].range; + dst_bview[j].address = src_bview[j].address; + + memcpy(dst_bview[j].surface_state.map, + src_bview[j].surface_state.map, + src_bview[j].surface_state.alloc_size); + + dst_desc[j].type = src_desc[j].type; + dst_desc[j].buffer_view = &dst_bview[j]; + } + } else { + for (uint32_t j = 0; j < copy->descriptorCount; j++) + dst_desc[j] = src_desc[j]; + } unsigned desc_size = anv_descriptor_size(src_layout); if (desc_size > 0) {