i965/blorp: Expose the shader cache through function pointers
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 26 Aug 2016 17:07:40 +0000 (10:07 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 29 Aug 2016 19:17:34 +0000 (12:17 -0700)
This sanitizes blorp's access to the i965 driver's shader cache by patching
it through the blorp_context.  When we start using blorp in Vulkan, we will
simply have to implement such a caching interface in the Vulkan driver.

Note: In my first attempt at this, I simplified it down to a single
upload_shader entrypoint and implemented the caching inside of blorp.  This
doesn't work, however, because the i965 driver will, on occation, dump its
entire cache and start over.  When this happens, blorp needs to be able to
recompile its shaders and re-upload them.  It's easiest to just expose the
caching interface.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
src/mesa/drivers/dri/i965/blorp.h
src/mesa/drivers/dri/i965/blorp_blit.c
src/mesa/drivers/dri/i965/blorp_clear.c
src/mesa/drivers/dri/i965/brw_blorp.c

index 7dbf022b74bdf3abd0f48348f521f07d88a262e4..602d97e2d9d0d1e9a6b1b10baccf8f4f19546293 100644 (file)
@@ -41,6 +41,15 @@ struct blorp_context {
    void *driver_ctx;
 
    const struct isl_device *isl_dev;
+
+   bool (*lookup_shader)(struct blorp_context *blorp,
+                         const void *key, uint32_t key_size,
+                         uint32_t *kernel_out, void *prog_data_out);
+   void (*upload_shader)(struct blorp_context *blorp,
+                         const void *key, uint32_t key_size,
+                         const void *kernel, uint32_t kernel_size,
+                         const void *prog_data, uint32_t prog_data_size,
+                         uint32_t *kernel_out, void *prog_data_out);
 };
 
 void blorp_init(struct blorp_context *blorp, void *driver_ctx,
index a4b3fe0e5b10286780e4c6d70c900c4e8fcf73f9..0291e01da8e5f5c2d0a0708b9b5c6aa58216cb22 100644 (file)
@@ -32,7 +32,6 @@
 
 #include "blorp_priv.h"
 #include "brw_context.h"
-#include "brw_state.h"
 #include "brw_meta_util.h"
 
 #define FILE_DEBUG_FLAG DEBUG_BLORP
@@ -1196,9 +1195,8 @@ brw_blorp_get_blit_kernel(struct brw_context *brw,
                           struct brw_blorp_params *params,
                           const struct brw_blorp_blit_prog_key *prog_key)
 {
-   if (brw_search_cache(&brw->cache, BRW_CACHE_BLORP_PROG,
-                        prog_key, sizeof(*prog_key),
-                        &params->wm_prog_kernel, &params->wm_prog_data))
+   if (brw->blorp.lookup_shader(&brw->blorp, prog_key, sizeof(*prog_key),
+                                &params->wm_prog_kernel, &params->wm_prog_data))
       return;
 
    const unsigned *program;
@@ -1219,11 +1217,10 @@ brw_blorp_get_blit_kernel(struct brw_context *brw,
    program = brw_blorp_compile_nir_shader(brw, nir, &wm_key, false,
                                           &prog_data, &program_size);
 
-   brw_upload_cache(&brw->cache, BRW_CACHE_BLORP_PROG,
-                    prog_key, sizeof(*prog_key),
-                    program, program_size,
-                    &prog_data, sizeof(prog_data),
-                    &params->wm_prog_kernel, &params->wm_prog_data);
+   brw->blorp.upload_shader(&brw->blorp, prog_key, sizeof(*prog_key),
+                            program, program_size,
+                            &prog_data, sizeof(prog_data),
+                            &params->wm_prog_kernel, &params->wm_prog_data);
 }
 
 static void
index 2da08f83c7a64e09620a00a803b01bf4d4f01b6f..5b8ceec5cf0ffb40ee2a817505d7f6fc3b59b479 100644 (file)
@@ -35,7 +35,6 @@
 #include "brw_meta_util.h"
 #include "brw_context.h"
 #include "brw_eu.h"
-#include "brw_state.h"
 
 #include "nir_builder.h"
 
@@ -56,9 +55,8 @@ brw_blorp_params_get_clear_kernel(struct brw_context *brw,
    memset(&blorp_key, 0, sizeof(blorp_key));
    blorp_key.use_simd16_replicated_data = use_replicated_data;
 
-   if (brw_search_cache(&brw->cache, BRW_CACHE_BLORP_PROG,
-                        &blorp_key, sizeof(blorp_key),
-                        &params->wm_prog_kernel, &params->wm_prog_data))
+   if (brw->blorp.lookup_shader(&brw->blorp, &blorp_key, sizeof(blorp_key),
+                                &params->wm_prog_kernel, &params->wm_prog_data))
       return;
 
    void *mem_ctx = ralloc_context(NULL);
@@ -88,11 +86,10 @@ brw_blorp_params_get_clear_kernel(struct brw_context *brw,
       brw_blorp_compile_nir_shader(brw, b.shader, &wm_key, use_replicated_data,
                                    &prog_data, &program_size);
 
-   brw_upload_cache(&brw->cache, BRW_CACHE_BLORP_PROG,
-                    &blorp_key, sizeof(blorp_key),
-                    program, program_size,
-                    &prog_data, sizeof(prog_data),
-                    &params->wm_prog_kernel, &params->wm_prog_data);
+   brw->blorp.upload_shader(&brw->blorp, &blorp_key, sizeof(blorp_key),
+                            program, program_size,
+                            &prog_data, sizeof(prog_data),
+                            &params->wm_prog_kernel, &params->wm_prog_data);
 
    ralloc_free(mem_ctx);
 }
index 727be6325609f823ed78d76ffff18e2b1cefd917..3dcec1de47c1cac65b8c3bb2ee7d6784915614d6 100644 (file)
 
 #define FILE_DEBUG_FLAG DEBUG_BLORP
 
+static bool
+brw_blorp_lookup_shader(struct blorp_context *blorp,
+                        const void *key, uint32_t key_size,
+                        uint32_t *kernel_out, void *prog_data_out)
+{
+   struct brw_context *brw = blorp->driver_ctx;
+   return brw_search_cache(&brw->cache, BRW_CACHE_BLORP_PROG,
+                           key, key_size, kernel_out, prog_data_out);
+}
+
+static void
+brw_blorp_upload_shader(struct blorp_context *blorp,
+                        const void *key, uint32_t key_size,
+                        const void *kernel, uint32_t kernel_size,
+                        const void *prog_data, uint32_t prog_data_size,
+                        uint32_t *kernel_out, void *prog_data_out)
+{
+   struct brw_context *brw = blorp->driver_ctx;
+   brw_upload_cache(&brw->cache, BRW_CACHE_BLORP_PROG, key, key_size,
+                    kernel, kernel_size, prog_data, prog_data_size,
+                    kernel_out, prog_data_out);
+}
+
 void
 brw_blorp_init(struct brw_context *brw)
 {
    blorp_init(&brw->blorp, brw, &brw->isl_dev);
+
+   brw->blorp.lookup_shader = brw_blorp_lookup_shader;
+   brw->blorp.upload_shader = brw_blorp_upload_shader;
 }
 
 static void