freedreno: Immediately compile a default variant of shaders.
authorEric Anholt <eric@anholt.net>
Tue, 14 Apr 2020 22:40:43 +0000 (15:40 -0700)
committerMarge Bot <eric+marge@anholt.net>
Fri, 1 May 2020 16:26:32 +0000 (16:26 +0000)
Now that we normalize our keys fairly well, build a variant at shader
state creation time so that hopefully you don't have to call the compiler
at draw time (as is now the case with glmark2 ES and most of the humus GL
demos).

Fixes: #2782
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4562>

src/gallium/drivers/freedreno/ir3/ir3_gallium.c

index 2f7a01603aa329bbd588126a046079c381cf7e4b..f5e93495d20622682f63e46d19ac4af42d7b29c7 100644 (file)
@@ -147,45 +147,42 @@ ir3_shader_create(struct ir3_compiler *compiler,
 
        struct ir3_shader *shader = ir3_shader_from_nir(compiler, nir, &stream_output);
 
-       if (fd_mesa_debug & FD_DBG_SHADERDB) {
-               /* if shader-db run, create a standard variant immediately
-                * (as otherwise nothing will trigger the shader to be
-                * actually compiled)
+       /* Compile standard variants immediately to try to avoid draw-time stalls
+        * to run the compiler.
+        */
+       struct ir3_shader_key key = {
+               .tessellation = IR3_TESS_NONE,
+       };
+
+       switch (nir->info.stage) {
+       case MESA_SHADER_TESS_EVAL:
+               key.tessellation = ir3_tess_mode(nir->info.tess.primitive_mode);
+               break;
+
+       case MESA_SHADER_TESS_CTRL:
+               /* The primitive_mode field, while it exists for TCS, is not
+                * populated (since separable shaders between TCS/TES are legal,
+                * so TCS wouldn't have access to TES's declaration).  Make a
+                * guess so that we shader-db something plausible for TCS.
                 */
-               struct ir3_shader_key key = {
-                       .tessellation = IR3_TESS_NONE,
-               };
-
-               switch (nir->info.stage) {
-               case MESA_SHADER_TESS_EVAL:
-                       key.tessellation = ir3_tess_mode(nir->info.tess.primitive_mode);
-                       break;
-
-               case MESA_SHADER_TESS_CTRL:
-                       /* The primitive_mode field, while it exists for TCS, is not
-                        * populated (since separable shaders between TCS/TES are legal,
-                        * so TCS wouldn't have access to TES's declaration).  Make a
-                        * guess so that we shader-db something plausible for TCS.
-                        */
-                       if (nir->info.outputs_written & VARYING_BIT_TESS_LEVEL_INNER)
-                               key.tessellation = IR3_TESS_TRIANGLES;
-                       else
-                               key.tessellation = IR3_TESS_ISOLINES;
-                       break;
-
-               case MESA_SHADER_GEOMETRY:
-                       key.has_gs = true;
-                       break;
-
-               default:
-                       break;
-               }
+               if (nir->info.outputs_written & VARYING_BIT_TESS_LEVEL_INNER)
+                       key.tessellation = IR3_TESS_TRIANGLES;
+               else
+                       key.tessellation = IR3_TESS_ISOLINES;
+               break;
+
+       case MESA_SHADER_GEOMETRY:
+               key.has_gs = true;
+               break;
+
+       default:
+               break;
+       }
 
-               ir3_shader_variant(shader, key, false, debug);
+       ir3_shader_variant(shader, key, false, debug);
 
-               if (nir->info.stage == MESA_SHADER_VERTEX)
-                       ir3_shader_variant(shader, key, true, debug);
-       }
+       if (nir->info.stage == MESA_SHADER_VERTEX)
+               ir3_shader_variant(shader, key, true, debug);
 
        shader->initial_variants_done = true;
 
@@ -215,14 +212,12 @@ ir3_shader_create_compute(struct ir3_compiler *compiler,
 
        struct ir3_shader *shader = ir3_shader_from_nir(compiler, nir, NULL);
 
-       if (fd_mesa_debug & FD_DBG_SHADERDB) {
-               /* if shader-db run, create a standard variant immediately
-                * (as otherwise nothing will trigger the shader to be
-                * actually compiled)
-                */
-               static struct ir3_shader_key key; /* static is implicitly zeroed */
-               ir3_shader_variant(shader, key, false, debug);
-       }
+       /* Immediately compile a standard variant.  We have so few variants in our
+        * shaders, that doing so almost eliminates draw-time recompiles.  (This
+        * is also how we get data from shader-db's ./run)
+        */
+       static struct ir3_shader_key key; /* static is implicitly zeroed */
+       ir3_shader_variant(shader, key, false, debug);
 
        shader->initial_variants_done = true;