asahi: Skip LOD bias lowering for GLES
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 4 Sep 2023 13:44:08 +0000 (09:44 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 5 Sep 2023 18:50:35 +0000 (18:50 +0000)
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 <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25052>

src/gallium/drivers/asahi/agx_pipe.c
src/gallium/drivers/asahi/agx_state.c
src/gallium/drivers/asahi/agx_state.h

index dfda3c0..7ee255c 100644 (file)
@@ -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;
 }
 
index e9a7a1e..df9d9ed 100644 (file)
@@ -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 */
index e8c28d0..0b19f70 100644 (file)
@@ -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.
     */