From c9dd59fef37d2866956df78cf4770e1496228e32 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sun, 23 Jul 2023 09:02:15 -0400 Subject: [PATCH] asahi: Factor out agx_launch For launching compute kernels on particular batches without dirtying state. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/asahi/agx_state.c | 48 ++++++++++++++++----------- src/gallium/drivers/asahi/agx_state.h | 3 ++ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 05b097d7cba..df81abe2395 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -3384,19 +3384,12 @@ agx_texture_barrier(struct pipe_context *pipe, unsigned flags) agx_flush_all(ctx, "Texture barrier"); } -static void -agx_launch_grid(struct pipe_context *pipe, const struct pipe_grid_info *info) +void +agx_launch(struct agx_batch *batch, const struct pipe_grid_info *info, + struct agx_compiled_shader *cs) { - struct agx_context *ctx = agx_context(pipe); - struct agx_batch *batch = agx_get_compute_batch(ctx); - struct agx_device *dev = agx_device(pipe->screen); - - agx_batch_init_state(batch); - - /* Consider compute launches as "draws" for the purposes of sanity - * checking batch state. - */ - batch->any_draws = true; + struct agx_context *ctx = batch->ctx; + struct agx_device *dev = agx_device(ctx->base.screen); /* To implement load_num_workgroups, the number of workgroups needs to be * available in GPU memory. This is either the indirect buffer, or just a @@ -3424,13 +3417,6 @@ agx_launch_grid(struct pipe_context *pipe, const struct pipe_grid_info *info) agx_batch_writes(batch, buffer); } - struct agx_uncompiled_shader *uncompiled = - ctx->stage[PIPE_SHADER_COMPUTE].shader; - - /* There is exactly one variant, get it */ - struct agx_compiled_shader *cs = - _mesa_hash_table_next_entry(uncompiled->variants, NULL)->data; - agx_batch_add_bo(batch, cs->bo); agx_update_descriptors(batch, cs, PIPE_SHADER_COMPUTE); @@ -3493,6 +3479,30 @@ agx_launch_grid(struct pipe_context *pipe, const struct pipe_grid_info *info) batch->cdm.current = out; assert(batch->cdm.current <= batch->cdm.end && "Failed to reserve sufficient space in encoder"); +} + +static void +agx_launch_grid(struct pipe_context *pipe, const struct pipe_grid_info *info) +{ + struct agx_context *ctx = agx_context(pipe); + struct agx_batch *batch = agx_get_compute_batch(ctx); + + agx_batch_init_state(batch); + + /* Consider compute launches as "draws" for the purposes of sanity + * checking batch state. + */ + batch->any_draws = true; + + struct agx_uncompiled_shader *uncompiled = + ctx->stage[PIPE_SHADER_COMPUTE].shader; + + /* There is exactly one variant, get it */ + struct agx_compiled_shader *cs = + _mesa_hash_table_next_entry(uncompiled->variants, NULL)->data; + + agx_launch(batch, info, cs); + /* TODO: Dirty tracking? */ /* TODO: Allow multiple kernels in a batch? */ diff --git a/src/gallium/drivers/asahi/agx_state.h b/src/gallium/drivers/asahi/agx_state.h index 8ea838458b0..eb6748073dc 100644 --- a/src/gallium/drivers/asahi/agx_state.h +++ b/src/gallium/drivers/asahi/agx_state.h @@ -540,6 +540,9 @@ agx_context(struct pipe_context *pctx) return (struct agx_context *)pctx; } +void agx_launch(struct agx_batch *batch, const struct pipe_grid_info *info, + struct agx_compiled_shader *cs); + void agx_init_query_functions(struct pipe_context *ctx); void