asahi: optimize aligned blits

we can optimize out a lot of logic in this (common) case.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30981>
This commit is contained in:
Alyssa Rosenzweig
2024-08-12 20:37:01 -04:00
committed by Marge Bot
parent 93785ae2fb
commit bcddf041eb
2 changed files with 33 additions and 25 deletions
+32 -25
View File
@@ -103,9 +103,14 @@ asahi_blit_compute_shader(struct pipe_context *ctx, struct asahi_blit_key *key)
nir_vector_insert_imm(b, nir_pad_vector(b, image_pos_nd, 3), layer, 2);
}
nir_def *in_bounds = nir_ige(b, logical_id_el_2d, nir_imm_ivec2(b, 0, 0));
in_bounds =
nir_iand(b, in_bounds, nir_ilt(b, logical_id_el_2d, dimensions_el_2d));
nir_def *in_bounds;
if (key->aligned) {
in_bounds = nir_imm_true(b);
} else {
in_bounds = nir_ige(b, logical_id_el_2d, nir_imm_ivec2(b, 0, 0));
in_bounds =
nir_iand(b, in_bounds, nir_ilt(b, logical_id_el_2d, dimensions_el_2d));
}
nir_def *colour0, *colour1;
nir_push_if(b, nir_ball(b, in_bounds));
@@ -328,14 +333,33 @@ asahi_compute_blit(struct pipe_context *ctx, const struct pipe_blit_info *info,
struct pipe_resource *src = info->src.resource;
struct pipe_resource *dst = info->dst.resource;
struct pipe_sampler_view src_templ = {0}, *src_view;
unsigned width = info->dst.box.width;
unsigned height = info->dst.box.height;
float src_width = (float)u_minify(src->width0, info->src.level);
float src_height = (float)u_minify(src->height0, info->src.level);
float x_scale = (info->src.box.width / (float)width) / src_width;
float y_scale = (info->src.box.height / (float)height) / src_height;
float x_scale =
(info->src.box.width / (float)info->dst.box.width) / src_width;
float y_scale =
(info->src.box.height / (float)info->dst.box.height) / src_height;
/* Expand the grid so destinations are in tiles */
unsigned expanded_x0 = info->dst.box.x & ~(TILE_WIDTH - 1);
unsigned expanded_y0 = info->dst.box.y & ~(TILE_HEIGHT - 1);
unsigned expanded_x1 =
align(info->dst.box.x + info->dst.box.width, TILE_WIDTH);
unsigned expanded_y1 =
align(info->dst.box.y + info->dst.box.height, TILE_HEIGHT);
/* But clamp to the destination size to save some redundant threads */
expanded_x1 =
MIN2(expanded_x1, u_minify(info->dst.resource->width0, info->dst.level));
expanded_y1 =
MIN2(expanded_y1, u_minify(info->dst.resource->height0, info->dst.level));
/* Calculate the width/height based on the expanded grid */
unsigned width = expanded_x1 - expanded_x0;
unsigned height = expanded_y1 - expanded_y0;
unsigned data[] = {
fui(0.5f * x_scale + (float)info->src.box.x / src_width),
@@ -404,6 +428,7 @@ asahi_compute_blit(struct pipe_context *ctx, const struct pipe_blit_info *info,
.src_format = info->src.format,
.dst_format = info->dst.format,
.array = array,
.aligned = info->dst.box.width == width && info->dst.box.height == height,
};
struct hash_entry *ent = _mesa_hash_table_search(blitter->blit_cs, &key);
void *cs = NULL;
@@ -420,24 +445,6 @@ asahi_compute_blit(struct pipe_context *ctx, const struct pipe_blit_info *info,
assert(cs != NULL);
ctx->bind_compute_state(ctx, cs);
/* Expand the grid so destinations are in tiles */
unsigned expanded_x0 = info->dst.box.x & ~(TILE_WIDTH - 1);
unsigned expanded_y0 = info->dst.box.y & ~(TILE_HEIGHT - 1);
unsigned expanded_x1 =
align(info->dst.box.x + info->dst.box.width, TILE_WIDTH);
unsigned expanded_y1 =
align(info->dst.box.y + info->dst.box.height, TILE_HEIGHT);
/* But clamp to the destination size to save some redundant threads */
expanded_x1 =
MIN2(expanded_x1, u_minify(info->dst.resource->width0, info->dst.level));
expanded_y1 =
MIN2(expanded_y1, u_minify(info->dst.resource->height0, info->dst.level));
/* Recalculate the width/height based on the expanded grid */
width = expanded_x1 - expanded_x0;
height = expanded_y1 - expanded_y0;
struct pipe_grid_info grid_info = {
.block = {TILE_WIDTH, TILE_HEIGHT, 1},
.last_block = {width % TILE_WIDTH, height % TILE_HEIGHT, 1},
+1
View File
@@ -578,6 +578,7 @@ enum asahi_blit_clamp {
struct asahi_blit_key {
enum pipe_format src_format, dst_format;
bool array;
bool aligned;
};
DERIVE_HASH_TABLE(asahi_blit_key);