From 07cb81f0fcf811d3c422b3ec1f1beb18c0e0c38c Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 4 Sep 2023 09:44:08 -0400 Subject: [PATCH] asahi: Skip LOD bias lowering for GLES This reduces silliness in Dolphin ubershaders by eliminating the double lowering. It also makes the GLES shader assembly nicer to read. Dolphin ubershader performance at 4K on MMG improved by about 0.5%. Not massive, but definitely noticeable and reduces the delta to macOS. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/asahi/agx_pipe.c | 2 ++ src/gallium/drivers/asahi/agx_state.c | 10 ++++++---- src/gallium/drivers/asahi/agx_state.h | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index dfda3c09ae2..7ee255c5479 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -1527,6 +1527,8 @@ agx_create_context(struct pipe_screen *screen, void *priv, unsigned flags) /* By default all samples are enabled */ ctx->sample_mask = ~0; + ctx->support_lod_bias = !(flags & PIPE_CONTEXT_NO_LOD_BIAS); + return pctx; } diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index e9a7a1ef6c5..df9d9ed1c7e 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -1718,7 +1718,7 @@ agx_get_shader_variant(struct agx_screen *screen, static void agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, - nir_shader *nir) + nir_shader *nir, bool support_lod_bias) { if (nir->info.stage == MESA_SHADER_KERNEL) nir->info.stage = MESA_SHADER_COMPUTE; @@ -1756,7 +1756,7 @@ agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, } bool allow_mediump = !(dev->debug & AGX_DBG_NO16); - agx_preprocess_nir(nir, true, allow_mediump, &so->info); + agx_preprocess_nir(nir, support_lod_bias, allow_mediump, &so->info); blob_init(&so->serialized_nir); nir_serialize(&so->serialized_nir, nir, true); @@ -1770,6 +1770,7 @@ static void * agx_create_shader_state(struct pipe_context *pctx, const struct pipe_shader_state *cso) { + struct agx_context *ctx = agx_context(pctx); struct agx_uncompiled_shader *so = rzalloc(NULL, struct agx_uncompiled_shader); struct agx_device *dev = agx_device(pctx->screen); @@ -1791,7 +1792,7 @@ agx_create_shader_state(struct pipe_context *pctx, asahi_fs_shader_key_equal); } - agx_shader_initialize(dev, so, nir); + agx_shader_initialize(dev, so, nir, ctx->support_lod_bias); /* We're done with the NIR, throw it away */ ralloc_free(nir); @@ -1847,6 +1848,7 @@ static void * agx_create_compute_state(struct pipe_context *pctx, const struct pipe_compute_state *cso) { + struct agx_context *ctx = agx_context(pctx); struct agx_device *dev = agx_device(pctx->screen); struct agx_uncompiled_shader *so = rzalloc(NULL, struct agx_uncompiled_shader); @@ -1862,7 +1864,7 @@ agx_create_compute_state(struct pipe_context *pctx, assert(cso->ir_type == PIPE_SHADER_IR_NIR && "TGSI kernels unsupported"); nir_shader *nir = (void *)cso->prog; - agx_shader_initialize(dev, so, nir); + agx_shader_initialize(dev, so, nir, ctx->support_lod_bias); agx_get_shader_variant(agx_screen(pctx->screen), so, &pctx->debug, &key); /* We're done with the NIR, throw it away */ diff --git a/src/gallium/drivers/asahi/agx_state.h b/src/gallium/drivers/asahi/agx_state.h index e8c28d0e536..0b19f7064c9 100644 --- a/src/gallium/drivers/asahi/agx_state.h +++ b/src/gallium/drivers/asahi/agx_state.h @@ -393,6 +393,9 @@ struct agx_context { struct agx_compiled_shader *vs, *fs; uint32_t dirty; + /* Acts as a context-level shader key */ + bool support_lod_bias; + /* Set of batches. When full, the LRU entry (the batch with the smallest * seqnum) is flushed to free a slot. */