[Mesa-dev] [PATCH 61/88] i965: add support for caching clip planes

Timothy Arceri timothy.arceri at collabora.com
Sat Sep 24 05:25:42 UTC 2016


---
 src/mesa/drivers/dri/i965/brw_shader_cache.c | 41 +++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index 7b5de32..3e00010 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -138,10 +138,18 @@ fallback_to_full_recompile(struct brw_context *brw,
 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)
+                  gl_shader_stage stage, struct gl_context *ctx,
+                  const struct brw_vs_prog_key *vs_key)
 {
    static const gl_constant_value zero = { 0 };
 
+   intptr_t eye_user_plane_base = 0;
+   intptr_t clip_user_plane_base = 0;
+   if (vs_key) {
+      eye_user_plane_base = blob_read_intptr(binary);
+      clip_user_plane_base = blob_read_intptr(binary);
+   }
+
    intptr_t parameter_values_base = blob_read_intptr(binary);
    intptr_t uniform_data_slots_base = blob_read_intptr(binary);
 
@@ -177,15 +185,26 @@ load_program_data(struct gl_shader_program *prog, struct blob_reader *binary,
       }
    }
 
+   unsigned cp_upper_boundary =
+      vs_key ? vs_key->nr_userclip_plane_consts * 4 : 0;
+
    for (unsigned i = 0; i < nr_params; i++) {
       intptr_t param = blob_read_intptr(binary);
-      ptrdiff_t p_offset, u_offset, i_offset;
+      ptrdiff_t p_offset, u_offset, i_offset, eye_offset, clip_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 (vs_key) {
+         eye_offset =
+            (param - eye_user_plane_base) / sizeof(gl_constant_value);
+         clip_offset =
+            (param - clip_user_plane_base) / sizeof(gl_constant_value);
+      }
       
       if (p_offset >= 0 && p_offset < 4 * param_list->NumParameters) {
          prog_data->param[i] =
@@ -195,6 +214,15 @@ load_program_data(struct gl_shader_program *prog, struct blob_reader *binary,
       } else if (i_offset >= 0 && i_offset < image_upper_boundary) {
          prog_data->param[i] =
             ((gl_constant_value *) prog_data->image_param) + i_offset;
+      } else if (vs_key &&
+                 eye_offset >= 0 && eye_offset < cp_upper_boundary) {
+         prog_data->param[i] =
+            ((gl_constant_value *) ctx->Transform.EyeUserPlane) + eye_offset;
+      } else if (vs_key &&
+                 clip_offset >= 0 && clip_offset < cp_upper_boundary) {
+         prog_data->param[i] =
+            ((gl_constant_value *) ctx->Transform._ClipUserPlane) +
+            clip_offset;
       } else {
          prog_data->param[i] = &zero;
       }
@@ -254,7 +282,8 @@ upload_cached_vs(struct brw_context *brw, struct blob_reader *binary,
    vs_prog_data = blob_read_bytes(binary, vs_prog_data_size);
    prog_data = &vs_prog_data->base.base;
 
-   load_program_data(prog, binary, prog_data, MESA_SHADER_VERTEX, &brw->ctx);
+   load_program_data(prog, binary, prog_data, MESA_SHADER_VERTEX, &brw->ctx,
+                     vs_key);
 
    struct brw_vertex_program *vp =
       (struct brw_vertex_program *)brw->vertex_program;
@@ -291,7 +320,7 @@ upload_cached_wm(struct brw_context *brw, struct blob_reader *binary,
    prog_data = &wm_prog_data->base;
 
    load_program_data(prog, binary, prog_data, MESA_SHADER_FRAGMENT,
-                     &brw->ctx);
+                     &brw->ctx, NULL);
 
    struct brw_fragment_program *wp =
       (struct brw_fragment_program *)brw->fragment_program;
@@ -481,6 +510,10 @@ write_cached_program(struct brw_context *brw)
       blob_write_uint32(binary, sizeof *brw->vs.prog_data);
       blob_write_bytes(binary, brw->vs.prog_data, sizeof *brw->vs.prog_data);
 
+      /* Cache clip plane pointers */
+      blob_write_intptr(binary, (intptr_t) brw->ctx.Transform.EyeUserPlane);
+      blob_write_intptr(binary, (intptr_t) brw->ctx.Transform._ClipUserPlane);
+
       write_program_data(prog, binary, &brw->vs.prog_data->base.base,
                          MESA_SHADER_VERTEX);
 
-- 
2.7.4



More information about the mesa-dev mailing list