vc4: Tell state_tracker that we would prefer NIR.
authorEric Anholt <eric@anholt.net>
Tue, 17 May 2016 20:04:20 +0000 (13:04 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 22 Aug 2016 19:11:08 +0000 (12:11 -0700)
Before this series, the code generation path was:

GLSL IR -> TGSI -> NIR -> NIR clone -> QIR -> QPU

Now it's (generally)

GLSL IR -> NIR -> NIR clone -> QIR -> QPU

src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_screen.c
src/gallium/drivers/vc4/vc4_screen.h

index 1e8542fc27fb23b7c5d033617bccc525a0adf109..dd8c4210eeed6c722469a627c2de3ce77d3d372e 100644 (file)
@@ -1971,8 +1971,16 @@ static const nir_shader_compiler_options nir_options = {
         .lower_fsat = true,
         .lower_fsqrt = true,
         .lower_negate = true,
+        .native_integers = true,
 };
 
+const void *
+vc4_screen_get_compiler_options(struct pipe_screen *pscreen,
+                                enum pipe_shader_ir ir, unsigned shader)
+{
+        return &nir_options;
+}
+
 static int
 count_nir_instrs(nir_shader *nir)
 {
@@ -2181,14 +2189,24 @@ vc4_shader_state_create(struct pipe_context *pctx,
 
         so->program_id = vc4->next_uncompiled_program_id++;
 
-        if (vc4_debug & VC4_DEBUG_TGSI) {
-                fprintf(stderr, "prog %d TGSI:\n",
-                        so->program_id);
-                tgsi_dump(cso->tokens, 0);
-                fprintf(stderr, "\n");
-        }
+        nir_shader *s;
 
-        nir_shader *s = tgsi_to_nir(cso->tokens, &nir_options);
+        if (cso->type == PIPE_SHADER_IR_NIR) {
+                /* The backend takes ownership of the NIR shader on state
+                 * creation.
+                 */
+                s = cso->ir.nir;
+        } else {
+                assert(cso->type == PIPE_SHADER_IR_TGSI);
+
+                if (vc4_debug & VC4_DEBUG_TGSI) {
+                        fprintf(stderr, "prog %d TGSI:\n",
+                                so->program_id);
+                        tgsi_dump(cso->tokens, 0);
+                        fprintf(stderr, "\n");
+                }
+                s = tgsi_to_nir(cso->tokens, &nir_options);
+        }
 
         NIR_PASS_V(s, nir_opt_global_to_local);
         NIR_PASS_V(s, nir_convert_to_ssa);
index 1c3c605c2dac7588446bb5cc98c1ac76a6f4ad2d..9e08e561c3ed32bc804fa9309d547aaf73c04a08 100644 (file)
@@ -386,7 +386,7 @@ vc4_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
         case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
                 return VC4_MAX_TEXTURE_SAMPLERS;
         case PIPE_SHADER_CAP_PREFERRED_IR:
-                return PIPE_SHADER_IR_TGSI;
+                return PIPE_SHADER_IR_NIR;
         case PIPE_SHADER_CAP_SUPPORTED_IRS:
                 return 0;
        case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT:
@@ -633,6 +633,7 @@ vc4_screen_create(int fd)
         pscreen->get_name = vc4_screen_get_name;
         pscreen->get_vendor = vc4_screen_get_vendor;
         pscreen->get_device_vendor = vc4_screen_get_vendor;
+        pscreen->get_compiler_options = vc4_screen_get_compiler_options;
 
         return pscreen;
 
index 1bbede25422ddbd95b5d14c35da0ac689d9d2f70..36fe1c74e9548e7d1b82ffd5b7d1a243caf582b4 100644 (file)
@@ -100,6 +100,10 @@ struct vc4_bo *
 vc4_screen_bo_from_handle(struct pipe_screen *pscreen,
                           struct winsys_handle *whandle);
 
+const void *
+vc4_screen_get_compiler_options(struct pipe_screen *pscreen,
+                                enum pipe_shader_ir ir, unsigned shader);
+
 extern uint32_t vc4_debug;
 
 void