diff --git a/.pick_status.json b/.pick_status.json index 5167944856e..727b532ea7d 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2354,7 +2354,7 @@ "description": "anv/sparse: replace device->using_sparse with device->num_sparse_resources", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "6368c1445f44e3c05b399d9e279d36a79a1a6bcc", "notes": null diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index 0dfdd582a4b..75f696cb1e7 100644 --- a/src/intel/vulkan/anv_batch_chain.c +++ b/src/intel/vulkan/anv_batch_chain.c @@ -1389,8 +1389,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 a05676cb94f..b0c728b1a06 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1856,13 +1856,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 180cf7e2c5d..1357b8e5824 100644 --- a/src/intel/vulkan/anv_sparse.c +++ b/src/intel/vulkan/anv_sparse.c @@ -707,6 +707,7 @@ anv_init_sparse_bindings(struct anv_device *device, return res; } + p_atomic_inc(&device->num_sparse_resources); return VK_SUCCESS; } @@ -720,6 +721,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 c96e32a4477..65c503aadd9 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -4418,7 +4418,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; }