Mesa (master): freedreno: Immediately compile a default variant of shaders.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri May 1 16:46:33 UTC 2020


Module: Mesa
Branch: master
Commit: 812c55b07960918db8bb047031c214f77ab1a37f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=812c55b07960918db8bb047031c214f77ab1a37f

Author: Eric Anholt <eric at anholt.net>
Date:   Tue Apr 14 15:40:43 2020 -0700

freedreno: Immediately compile a default variant of shaders.

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 | 83 ++++++++++++-------------
 1 file changed, 39 insertions(+), 44 deletions(-)

diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
index 2f7a01603aa..f5e93495d20 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
@@ -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;
 



More information about the mesa-commit mailing list