[Mesa-dev] [PATCH 41/77] i965: add image param shader cache support

Timothy Arceri timothy.arceri at collabora.com
Mon Oct 3 06:05:00 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 8b31e71..a3dc2a3 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -25,6 +25,7 @@
 #include <compiler/glsl/cache.h>
 #include <compiler/glsl/ir_uniform.h>
 #include <compiler/glsl/shader_cache.h>
+#include <compiler/nir_types.h>
 #include <util/macros.h>
 #include <util/mesa-sha1.h>
 #include <main/mtypes.h>
@@ -96,20 +97,46 @@ load_program_data(struct gl_shader_program *prog, 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 < prog->NumUniformStorage; u++) {
+      struct gl_uniform_storage *storage = &prog->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 =
          prog->_LinkedShaders[stage]->Program->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] =
             ((gl_constant_value *) param_list->ParameterValues) + p_offset;
       } else if (u_offset >= 0 && u_offset < prog->NumUniformDataSlots) {
          prog_data->param[i] = prog->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;
       }
@@ -316,6 +343,8 @@ write_program_data(struct brw_context *brw, struct gl_shader_program *prog,
    blob_write_uint64(binary, ptr_to_uint64_t(prog->UniformDataSlots));
 
    blob_write_uint32(binary, stage_prog_data->nr_params);
+   blob_write_uint32(binary, stage_prog_data->nr_image_params);
+   blob_write_uint64(binary, ptr_to_uint64_t(stage_prog_data->image_param));
 
    for (unsigned i = 0; i < stage_prog_data->nr_params; i++) {
       blob_write_uint64(binary,
-- 
2.7.4



More information about the mesa-dev mailing list