[Mesa-dev] [PATCH 60/77] i965: add shader cache support for geometry shaders

Timothy Arceri timothy.arceri at collabora.com
Mon Oct 3 06:05:19 UTC 2016


---
 src/mesa/drivers/dri/i965/brw_compiler.h     |  2 ++
 src/mesa/drivers/dri/i965/brw_gs.c           | 23 ++++++++++++++++++----
 src/mesa/drivers/dri/i965/brw_shader_cache.c | 29 +++++++++++++++++++++++++++-
 3 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_compiler.h b/src/mesa/drivers/dri/i965/brw_compiler.h
index 9a78c72..41e9ebc 100644
--- a/src/mesa/drivers/dri/i965/brw_compiler.h
+++ b/src/mesa/drivers/dri/i965/brw_compiler.h
@@ -733,6 +733,8 @@ struct brw_gs_prog_data
     * binding table entry.
     */
    unsigned char transform_feedback_swizzles[64 /* BRW_MAX_SOL_BINDINGS */];
+
+   unsigned program_size;
 };
 
 
diff --git a/src/mesa/drivers/dri/i965/brw_gs.c b/src/mesa/drivers/dri/i965/brw_gs.c
index 7b668ba..464b27e 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_gs.c
@@ -194,6 +194,8 @@ brw_codegen_gs_prog(struct brw_context *brw,
                     &stage_state->prog_offset, &brw->gs.prog_data, gp);
    ralloc_free(mem_ctx);
 
+   brw->gs.prog_data->program_size = program_size;
+
    return true;
 }
 
@@ -259,10 +261,23 @@ brw_upload_gs_prog(struct brw_context *brw)
    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;
+#ifdef ENABLE_SHADER_CACHE
+      upload_cached_program(brw, MESA_SHADER_GEOMETRY);
+
+      /* If upload from disk cache failed call codegen */
+      if (!current[MESA_SHADER_GEOMETRY] ||
+          !current[MESA_SHADER_GEOMETRY]->program_written_to_cache) {
+         gp = (struct brw_geometry_program *) brw->geometry_program;
+         gp->id = key.program_string_id;
+#endif
+         bool success = brw_codegen_gs_prog(brw,
+                                            current[MESA_SHADER_GEOMETRY], gp,
+                                            &key);
+         assert(success);
+         (void)success;
+#ifdef ENABLE_SHADER_CACHE
+      }
+#endif
    }
    brw->gs.base.prog_data = &brw->gs.prog_data->base.base;
 }
diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index 280d117..3d06c2b 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -34,6 +34,7 @@
 #include <main/mtypes.h>
 
 #include "brw_context.h"
+#include "brw_gs.h"
 #include "brw_state.h"
 #include "brw_vs.h"
 #include "brw_wm.h"
@@ -289,6 +290,7 @@ read_and_upload(struct brw_context *brw, struct program_cache *cache,
 
    struct brw_stage_prog_data *prog_data;
    struct brw_wm_prog_key wm_key;
+   struct brw_gs_prog_key gs_key;
    struct brw_vs_prog_key vs_key;
    struct brw_stage_state *stage_state;
 
@@ -308,6 +310,11 @@ read_and_upload(struct brw_context *brw, struct program_cache *cache,
    case MESA_SHADER_VERTEX:
       gen_shader_sha1(brw, prog, stage, &vs_key, binary_sha1);
       break;
+   case MESA_SHADER_GEOMETRY:
+      brw_gs_populate_key(brw, &gs_key);
+      gs_key.program_string_id = 0;
+      gen_shader_sha1(brw, prog, stage, &gs_key, binary_sha1);
+      break;
    case MESA_SHADER_FRAGMENT:
       brw_wm_populate_key(brw, &wm_key);
       gen_shader_sha1(brw, prog, stage, &wm_key, binary_sha1);
@@ -356,6 +363,12 @@ read_and_upload(struct brw_context *brw, struct program_cache *cache,
       SET_UPLOAD_PRAMS(vs, VS, vp, base.base)
       break;
    }
+   case MESA_SHADER_GEOMETRY: {
+      struct brw_geometry_program *gp =
+         (struct brw_geometry_program *)brw->geometry_program;
+      SET_UPLOAD_PRAMS(gs, GS, gp, base.base)
+      break;
+   }
    case MESA_SHADER_FRAGMENT: {
       struct brw_fragment_program *wp =
          (struct brw_fragment_program *)brw->fragment_program;
@@ -464,7 +477,6 @@ write_program_data(struct brw_context *brw, struct gl_shader_program *prog,
                    struct program_cache *cache, gl_shader_stage stage)
 {
    unsigned char sha1[20];
-   char buf[41];
 
    struct blob *binary = blob_create (NULL);
    if (binary == NULL)
@@ -558,6 +570,21 @@ write_cached_program(struct brw_context *brw)
       }
    }
 
+   if (prog->_LinkedShaders[MESA_SHADER_GEOMETRY]) {
+      struct brw_gs_prog_key gs_key;
+      brw_gs_populate_key(brw, &gs_key);
+      gs_key.program_string_id = 0;
+
+      if (!write_program_data(brw, prog, &gs_key,
+                              &brw->gs.prog_data->base.base,
+                              brw->gs.prog_data->program_size,
+                              brw->gs.prog_data, sizeof *brw->gs.prog_data,
+                              brw->gs.base.prog_offset, cache,
+                              MESA_SHADER_GEOMETRY)) {
+         return;
+      }
+   }
+
    if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT]) {
       struct brw_wm_prog_key wm_key;
       brw_wm_populate_key(brw, &wm_key);
-- 
2.7.4



More information about the mesa-dev mailing list