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 <lionel.g.landwerlin@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16571>
This commit is contained in:
Mark Janes 2022-05-16 12:52:42 -07:00 committed by Marge Bot
parent c4c096e66e
commit 34a130fedf
1 changed files with 11 additions and 15 deletions

View File

@ -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);