From 9288a3a583ae6c8204333e1c9fc304a1ebfeee93 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Thu, 31 Oct 2024 03:13:56 +0900 Subject: [PATCH] asahi: Extract agx_decompress_inplace() Signed-off-by: Asahi Lina Part-of: --- src/gallium/drivers/asahi/agx_state.c | 76 +++++++++++++++------------ src/gallium/drivers/asahi/agx_state.h | 3 ++ 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 5a39967e99c..3353b5d710c 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -3483,40 +3483,7 @@ agx_batch_init_state(struct agx_batch *batch) continue; if (true || (rsrc->base.bind & PIPE_BIND_SHARED)) { - struct agx_context *ctx = batch->ctx; - struct agx_device *dev = agx_device(ctx->base.screen); - - perf_debug(dev, "Decompressing in-place"); - - if (!batch->cdm.bo) - batch->cdm = agx_encoder_allocate(batch, dev); - - struct agx_ptr data = agx_pool_alloc_aligned( - &batch->pool, sizeof(struct libagx_decompress_push), 64); - struct libagx_decompress_push *push = data.cpu; - agx_fill_decompress_push(push, layout, surf->u.tex.first_layer, - level, agx_map_texture_gpu(rsrc, 0)); - - struct pipe_sampler_view sampler_view = - sampler_view_for_surface(surf); - sampler_view.target = PIPE_TEXTURE_2D_ARRAY; - struct pipe_image_view view = image_view_for_surface(surf); - agx_pack_texture(&push->compressed, rsrc, surf->format, - &sampler_view); - agx_batch_upload_pbe(batch, &push->uncompressed, &view, false, true, - true, true); - - struct agx_grid grid = agx_grid_direct( - ail_metadata_width_tl(layout, level) * 32, - ail_metadata_height_tl(layout, level), - surf->u.tex.last_layer - surf->u.tex.first_layer + 1, 32, 1, 1); - - struct agx_decompress_key key = { - .nr_samples = layout->sample_count_sa, - }; - - agx_launch_with_uploaded_data(batch, &grid, agx_nir_decompress, - &key, sizeof(key), data.gpu); + agx_decompress_inplace(batch, surf, "Render target spilled"); } else { agx_decompress(batch->ctx, rsrc, "Render target spilled"); } @@ -5621,6 +5588,47 @@ agx_set_global_binding(struct pipe_context *pipe, unsigned first, void agx_init_state_functions(struct pipe_context *ctx); +void +agx_decompress_inplace(struct agx_batch *batch, struct pipe_surface *surf, + const char *reason) +{ + struct agx_context *ctx = batch->ctx; + struct agx_device *dev = agx_device(ctx->base.screen); + struct agx_resource *rsrc = agx_resource(surf->texture); + struct ail_layout *layout = &rsrc->layout; + unsigned level = surf->u.tex.level; + + perf_debug(dev, "Decompressing in-place due to: %s", reason); + + if (!batch->cdm.bo) + batch->cdm = agx_encoder_allocate(batch, dev); + + struct agx_ptr data = agx_pool_alloc_aligned( + &batch->pool, sizeof(struct libagx_decompress_push), 64); + struct libagx_decompress_push *push = data.cpu; + agx_fill_decompress_push(push, layout, surf->u.tex.first_layer, level, + agx_map_texture_gpu(rsrc, 0)); + + struct pipe_sampler_view sampler_view = sampler_view_for_surface(surf); + sampler_view.target = PIPE_TEXTURE_2D_ARRAY; + struct pipe_image_view view = image_view_for_surface(surf); + agx_pack_texture(&push->compressed, rsrc, surf->format, &sampler_view); + agx_batch_upload_pbe(batch, &push->uncompressed, &view, false, true, true, + true); + + struct agx_grid grid = agx_grid_direct( + ail_metadata_width_tl(layout, level) * 32, + ail_metadata_height_tl(layout, level), + surf->u.tex.last_layer - surf->u.tex.first_layer + 1, 32, 1, 1); + + struct agx_decompress_key key = { + .nr_samples = layout->sample_count_sa, + }; + + agx_launch_with_uploaded_data(batch, &grid, agx_nir_decompress, &key, + sizeof(key), data.gpu); +} + void agx_init_state_functions(struct pipe_context *ctx) { diff --git a/src/gallium/drivers/asahi/agx_state.h b/src/gallium/drivers/asahi/agx_state.h index 67b182d5b58..93a69bd7002 100644 --- a/src/gallium/drivers/asahi/agx_state.h +++ b/src/gallium/drivers/asahi/agx_state.h @@ -1244,3 +1244,6 @@ agx_texture_buffer_size_el(enum pipe_format format, uint32_t size) return MIN2(AGX_TEXTURE_BUFFER_MAX_SIZE, size / blocksize); } + +void agx_decompress_inplace(struct agx_batch *batch, struct pipe_surface *surf, + const char *reason);