[Mesa-dev] [PATCH 47/88] i965: add cache fallback support

Timothy Arceri timothy.arceri at collabora.com
Sat Sep 24 05:25:28 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 979f057..d571d4a 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -28,7 +28,10 @@
 #include <compiler/glsl/ir_uniform.h>
 #include <compiler/glsl/cache.h>
 #include <compiler/glsl/blob.h>
+#include <compiler/glsl/program.h>
 #include <compiler/nir_types.h>
+#include <program/ir_to_mesa.h>
+#include <program/program.h>
 
 #include "brw_state.h"
 #include "brw_wm.h"
@@ -79,6 +82,53 @@ gen_wm_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)
@@ -313,8 +363,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);
    free(buffer);
 }
 
-- 
2.7.4



More information about the mesa-dev mailing list