Mesa (master): freedreno: a2xx: use nir_lower_io for TGSI shaders

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 23 17:13:51 UTC 2019


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

Author: Jonathan Marek <jonathan at marek.ca>
Date:   Wed Apr 10 14:11:26 2019 -0400

freedreno: a2xx: use nir_lower_io for TGSI shaders

Allows removing the load_deref/store_deref code in the compiler.

tgsi_to_nir now uses screen instead of options so we can simplify that too.

Signed-off-by: Jonathan Marek <jonathan at marek.ca>
Reviewed-by: Rob Clark <robdclark at gmail.com>

---

 src/gallium/drivers/freedreno/a2xx/fd2_program.c | 23 ++++++--------
 src/gallium/drivers/freedreno/a2xx/ir2_nir.c     | 38 ++----------------------
 2 files changed, 11 insertions(+), 50 deletions(-)

diff --git a/src/gallium/drivers/freedreno/a2xx/fd2_program.c b/src/gallium/drivers/freedreno/a2xx/fd2_program.c
index 0d262e93208..f09b7406506 100644
--- a/src/gallium/drivers/freedreno/a2xx/fd2_program.c
+++ b/src/gallium/drivers/freedreno/a2xx/fd2_program.c
@@ -32,6 +32,7 @@
 #include "util/u_format.h"
 #include "tgsi/tgsi_dump.h"
 #include "tgsi/tgsi_parse.h"
+#include "nir/tgsi_to_nir.h"
 
 #include "freedreno_program.h"
 
@@ -96,14 +97,11 @@ fd2_fp_state_create(struct pipe_context *pctx,
 	if (!so)
 		return NULL;
 
-	if (cso->type == PIPE_SHADER_IR_NIR) {
-		so->nir = cso->ir.nir;
-		NIR_PASS_V(so->nir, nir_lower_io, nir_var_all, ir2_glsl_type_size,
+	so->nir = (cso->type == PIPE_SHADER_IR_NIR) ? cso->ir.nir :
+		tgsi_to_nir(cso->tokens, pctx->screen);
+
+	NIR_PASS_V(so->nir, nir_lower_io, nir_var_all, ir2_glsl_type_size,
 			   (nir_lower_io_options)0);
-	} else {
-		assert(cso->type == PIPE_SHADER_IR_TGSI);
-		so->nir = ir2_tgsi_to_nir(cso->tokens, pctx->screen);
-	}
 
 	if (ir2_optimize_nir(so->nir, true))
 		goto fail;
@@ -136,14 +134,11 @@ fd2_vp_state_create(struct pipe_context *pctx,
 	if (!so)
 		return NULL;
 
-	if (cso->type == PIPE_SHADER_IR_NIR) {
-		so->nir = cso->ir.nir;
-		NIR_PASS_V(so->nir, nir_lower_io, nir_var_all, ir2_glsl_type_size,
+	so->nir = (cso->type == PIPE_SHADER_IR_NIR) ? cso->ir.nir :
+		tgsi_to_nir(cso->tokens, pctx->screen);
+
+	NIR_PASS_V(so->nir, nir_lower_io, nir_var_all, ir2_glsl_type_size,
 			   (nir_lower_io_options)0);
-	} else {
-		assert(cso->type == PIPE_SHADER_IR_TGSI);
-		so->nir = ir2_tgsi_to_nir(cso->tokens, pctx->screen);
-	}
 
 	if (ir2_optimize_nir(so->nir, true))
 		goto fail;
diff --git a/src/gallium/drivers/freedreno/a2xx/ir2_nir.c b/src/gallium/drivers/freedreno/a2xx/ir2_nir.c
index ee348ca6a93..ddf93a637af 100644
--- a/src/gallium/drivers/freedreno/a2xx/ir2_nir.c
+++ b/src/gallium/drivers/freedreno/a2xx/ir2_nir.c
@@ -25,7 +25,6 @@
  */
 
 #include "ir2_private.h"
-#include "nir/tgsi_to_nir.h"
 
 #include "freedreno_util.h"
 #include "fd2_program.h"
@@ -42,17 +41,6 @@ static const nir_shader_compiler_options options = {
 	.vertex_id_zero_based = true, /* its not implemented anyway */
 };
 
-struct nir_shader *
-ir2_tgsi_to_nir(const struct tgsi_token *tokens,
-		struct pipe_screen *screen)
-{
-	if (!screen) {
-		return tgsi_to_nir_noscreen(tokens, &options);
-	}
-
-	return tgsi_to_nir(tokens, screen);
-}
-
 const nir_shader_compiler_options *
 ir2_get_compiler_options(void)
 {
@@ -598,7 +586,6 @@ emit_intrinsic(struct ir2_context *ctx, nir_intrinsic_instr *intr)
 {
 	struct ir2_instr *instr;
 	nir_const_value *const_offset;
-	nir_deref_instr *deref;
 	unsigned idx;
 
 	switch (intr->intrinsic) {
@@ -608,16 +595,6 @@ emit_intrinsic(struct ir2_context *ctx, nir_intrinsic_instr *intr)
 	case nir_intrinsic_store_output:
 		store_output(ctx, intr->src[0], output_slot(ctx, intr), intr->num_components);
 		break;
-	case nir_intrinsic_load_deref:
-		deref = nir_src_as_deref(intr->src[0]);
-		assert(deref->deref_type == nir_deref_type_var);
-		load_input(ctx, &intr->dest, deref->var->data.driver_location);
-		break;
-	case nir_intrinsic_store_deref:
-		deref = nir_src_as_deref(intr->src[0]);
-		assert(deref->deref_type == nir_deref_type_var);
-		store_output(ctx, intr->src[1], deref->var->data.location, intr->num_components);
-		break;
 	case nir_intrinsic_load_uniform:
 		const_offset = nir_src_as_const_value(intr->src[0]);
 		assert(const_offset); /* TODO can be false in ES2? */
@@ -1066,21 +1043,10 @@ static void cleanup_binning(struct ir2_context *ctx)
 				continue;
 
 			nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
-			unsigned slot;
-			switch (intr->intrinsic) {
-			case nir_intrinsic_store_deref: {
-				nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
-				assert(deref->deref_type == nir_deref_type_var);
-				slot = deref->var->data.location;
-			} break;
-			case nir_intrinsic_store_output:
-				slot = output_slot(ctx, intr);
-				break;
-			default:
+			if (intr->intrinsic != nir_intrinsic_store_output)
 				continue;
-			}
 
-			if (slot != VARYING_SLOT_POS)
+			if (output_slot(ctx, intr) != VARYING_SLOT_POS)
 				nir_instr_remove(instr);
 		}
 	}




More information about the mesa-commit mailing list