[Mesa-dev] [PATCH 1/2] i965: Refactor brw_upload_programs by inlining per-stage upload functions

Carl Worth cworth at cworth.org
Fri May 15 17:09:57 PDT 2015


In this commit, the function bodies of each of the
brw_upload_<stage>_prog functions are manually inlined into
brw_upload_programs. This commit is intended to have no functional
change.

The resulting function body of brw_upload_programs is fairly messy,
and is expected to be cleaned up by subsequent commits that continue
the refactoring.
---
 src/mesa/drivers/dri/i965/brw_ff_gs.c        |  37 +-------
 src/mesa/drivers/dri/i965/brw_ff_gs.h        |   7 +-
 src/mesa/drivers/dri/i965/brw_gs.c           |  59 +-----------
 src/mesa/drivers/dri/i965/brw_gs.h           |   6 +-
 src/mesa/drivers/dri/i965/brw_state_upload.c | 129 +++++++++++++++++++++++++--
 src/mesa/drivers/dri/i965/brw_vs.c           |  43 +--------
 src/mesa/drivers/dri/i965/brw_vs.h           |   6 +-
 src/mesa/drivers/dri/i965/brw_wm.c           |  31 +------
 src/mesa/drivers/dri/i965/brw_wm.h           |   6 +-
 9 files changed, 153 insertions(+), 171 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_ff_gs.c b/src/mesa/drivers/dri/i965/brw_ff_gs.c
index f72f37f..4c438e5 100644
--- a/src/mesa/drivers/dri/i965/brw_ff_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_ff_gs.c
@@ -149,7 +149,7 @@ brw_codegen_ff_gs_prog(struct brw_context *brw,
    ralloc_free(mem_ctx);
 }
 
-static bool
+bool
 brw_ff_gs_state_dirty(struct brw_context *brw)
 {
    return brw_state_dirty(brw,
@@ -159,7 +159,7 @@ brw_ff_gs_state_dirty(struct brw_context *brw)
                           BRW_NEW_VS_PROG_DATA);
 }
 
-static void
+void
 brw_ff_gs_populate_key(struct brw_context *brw,
                        struct brw_ff_gs_prog_key *key)
 {
@@ -231,36 +231,3 @@ brw_ff_gs_populate_key(struct brw_context *brw,
                            brw->primitive == _3DPRIM_LINELOOP);
    }
 }
-
-/* Calculate interpolants for triangle and line rasterization.
- */
-void
-brw_upload_ff_gs_prog(struct brw_context *brw)
-{
-   struct brw_ff_gs_prog_key key;
-
-   if (!brw_ff_gs_state_dirty(brw))
-      return;
-
-   /* Populate the key:
-    */
-   brw_ff_gs_populate_key(brw, &key);
-
-   if (brw->ff_gs.prog_active != key.need_gs_prog) {
-      brw->ctx.NewDriverState |= BRW_NEW_FF_GS_PROG_DATA;
-      brw->ff_gs.prog_active = key.need_gs_prog;
-   }
-
-   if (brw->ff_gs.prog_active) {
-      if (!brw_search_cache(&brw->cache, BRW_CACHE_FF_GS_PROG,
-			    &key, sizeof(key),
-			    &brw->ff_gs.prog_offset, &brw->ff_gs.prog_data)) {
-         brw_codegen_ff_gs_prog(brw, &key);
-      }
-   }
-}
-
-void gen6_brw_upload_ff_gs_prog(struct brw_context *brw)
-{
-   brw_upload_ff_gs_prog(brw);
-}
diff --git a/src/mesa/drivers/dri/i965/brw_ff_gs.h b/src/mesa/drivers/dri/i965/brw_ff_gs.h
index 9e016b8..dca6405 100644
--- a/src/mesa/drivers/dri/i965/brw_ff_gs.h
+++ b/src/mesa/drivers/dri/i965/brw_ff_gs.h
@@ -110,10 +110,13 @@ void brw_ff_gs_lines(struct brw_ff_gs_compile *c);
 void gen6_sol_program(struct brw_ff_gs_compile *c,
                       struct brw_ff_gs_prog_key *key,
                       unsigned num_verts, bool check_edge_flag);
-void gen6_brw_upload_ff_gs_prog(struct brw_context *brw);
+
+bool
+brw_ff_gs_state_dirty(struct brw_context *brw);
 
 void
