From 34a130fedf0abe1596891e85df48fb2b208385ed Mon Sep 17 00:00:00 2001 From: Mark Janes Date: Mon, 16 May 2022 12:52:42 -0700 Subject: [PATCH] anv: fix performance bug in INTEL_MEASURE Re-allocating the buffer object for snapshots carries a heavy penalty at run-time. When resetting a command buffer, the buffer object that is allocated for snapshots may be re-used directly on subsequent renders. Stale snapshot data will persist in the buffer object. To verify that rendering is complete, zero the final timestamp value and check that it has been written before gathering data. Reviewed-by: Lionel Landwerlin Reviewed-by: Kenneth Graunke Part-of: --- src/intel/vulkan/anv_measure.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/intel/vulkan/anv_measure.c b/src/intel/vulkan/anv_measure.c index 2b2e9b672f8..7b82926a5dd 100644 --- a/src/intel/vulkan/anv_measure.c +++ b/src/intel/vulkan/anv_measure.c @@ -332,16 +332,6 @@ anv_measure_reset(struct anv_cmd_buffer *cmd_buffer) measure->base.frame = 0; measure->base.event_count = 0; list_inithead(&measure->base.link); - - anv_device_release_bo(device, measure->bo); - ASSERTED VkResult result = - anv_device_alloc_bo(device, "measure data", - config->batch_size * sizeof(uint64_t), - ANV_BO_ALLOC_MAPPED, - 0, - (struct anv_bo**)&measure->bo); - measure->base.timestamps = measure->bo->map; - assert(result == VK_SUCCESS); } void @@ -403,19 +393,25 @@ _anv_measure_submit(struct anv_cmd_buffer *cmd_buffer) if (measure == NULL) return; - if (measure->base.index == 0) + struct intel_measure_batch *base = &measure->base; + if (base->index == 0) /* no snapshots were started */ return; /* finalize snapshots and enqueue them */ static unsigned cmd_buffer_count = 0; - measure->base.batch_count = p_atomic_inc_return(&cmd_buffer_count); + base->batch_count = p_atomic_inc_return(&cmd_buffer_count); - if (measure->base.index %2 == 1) { - anv_measure_end_snapshot(cmd_buffer, measure->base.event_count); - measure->base.event_count = 0; + if (base->index %2 == 1) { + anv_measure_end_snapshot(cmd_buffer, base->event_count); + base->event_count = 0; } + /* Mark the final timestamp as 'not completed'. This marker will be used + * to verify that rendering is complete. + */ + base->timestamps[base->index - 1] = 0; + /* add to the list of submitted snapshots */ pthread_mutex_lock(&measure_device->mutex); list_addtail(&measure->base.link, &measure_device->queued_snapshots);