i965: Add shader cache support for compute
authorJordan Justen <jordan.l.justen@intel.com>
Thu, 2 Mar 2017 00:52:23 +0000 (16:52 -0800)
committerJordan Justen <jordan.l.justen@intel.com>
Wed, 1 Nov 2017 06:36:54 +0000 (23:36 -0700)
v2:
 * Use MAYBE_UNUSED. (Matt)

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_cs.c
src/mesa/drivers/dri/i965/brw_cs.h
src/mesa/drivers/dri/i965/brw_disk_cache.c
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/brw_state_upload.c

index 1d34a8a79d18cd18b58f218decd0c25a05c93788..71d0beaae977d67876e72841421154fb23e3c263 100644 (file)
@@ -130,7 +130,7 @@ brw_codegen_cs_prog(struct brw_context *brw,
 }
 
 
-static void
+void
 brw_cs_populate_key(struct brw_context *brw, struct brw_cs_prog_key *key)
 {
    struct gl_context *ctx = &brw->ctx;
@@ -168,14 +168,20 @@ brw_upload_cs_prog(struct brw_context *brw)
 
    brw_cs_populate_key(brw, &key);
 
-   if (!brw_search_cache(&brw->cache, BRW_CACHE_CS_PROG,
-                         &key, sizeof(key),
-                         &brw->cs.base.prog_offset,
-                         &brw->cs.base.prog_data)) {
-      bool success = brw_codegen_cs_prog(brw, cp, &key);
-      (void) success;
-      assert(success);
-   }
+   if (brw_search_cache(&brw->cache, BRW_CACHE_CS_PROG,
+                        &key, sizeof(key),
+                        &brw->cs.base.prog_offset,
+                        &brw->cs.base.prog_data))
+      return;
+
+   if (brw_disk_cache_upload_program(brw, MESA_SHADER_COMPUTE))
+      return;
+
+   cp = (struct brw_program *) brw->programs[MESA_SHADER_COMPUTE];
+   cp->id = key.program_string_id;
+
+   MAYBE_UNUSED bool success = brw_codegen_cs_prog(brw, cp, &key);
+   assert(success);
 }
 
 
index 890a0c8a8070894a7703396c953be321eb03744b..60eb19c35948e140ffcfceca4ec428c1248cd5c6 100644 (file)
@@ -32,6 +32,9 @@ extern "C" {
 void
 brw_upload_cs_prog(struct brw_context *brw);
 
+void
+brw_cs_populate_key(struct brw_context *brw, struct brw_cs_prog_key *key);
+
 #ifdef __cplusplus
 }
 #endif
index 3511eaacf02f3b74b70dfe323b13b7646c02efe1..eef58d5ba3f855fe0f79ac63f55f8723aff5564e 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "brw_context.h"
 #include "brw_program.h"
+#include "brw_cs.h"
 #include "brw_gs.h"
 #include "brw_state.h"
 #include "brw_vs.h"
@@ -137,6 +138,10 @@ read_and_upload(struct brw_context *brw, struct disk_cache *cache,
       brw_wm_populate_key(brw, &prog_key.wm);
       prog_key.wm.program_string_id = 0;
       break;
+   case MESA_SHADER_COMPUTE:
+      brw_cs_populate_key(brw, &prog_key.cs);
+      prog_key.cs.program_string_id = 0;
+      break;
    default:
       unreachable("Unsupported stage!");
    }
@@ -211,6 +216,11 @@ read_and_upload(struct brw_context *brw, struct disk_cache *cache,
       cache_id = BRW_CACHE_FS_PROG;
       stage_state = &brw->wm.base;
       break;
+   case MESA_SHADER_COMPUTE:
+      prog_key.cs.program_string_id = brw_program(prog)->id;
+      cache_id = BRW_CACHE_CS_PROG;
+      stage_state = &brw->cs.base;
+      break;
    default:
       unreachable("Unsupported stage!");
    }
@@ -288,7 +298,7 @@ write_program_data(struct brw_context *brw, struct gl_program *prog,
 }
 
 void
-brw_disk_cache_write_program(struct brw_context *brw)
+brw_disk_cache_write_render_programs(struct brw_context *brw)
 {
    struct disk_cache *cache = brw->ctx.Cache;
    if (cache == NULL)
@@ -350,3 +360,23 @@ brw_disk_cache_write_program(struct brw_context *brw)
                          MESA_SHADER_FRAGMENT);
    }
 }
+
+void
+brw_disk_cache_write_compute_program(struct brw_context *brw)
+{
+   struct disk_cache *cache = brw->ctx.Cache;
+   if (cache == NULL)
+      return;
+
+   struct gl_program *prog =
+      brw->ctx._Shader->CurrentProgram[MESA_SHADER_COMPUTE];
+   if (prog && !prog->program_written_to_cache) {
+      struct brw_cs_prog_key cs_key;
+      brw_cs_populate_key(brw, &cs_key);
+      cs_key.program_string_id = 0;
+
+      write_program_data(brw, prog, &cs_key, brw->cs.base.prog_data,
+                         brw->cs.base.prog_offset, cache,
+                         MESA_SHADER_COMPUTE);
+   }
+}
index 6f2e0501b4b8677693a0d16d526a5aeb8f0251b6..c98b7facd5770f6c2815c2cb74b27589d79ca008 100644 (file)
@@ -134,7 +134,8 @@ void gen8_write_pma_stall_bits(struct brw_context *brw,
 /* brw_disk_cache.c */
 bool brw_disk_cache_upload_program(struct brw_context *brw,
                                    gl_shader_stage stage);
-void brw_disk_cache_write_program(struct brw_context *brw);
+void brw_disk_cache_write_compute_program(struct brw_context *brw);
+void brw_disk_cache_write_render_programs(struct brw_context *brw);
 
 /***********************************************************************
  * brw_state.c
index 60f54a9cd0bd0f5c4eee292519060eba57a8843d..9e1cf54abdacca73a58232e3d9d3413e85244374 100644 (file)
@@ -419,9 +419,10 @@ brw_upload_programs(struct brw_context *brw,
          brw_upload_sf_prog(brw);
       }
 
-      brw_disk_cache_write_program(brw);
+      brw_disk_cache_write_render_programs(brw);
    } else if (pipeline == BRW_COMPUTE_PIPELINE) {
       brw_upload_cs_prog(brw);
+      brw_disk_cache_write_compute_program(brw);
    }
 }