freedreno: a2xx: use nir_lower_io for TGSI shaders
authorJonathan Marek <jonathan@marek.ca>
Wed, 10 Apr 2019 18:11:26 +0000 (14:11 -0400)
committerRob Clark <robdclark@gmail.com>
Tue, 23 Apr 2019 17:13:32 +0000 (17:13 +0000)
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@marek.ca>
Reviewed-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/a2xx/fd2_program.c
src/gallium/drivers/freedreno/a2xx/ir2_nir.c

index 0d262e93208c4f7cefd8296595a4e1727e7eb340..f09b74065066aeb7fd2986b58454d7029d521f3e 100644 (file)
@@ -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;
index ee348ca6a938bf3279165c5443ea4dd69e51f9da..ddf93a637af2a4e1d8615017a033d419e1b19777 100644 (file)
@@ -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);
                }
        }