[Mesa-dev] [PATCH 28/56] i965: add image param shader cache support

Timothy Arceri timothy.arceri at collabora.com
Tue Nov 29 03:58:27 UTC 2016


---
 src/mesa/drivers/dri/i965/brw_shader_cache.c | 31 +++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index 4798809..cf90b0e 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -24,6 +24,7 @@
 #include "compiler/glsl/blob.h"
 #include "compiler/glsl/ir_uniform.h"
 #include "compiler/glsl/shader_cache.h"
+#include "compiler/nir_types.h"
 #include "main/mtypes.h"
 #include "util/disk_cache.h"
 #include "util/macros.h"
@@ -96,13 +97,36 @@ load_program_data(struct gl_program *glprog, struct blob_reader *binary,
               prog_data->nr_params, prog_data->param);
    }
 
+   uint32_t nr_image_params = blob_read_uint32(binary);
+   assert(nr_image_params == prog_data->nr_image_params);
+
+   prog_data->image_param = rzalloc_array(NULL, struct brw_image_param,
+                                          nr_image_params);
+
+   uint64_t image_params_base = blob_read_uint64(binary);
+
+   /* calculate image bounds */
+   unsigned image_upper_boundary = 0;
+   for (unsigned u = 0; u < glprog->sh.data->NumUniformStorage; u++) {
+      struct gl_uniform_storage *storage = &glprog->sh.data->UniformStorage[u];
+
+      if (storage->builtin)
+         continue;
+
+      if (glsl_get_base_type(storage->type) == GLSL_TYPE_IMAGE) {
+         image_upper_boundary +=
+            BRW_IMAGE_PARAM_SIZE * MAX2(storage->array_elements, 1);
+      }
+   }
+
    for (unsigned i = 0; i < nr_params; i++) {
       uint64_t param = blob_read_uint64(binary);
-      ptrdiff_t p_offset, u_offset;
+      ptrdiff_t p_offset, u_offset, i_offset;
       struct gl_program_parameter_list *param_list = glprog->Parameters;
 
       p_offset = (param - parameter_values_base) / sizeof(gl_constant_value);
       u_offset = (param - uniform_data_slots_base) / sizeof(gl_constant_value);
+      i_offset = (param - image_params_base) / sizeof(gl_constant_value);
       
       if (p_offset >= 0 && p_offset < 4 * param_list->NumParameters) {
          prog_data->param[i] =
@@ -110,6 +134,9 @@ load_program_data(struct gl_program *glprog, struct blob_reader *binary,
       } else if (u_offset >= 0 &&
                  u_offset < glprog->sh.data->NumUniformDataSlots) {
          prog_data->param[i] = glprog->sh.data->UniformDataSlots + u_offset;
+      } else if (i_offset >= 0 && i_offset < image_upper_boundary) {
+         prog_data->param[i] =
+            ((gl_constant_value *) prog_data->image_param) + i_offset;
       } else {
          prog_data->param[i] = &zero;
       }
@@ -323,6 +350,8 @@ write_program_data(struct brw_context *brw, struct gl_program *prog,
    blob_write_uint64(binary, ptr_to_uint64_t(prog->sh.data->UniformDataSlots));
 
    blob_write_uint32(binary, prog_data->nr_params);
+   blob_write_uint32(binary, prog_data->nr_image_params);
+   blob_write_uint64(binary, ptr_to_uint64_t(prog_data->image_param));
 
    for (unsigned i = 0; i < prog_data->nr_params; i++) {
       blob_write_uint64(binary, ptr_to_uint64_t((void *) prog_data->param[i]));
-- 
2.7.4



More information about the mesa-dev mailing list