anv: Slow clear if fast-clear cost is not mitigated

Fast-clears require expensive flushes beforehand and afterwards. The
cost of flushes are decreased in a series of back-to-back fast-clears as
no extra fast-clear flushes are required in between them. If the ratio
of a command buffer's recorded back-to-back fast clears over independent
fast-clears falls below 1/2, prevent that command buffer from recording
any further fast-clears.

Averaging two runs of our Factorio trace on an A750 shows a +14.37%
improvement in FPS.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32984>
This commit is contained in:
Nanley Chery 2025-01-10 09:27:15 -05:00 committed by Marge Bot
parent 24107f2f67
commit 052d7e1a9c
3 changed files with 20 additions and 0 deletions

View file

@ -3564,6 +3564,14 @@ anv_can_fast_clear_color(const struct anv_cmd_buffer *cmd_buffer,
return false; return false;
} }
if (cmd_buffer->num_independent_clears >= 16 &&
cmd_buffer->num_independent_clears >
cmd_buffer->num_dependent_clears * 2) {
anv_perf_warn(VK_LOG_OBJS(&image->vk.base),
"Not enough back-to-back fast-clears. Slow clearing.");
return false;
}
return true; return true;
} }

View file

@ -4249,6 +4249,10 @@ struct anv_cmd_buffer {
struct anv_cmd_state state; struct anv_cmd_state state;
/* Fast-clear statistics. */
uint64_t num_dependent_clears;
uint64_t num_independent_clears;
struct anv_address return_addr; struct anv_address return_addr;
/* Set by SetPerformanceMarkerINTEL, written into queries by CmdBeginQuery */ /* Set by SetPerformanceMarkerINTEL, written into queries by CmdBeginQuery */

View file

@ -3108,6 +3108,14 @@ genX(cmd_buffer_update_color_aux_op)(struct anv_cmd_buffer *cmd_buffer,
} else { } else {
cmd_buffer->state.color_aux_op = next_aux_op; cmd_buffer->state.color_aux_op = next_aux_op;
} }
if (next_aux_op == ISL_AUX_OP_FAST_CLEAR) {
if (aux_op_clears(last_aux_op)) {
cmd_buffer->num_dependent_clears++;
} else {
cmd_buffer->num_independent_clears++;
}
}
} }
static void static void