-brw_upload_ff_gs_prog(struct brw_context *brw);
+brw_ff_gs_populate_key(struct brw_context *brw,
+                       struct brw_ff_gs_prog_key *key);
 
 void
 brw_codegen_ff_gs_prog(struct brw_context *brw,
diff --git a/src/mesa/drivers/dri/i965/brw_gs.c b/src/mesa/drivers/dri/i965/brw_gs.c
index 52c7303..71765f9 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_gs.c
@@ -290,7 +290,7 @@ brw_codegen_gs_prog(struct brw_context *brw,
    return true;
 }
 
-static bool
+bool
 brw_gs_state_dirty(struct brw_context *brw)
 {
    return brw_state_dirty(brw,
@@ -300,7 +300,7 @@ brw_gs_state_dirty(struct brw_context *brw)
                           BRW_NEW_VUE_MAP_VS);
 }
 
-static void
+void
 brw_gs_populate_key(struct brw_context *brw,
                     struct brw_gs_prog_key *key)
 {
@@ -324,61 +324,6 @@ brw_gs_populate_key(struct brw_context *brw,
    key->input_varyings = brw->vue_map_vs.slots_valid;
 }
 
-void
-brw_upload_gs_prog(struct brw_context *brw)
-{
-   struct gl_context *ctx = &brw->ctx;
-   struct gl_shader_program **current = ctx->_Shader->CurrentProgram;
-   struct brw_stage_state *stage_state = &brw->gs.base;
-   struct brw_gs_prog_key key;
-   /* BRW_NEW_GEOMETRY_PROGRAM */
-   struct brw_geometry_program *gp =
-      (struct brw_geometry_program *) brw->geometry_program;
-
-   if (!brw_gs_state_dirty(brw))
-      return;
-
-   if (gp == NULL) {
-      /* No geometry shader.  Vertex data just passes straight through. */
-      if (brw->ctx.NewDriverState & BRW_NEW_VUE_MAP_VS) {
-         brw->vue_map_geom_out = brw->vue_map_vs;
-         brw->ctx.NewDriverState |= BRW_NEW_VUE_MAP_GEOM_OUT;
-      }
-
-      if (brw->gen == 6 &&
-          (brw->ctx.NewDriverState & BRW_NEW_TRANSFORM_FEEDBACK)) {
-         gen6_brw_upload_ff_gs_prog(brw);
-         return;
-      }
-
-      /* Other state atoms had better not try to access prog_data, since
-       * there's no GS program.
-       */
-      brw->gs.prog_data = NULL;
-      brw->gs.base.prog_data = NULL;
-
-      return;
-   }
-
-   brw_gs_populate_key(brw, &key);
-
-   if (!brw_search_cache(&brw->cache, BRW_CACHE_GS_PROG,
-                         &key, sizeof(key),
-                         &stage_state->prog_offset, &brw->gs.prog_data)) {
-      bool success = brw_codegen_gs_prog(brw, current[MESA_SHADER_GEOMETRY],
-                                         gp, &key);
-      assert(success);
-      (void)success;
-   }
-   brw->gs.base.prog_data = &brw->gs.prog_data->base.base;
-
-   if (memcmp(&brw->gs.prog_data->base.vue_map, &brw->vue_map_geom_out,
-              sizeof(brw->vue_map_geom_out)) != 0) {
-      brw->vue_map_geom_out = brw->gs.prog_data->base.vue_map;
-      brw->ctx.NewDriverState |= BRW_NEW_VUE_MAP_GEOM_OUT;
-   }
-}
-
 bool
 brw_gs_precompile(struct gl_context *ctx,
                   struct gl_shader_program *shader_prog,
diff --git a/src/mesa/drivers/dri/i965/brw_gs.h b/src/mesa/drivers/dri/i965/brw_gs.h
index b327c40..a484e4b 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.h
+++ b/src/mesa/drivers/dri/i965/brw_gs.h
@@ -39,8 +39,12 @@ struct gl_program;
 
 bool brw_gs_prog_data_compare(const void *a, const void *b);
 
+bool
+brw_gs_state_dirty(struct brw_context *brw);
+
 void
-brw_upload_gs_prog(struct brw_context *brw);
+brw_gs_populate_key(struct brw_context *brw,
+                    struct brw_gs_prog_key *key);
 
 bool
 brw_codegen_gs_prog(struct brw_context *brw,
diff --git a/src/mesa/drivers/dri/i965/brw_state_upload.c b/src/mesa/drivers/dri/i965/brw_state_upload.c
index 84b0861..7fa434f 100644
--- a/src/mesa/drivers/dri/i965/brw_state_upload.c
+++ b/src/mesa/drivers/dri/i965/brw_state_upload.c
@@ -619,15 +619,132 @@ static inline void
 brw_upload_programs(struct brw_context *brw,
                     enum brw_pipeline pipeline)
 {
+   struct gl_context *ctx = &brw->ctx;
+   struct gl_shader_program **current = ctx->_Shader->CurrentProgram;
+   struct gl_shader_program *current_fp = ctx->_Shader->_CurrentFragmentProgram;
+   struct brw_vs_prog_key vs_key;
+   struct brw_ff_gs_prog_key ff_gs_key;
+   struct brw_gs_prog_key gs_key;
+   struct brw_wm_prog_key wm_key;
+   struct brw_stage_state *stage_state = &brw->gs.base;
+   struct brw_vertex_program *vp =
+      (struct brw_vertex_program *) brw->vertex_program;
+   struct brw_geometry_program *gp =
+      (struct brw_geometry_program *) brw->geometry_program;
+   struct brw_fragment_program *fp =
+      (struct brw_fragment_program *) brw->fragment_program;
+
    if (pipeline == BRW_RENDER_PIPELINE) {
-      brw_upload_vs_prog(brw);
 
-      if (brw->gen < 6)
-         brw_upload_ff_gs_prog(brw);
-      else
-         brw_upload_gs_prog(brw);
+      if (brw_vs_state_dirty(brw)) {
+
+         brw_vs_populate_key(brw, &vs_key);
+
+         if (!brw_search_cache(&brw->cache, BRW_CACHE_VS_PROG,
+                               &vs_key, sizeof(vs_key),
+                               &brw->vs.base.prog_offset, &brw->vs.prog_data)) {
+            bool success = brw_codegen_vs_prog(brw, current[MESA_SHADER_VERTEX],
+                                               vp, &vs_key);
+            (void) success;
+            assert(success);
+         }
+         brw->vs.base.prog_data = &brw->vs.prog_data->base.base;
+
+         if (memcmp(&brw->vs.prog_data->base.vue_map, &brw->vue_map_geom_out,
+                    sizeof(brw->vue_map_geom_out)) != 0) {
+            brw->vue_map_vs = brw->vs.prog_data->base.vue_map;
+            brw->ctx.NewDriverState |= BRW_NEW_VUE_MAP_VS;
+            if (brw->gen < 6) {
+               /* No geometry shader support, so the VS VUE map is the VUE map
+                * for the output of the "geometry" portion of the pipeline.
+                */
+               brw->vue_map_geom_out = brw->vue_map_vs;
+               brw->ctx.NewDriverState |= BRW_NEW_VUE_MAP_GEOM_OUT;
+            }
+         }
+      }
+
+      if (brw->gen < 6) {
+
+      UPLOAD_FF_GS_PROG:
+
+         if (brw_ff_gs_state_dirty(brw)) {
+
+            /* Populate the key:
+             */
+            brw_ff_gs_populate_key(brw, &ff_gs_key);
+
+            if (brw->ff_gs.prog_active != ff_gs_key.need_gs_prog) {
+               brw->ctx.NewDriverState |= BRW_NEW_FF_GS_PROG_DATA;
+               brw->ff_gs.prog_active = ff_gs_key.need_gs_prog;
+            }
+
+            if (brw->ff_gs.prog_active) {
+               if (!brw_search_cache(&brw->cache, BRW_CACHE_FF_GS_PROG,
+                                     &ff_gs_key, sizeof(ff_gs_key),
+                                     &brw->ff_gs.prog_offset, &brw->ff_gs.prog_data)) {
+                  brw_codegen_ff_gs_prog(brw, &ff_gs_key);
+               }
+            }
+         }
+      } else {
+
+         if (brw_gs_state_dirty(brw)) {
+
+            if (gp == NULL) {
+               /* No geometry shader.  Vertex data just passes straight through. */
+               if (brw->ctx.NewDriverState & BRW_NEW_VUE_MAP_VS) {
+                  brw->vue_map_geom_out = brw->vue_map_vs;
+                  brw->ctx.NewDriverState |= BRW_NEW_VUE_MAP_GEOM_OUT;
+               }
+
+               if (brw->gen == 6 &&
+                   (brw->ctx.NewDriverState & BRW_NEW_TRANSFORM_FEEDBACK)) {
+                  goto UPLOAD_FF_GS_PROG;
+               }
+
+               /* Other state atoms had better not try to access prog_data,
+                * since there's no GS program.
+                */
+               brw->gs.prog_data = NULL;
+               brw->gs.base.prog_data = NULL;
+            } else {
+
+               brw_gs_populate_key(brw, &gs_key);
+
+               if (!brw_search_cache(&brw->cache, BRW_CACHE_GS_PROG,
+                                     &gs_key, sizeof(gs_key),
+                                     &stage_state->prog_offset, &brw->gs.prog_data)) {
+                  bool success = brw_codegen_gs_prog(brw, current[MESA_SHADER_GEOMETRY],
+                                                     gp, &gs_key);
+                  assert(success);
+                  (void)success;
+               }
+               brw->gs.base.prog_data = &brw->gs.prog_data->base.base;
+
+               if (memcmp(&brw->gs.prog_data->base.vue_map, &brw->vue_map_geom_out,
+                          sizeof(brw->vue_map_geom_out)) != 0) {
+                  brw->vue_map_geom_out = brw->gs.prog_data->base.vue_map;
+                  brw->ctx.NewDriverState |= BRW_NEW_VUE_MAP_GEOM_OUT;
+               }
+            }
+         }
+      }
+
+      if (brw_wm_state_dirty(brw)) {
+
+         brw_wm_populate_key(brw, &wm_key);
+
+         if (!brw_search_cache(&brw->cache, BRW_CACHE_FS_PROG,
+                               &wm_key, sizeof(wm_key),
+                               &brw->wm.base.prog_offset, &brw->wm.prog_data)) {
+            bool success = brw_codegen_wm_prog(brw, current_fp, fp, &wm_key);
+            (void) success;
+            assert(success);
+         }
+         brw->wm.base.prog_data = &brw->wm.prog_data->base;
+      }
 
-      brw_upload_wm_prog(brw);
    } else if (pipeline == BRW_COMPUTE_PIPELINE) {
       brw_upload_cs_prog(brw);
    }
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index d03567e..548bccc 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -403,7 +403,7 @@ brw_setup_vue_key_clip_info(struct brw_context *brw,
    }
 }
 
-static bool
+bool
 brw_vs_state_dirty(struct brw_context *brw)
 {
    return brw_state_dirty(brw,
@@ -417,7 +417,7 @@ brw_vs_state_dirty(struct brw_context *brw)
                           BRW_NEW_VS_ATTRIB_WORKAROUNDS);
 }
 
-static void
+void
 brw_vs_populate_key(struct brw_context *brw,
                     struct brw_vs_prog_key *key)
 {
@@ -466,45 +466,6 @@ brw_vs_populate_key(struct brw_context *brw,
           sizeof(brw->vb.attrib_wa_flags));
 }
 
-void
-brw_upload_vs_prog(struct brw_context *brw)
-{
-   struct gl_context *ctx = &brw->ctx;
-   struct gl_shader_program **current = ctx->_Shader->CurrentProgram;
-   struct brw_vs_prog_key key;
-   /* BRW_NEW_VERTEX_PROGRAM */
-   struct brw_vertex_program *vp =
-      (struct brw_vertex_program *)brw->vertex_program;
-
-   if (!brw_vs_state_dirty(brw))
-      return;
-
-   brw_vs_populate_key(brw, &key);
-
-   if (!brw_search_cache(&brw->cache, BRW_CACHE_VS_PROG,
-			 &key, sizeof(key),
-			 &brw->vs.base.prog_offset, &brw->vs.prog_data)) {
-      bool success = brw_codegen_vs_prog(brw, current[MESA_SHADER_VERTEX],
-                                         vp, &key);
-      (void) success;
-      assert(success);
-   }
-   brw->vs.base.prog_data = &brw->vs.prog_data->base.base;
-
-   if (memcmp(&brw->vs.prog_data->base.vue_map, &brw->vue_map_geom_out,
-              sizeof(brw->vue_map_geom_out)) != 0) {
-      brw->vue_map_vs = brw->vs.prog_data->base.vue_map;
-      brw->ctx.NewDriverState |= BRW_NEW_VUE_MAP_VS;
-      if (brw->gen < 6) {
-         /* No geometry shader support, so the VS VUE map is the VUE map for
-          * the output of the "geometry" portion of the pipeline.
-          */
-         brw->vue_map_geom_out = brw->vue_map_vs;
-         brw->ctx.NewDriverState |= BRW_NEW_VUE_MAP_GEOM_OUT;
-      }
-   }
-}
-
 bool
 brw_vs_precompile(struct gl_context *ctx,
                   struct gl_shader_program *shader_prog,
diff --git a/src/mesa/drivers/dri/i965/brw_vs.h b/src/mesa/drivers/dri/i965/brw_vs.h
index 6157ae6..c12c774 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.h
+++ b/src/mesa/drivers/dri/i965/brw_vs.h
@@ -72,8 +72,12 @@ void brw_vs_debug_recompile(struct brw_context *brw,
                             const struct brw_vs_prog_key *key);
 bool brw_vs_prog_data_compare(const void *a, const void *b);
 
+bool
+brw_vs_state_dirty(struct brw_context *brw);
+
 void
-brw_upload_vs_prog(struct brw_context *brw);
+brw_vs_populate_key(struct brw_context *brw,
+                    struct brw_vs_prog_key *key);
 
 bool
 brw_codegen_vs_prog(struct brw_context *brw,
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index 45a03bb..882206c 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -430,7 +430,7 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
    }
 }
 
-static bool
+bool
 brw_wm_state_dirty (struct brw_context *brw)
 {
    return brw_state_dirty(brw,
@@ -451,8 +451,9 @@ brw_wm_state_dirty (struct brw_context *brw)
                           BRW_NEW_VUE_MAP_GEOM_OUT);
 }
 
-static void brw_wm_populate_key( struct brw_context *brw,
-				 struct brw_wm_prog_key *key )
+void
+brw_wm_populate_key(struct brw_context *brw,
+                    struct brw_wm_prog_key *key )
 {
    struct gl_context *ctx = &brw->ctx;
    /* BRW_NEW_FRAGMENT_PROGRAM */
@@ -611,27 +612,3 @@ static void brw_wm_populate_key( struct brw_context *brw,
    /* The unique fragment program ID */
    key->program_string_id = fp->id;
 }
-
-void
-brw_upload_wm_prog(struct brw_context *brw)
-{
-   struct gl_context *ctx = &brw->ctx;
-   struct gl_shader_program *current = ctx->_Shader->_CurrentFragmentProgram;
-   struct brw_wm_prog_key key;
-   struct brw_fragment_program *fp = (struct brw_fragment_program *)
-      brw->fragment_program;
-
-   if (!brw_wm_state_dirty(brw))
-      return;
-
-   brw_wm_populate_key(brw, &key);
-
-   if (!brw_search_cache(&brw->cache, BRW_CACHE_FS_PROG,
-			 &key, sizeof(key),
-			 &brw->wm.base.prog_offset, &brw->wm.prog_data)) {
-      bool success = brw_codegen_wm_prog(brw, current, fp, &key);
-      (void) success;
-      assert(success);
-   }
-   brw->wm.base.prog_data = &brw->wm.prog_data->base;
-}
diff --git a/src/mesa/drivers/dri/i965/brw_wm.h b/src/mesa/drivers/dri/i965/brw_wm.h
index 0a8a97b..22af0af 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.h
+++ b/src/mesa/drivers/dri/i965/brw_wm.h
@@ -87,8 +87,12 @@ void brw_wm_debug_recompile(struct brw_context *brw,
                             const struct brw_wm_prog_key *key);
 bool brw_wm_prog_data_compare(const void *a, const void *b);
 
+bool
+brw_wm_state_dirty (struct brw_context *brw);
+
 void
-brw_upload_wm_prog(struct brw_context *brw);
+brw_wm_populate_key(struct brw_context *brw,
+                    struct brw_wm_prog_key *key);
 
 #ifdef __cplusplus
 } // extern "C"
-- 
2.1.4



More information about the mesa-dev mailing list