diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index 4117481006c..bb986847a08 100644 --- a/src/intel/vulkan/anv_batch_chain.c +++ b/src/intel/vulkan/anv_batch_chain.c @@ -1394,8 +1394,6 @@ anv_queue_submit_sparse_bind_locked(struct anv_queue *queue, return vk_queue_set_lost(&queue->vk, "Sparse binding not supported"); } - device->using_sparse = true; - assert(submit->command_buffer_count == 0); if (INTEL_DEBUG(DEBUG_SPARSE)) { diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 641330f11c4..049c2edfd3c 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1968,13 +1968,13 @@ struct anv_device { struct list_head in_flight_batches; } trtt; - /* This is true if the user ever bound a sparse resource to memory. This - * is used for a workaround that makes every memoryBarrier flush more - * things than it should. Many applications request for the sparse - * featuers to be enabled but don't use them, and some create sparse - * resources but never use them. + /* Number of sparse resources that currently exist. This is used for a + * workaround that makes every memoryBarrier flush more things than it + * should. Some workloads create and then immediately destroy sparse + * resources when they start, so just counting if a sparse resource was + * ever created is not enough. */ - bool using_sparse; + uint32_t num_sparse_resources; struct anv_device_astc_emu astc_emu; diff --git a/src/intel/vulkan/anv_sparse.c b/src/intel/vulkan/anv_sparse.c index 1bd403cee0c..a4fa29462f4 100644 --- a/src/intel/vulkan/anv_sparse.c +++ b/src/intel/vulkan/anv_sparse.c @@ -654,6 +654,7 @@ anv_init_sparse_bindings(struct anv_device *device, return res; } + p_atomic_inc(&device->num_sparse_resources); return VK_SUCCESS; } @@ -667,6 +668,8 @@ anv_free_sparse_bindings(struct anv_device *device, sparse_debug("%s: address:0x%016"PRIx64" size:0x%08"PRIx64"\n", __func__, sparse->address, sparse->size); + p_atomic_dec(&device->num_sparse_resources); + struct anv_vm_bind unbind = { .bo = 0, .address = sparse->address, diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index ca5ad262a30..eed57513cf9 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -3939,7 +3939,8 @@ cmd_buffer_barrier(struct anv_cmd_buffer *cmd_buffer, /* There's no way of knowing if this memory barrier is related to sparse * buffers! This is pretty horrible. */ - if (device->using_sparse && mask_is_write(src_flags)) + if (mask_is_write(src_flags) && + p_atomic_read(&device->num_sparse_resources) > 0) apply_sparse_flushes = true; }