[Mesa-dev] [PATCH 43/77] i965: add cache fallback support

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


---
 src/mesa/drivers/dri/i965/brw_shader_cache.c | 53 ++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index 0452641..bd9306b 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -24,8 +24,11 @@
 #include <compiler/glsl/blob.h>
 #include <compiler/glsl/cache.h>
 #include <compiler/glsl/ir_uniform.h>
+#include <compiler/glsl/program.h>
 #include <compiler/glsl/shader_cache.h>
 #include <compiler/nir_types.h>
+#include <program/ir_to_mesa.h>
+#include <program/program.h>
 #include <util/macros.h>
 #include <util/mesa-sha1.h>
 #include <main/mtypes.h>
@@ -78,6 +81,53 @@ gen_shader_sha1(struct brw_context *brw, struct gl_shader_program *prog,
 }
 
 static void
+fallback_to_full_recompile(struct brw_context *brw,
+                           struct gl_shader_program *prog)
+{
+   prog->program_written_to_cache = false;
+   if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) {
+      fprintf(stderr, "Falling back to compile from source.\n");
+   }
+
+   /* Cached program not found. Fall back to linking shaders but first
+    * compile any shaders we didn't compile earlier.
+    */
+   if (brw->vertex_program->Base.nir == NULL) {
+      struct gl_shader_program *shProg =
+         brw->ctx._Shader->CurrentProgram[MESA_SHADER_VERTEX];
+
+      for (unsigned i = 0; i < shProg->NumShaders; i++) {
+         _mesa_glsl_compile_shader(&brw->ctx, shProg->Shaders[i], false,
+                                   false, true);
+      }
+      _mesa_glsl_link_shader(&brw->ctx, shProg, true);
+
+      struct gl_program *vp =
+         shProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program;
+      brw->vertex_program = gl_vertex_program(vp);
+
+      struct gl_program *fp =
+         shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program;
+      brw->fragment_program = gl_fragment_program(fp);
+   }
+
+   if (brw->fragment_program->Base.nir == NULL) {
+      struct gl_shader_program *shProg =
+         brw->ctx._Shader->_CurrentFragmentProgram;
+
+      for (unsigned i = 0; i < shProg->NumShaders; i++) {
+         _mesa_glsl_compile_shader(&brw->ctx, shProg->Shaders[i], false,
+                                   false, true);
+      }
+      _mesa_glsl_link_shader(&brw->ctx, shProg, true);
+
+      struct gl_program *fp =
+         shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program;
+      brw->fragment_program = gl_fragment_program(fp);
+   }
+}
+
+static void
 load_program_data(struct gl_shader_program *prog, struct blob_reader *binary,
                   struct brw_stage_prog_data *prog_data,
                   gl_shader_stage stage, struct gl_context *ctx)
@@ -318,8 +368,7 @@ upload_cached_program(struct brw_context *brw, gl_shader_stage stage)
    return;
 
 FAIL:
-   /*FIXME: Fall back and compile from source here. */
-   prog->program_written_to_cache = false;
+   fallback_to_full_recompile(brw, prog);
 }
 
 static bool
-- 
2.7.4



More information about the mesa-dev mailing list