From 4cd7976208bbad2701d9ce82a3990966adfcae18 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Thu, 16 Feb 2023 10:39:47 -0800 Subject: [PATCH] anv: Fix gfx8/9 VB range > 32bits workaround detection. Since the dirty range started out as 0..0, you would have 0..VBend as the new dirty range on the first draw, and if your VB was >32b then you'd flush every time you used it. Instead, if there's no existing dirty range then just set it to our new VB's range. Perf results with zink+anv on my CFL: sauerbraten: +24.8182% +/- 0.602077% (n=5) portal-2-v2.trace: +4.64289% +/- 0.285285% (n=5) Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_private.h | 16 +++++++++++++--- src/intel/vulkan/genX_cmd_buffer.c | 10 ++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index d98cf8d8f8a..94ea83e7625 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -2452,6 +2452,18 @@ struct anv_vb_cache_range { uint64_t end; }; +static inline void +anv_merge_vb_cache_range(struct anv_vb_cache_range *dirty, + const struct anv_vb_cache_range *bound) +{ + if (dirty->start == dirty->end) { + *dirty = *bound; + } else if (bound->start != bound->end) { + dirty->start = MIN2(dirty->start, bound->start); + dirty->end = MAX2(dirty->end, bound->end); + } +} + /* Check whether we need to apply the Gfx8-9 vertex buffer workaround*/ static inline bool anv_gfx8_9_vb_cache_range_needs_workaround(struct anv_vb_cache_range *bound, @@ -2474,9 +2486,7 @@ anv_gfx8_9_vb_cache_range_needs_workaround(struct anv_vb_cache_range *bound, bound->start &= ~(64ull - 1ull); bound->end = align64(bound->end, 64); - /* Compute the dirty range */ - dirty->start = MIN2(dirty->start, bound->start); - dirty->end = MAX2(dirty->end, bound->end); + anv_merge_vb_cache_range(dirty, bound); /* If our range is larger than 32 bits, we have to flush */ assert(bound->end - bound->start <= (1ull << 32)); diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index 12674d7ca05..3a7eb7a0a26 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -6657,10 +6657,7 @@ genX(cmd_buffer_update_dirty_vbs_for_gfx8_vb_flush)(struct anv_cmd_buffer *cmd_b struct anv_vb_cache_range *bound = &cmd_buffer->state.gfx.ib_bound_range; struct anv_vb_cache_range *dirty = &cmd_buffer->state.gfx.ib_dirty_range; - if (bound->end > bound->start) { - dirty->start = MIN2(dirty->start, bound->start); - dirty->end = MAX2(dirty->end, bound->end); - } + anv_merge_vb_cache_range(dirty, bound); } uint64_t mask = vb_used; @@ -6674,10 +6671,7 @@ genX(cmd_buffer_update_dirty_vbs_for_gfx8_vb_flush)(struct anv_cmd_buffer *cmd_b bound = &cmd_buffer->state.gfx.vb_bound_ranges[i]; dirty = &cmd_buffer->state.gfx.vb_dirty_ranges[i]; - if (bound->end > bound->start) { - dirty->start = MIN2(dirty->start, bound->start); - dirty->end = MAX2(dirty->end, bound->end); - } + anv_merge_vb_cache_range(dirty, bound); } } #endif /* GFX_VER == 9 */