i965: Split process_nir into two haves; pre- and post-
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 20 Oct 2015 01:46:29 +0000 (18:46 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 20 Oct 2015 20:02:03 +0000 (13:02 -0700)
src/mesa/drivers/dri/i965/brw_nir.c
src/mesa/drivers/dri/i965/brw_nir.h
src/vulkan/anv_compiler.cpp

index dc4977709140e8fbacf21c0d4f81dd392f686171..9a33188cb5c22cfb553d16477b575a37be320b5b 100644 (file)
@@ -200,7 +200,14 @@ brw_create_nir(struct brw_context *brw,
    }
    nir_validate_shader(nir);
 
-   brw_process_nir(nir, brw->intelScreen->devinfo, shader_prog, stage, is_scalar);
+   brw_preprocess_nir(nir, brw->intelScreen->devinfo, is_scalar);
+
+   if (shader_prog) {
+      nir_lower_samplers(nir, shader_prog);
+      nir_validate_shader(nir);
+   }
+
+   brw_postprocess_nir(nir, brw->intelScreen->devinfo, is_scalar);
 
    static GLuint msg_id = 0;
    _mesa_gl_debug(&brw->ctx, &msg_id,
@@ -208,23 +215,21 @@ brw_create_nir(struct brw_context *brw,
                   MESA_DEBUG_TYPE_OTHER,
                   MESA_DEBUG_SEVERITY_NOTIFICATION,
                   "%s NIR shader:\n",
-                  _mesa_shader_stage_to_abbrev(stage));
+                  _mesa_shader_stage_to_abbrev(nir->stage));
 
    return nir;
 }
 
 void
-brw_process_nir(nir_shader *nir,
-                const struct brw_device_info *devinfo,
-                const struct gl_shader_program *shader_prog,
-                gl_shader_stage stage, bool is_scalar)
+brw_preprocess_nir(nir_shader *nir,
+                   const struct brw_device_info *devinfo,
+                   bool is_scalar)
 {
-   bool debug_enabled = INTEL_DEBUG & intel_debug_flag_for_shader_stage(stage);
    static const nir_lower_tex_options tex_options = {
       .lower_txp = ~0,
    };
 
-   if (stage == MESA_SHADER_GEOMETRY) {
+   if (nir->stage == MESA_SHADER_GEOMETRY) {
       nir_lower_gs_intrinsics(nir);
       nir_validate_shader(nir);
    }
@@ -249,6 +254,15 @@ brw_process_nir(nir_shader *nir,
 
    /* Get rid of split copies */
    nir_optimize(nir, is_scalar);
+}
+
+void
+brw_postprocess_nir(nir_shader *nir,
+                    const struct brw_device_info *devinfo,
+                    bool is_scalar)
+{
+   bool debug_enabled =
+      (INTEL_DEBUG & intel_debug_flag_for_shader_stage(nir->stage));
 
    brw_nir_lower_inputs(nir, is_scalar);
    brw_nir_lower_outputs(nir, is_scalar);
@@ -261,11 +275,6 @@ brw_process_nir(nir_shader *nir,
    nir_remove_dead_variables(nir);
    nir_validate_shader(nir);
 
-   if (shader_prog) {
-      nir_lower_samplers(nir, shader_prog);
-      nir_validate_shader(nir);
-   }
-
    nir_lower_system_values(nir);
    nir_validate_shader(nir);
 
@@ -301,7 +310,7 @@ brw_process_nir(nir_shader *nir,
       }
 
       fprintf(stderr, "NIR (SSA form) for %s shader:\n",
-              _mesa_shader_stage_to_string(stage));
+              _mesa_shader_stage_to_string(nir->stage));
       nir_print_shader(nir, stderr);
    }
 
@@ -328,7 +337,7 @@ brw_process_nir(nir_shader *nir,
 
    if (unlikely(debug_enabled)) {
       fprintf(stderr, "NIR (final form) for %s shader:\n",
-              _mesa_shader_stage_to_string(stage));
+              _mesa_shader_stage_to_string(nir->stage));
       nir_print_shader(nir, stderr);
    }
 }
index 19e5552754584f62fca91337f9b82139d4287802..a6d6768795acec59227fe61b4b4aa315bf15e3d1 100644 (file)
@@ -86,10 +86,13 @@ enum brw_reg_type brw_type_for_nir_type(nir_alu_type type);
 enum glsl_base_type brw_glsl_base_type_for_nir_type(nir_alu_type type);
 
 void
-brw_process_nir(nir_shader *nir,
-                const struct brw_device_info *devinfo,
-                const struct gl_shader_program *shader_prog,
-                gl_shader_stage stage, bool is_scalar);
+brw_preprocess_nir(nir_shader *nir,
+                   const struct brw_device_info *devinfo,
+                   bool is_scalar);
+void
+brw_postprocess_nir(nir_shader *nir,
+                    const struct brw_device_info *devinfo,
+                    bool is_scalar);
 
 void brw_nir_setup_glsl_uniforms(nir_shader *shader,
                                  struct gl_shader_program *shader_prog,
index 14d3fad23e76db42ba356b173bf1c07727a4e421..5d74f0f131e69491c17dadd83ba238eeb38cedea 100644 (file)
@@ -729,11 +729,13 @@ anv_compile_shader_spirv(struct anv_compiler *compiler,
    }
    nir_validate_shader(mesa_shader->Program->nir);
 
+   brw_preprocess_nir(mesa_shader->Program->nir,
+                      compiler->screen->devinfo, is_scalar);
+
    setup_nir_io(mesa_shader, mesa_shader->Program->nir);
 
-   brw_process_nir(mesa_shader->Program->nir,
-                   compiler->screen->devinfo,
-                   NULL, mesa_shader->Stage, is_scalar);
+   brw_postprocess_nir(mesa_shader->Program->nir,
+                       compiler->screen->devinfo, is_scalar);
 
    mesa_shader->num_uniform_components =
       mesa_shader->Program->nir->num_uniforms;