[Mesa-dev] [PATCH] i965: create populate key functions for tcs and tes

Timothy Arceri timothy.arceri at collabora.com
Sat Jun 18 06:18:17 UTC 2016


These will be used by the on disk shader cache.
---
 src/mesa/drivers/dri/i965/brw_program.h      | 10 ++--
 src/mesa/drivers/dri/i965/brw_state_upload.c | 18 +-------
 src/mesa/drivers/dri/i965/brw_tcs.c          | 68 +++++++++++++++++-----------
 src/mesa/drivers/dri/i965/brw_tes.c          | 62 ++++++++++++++++---------
 4 files changed, 91 insertions(+), 67 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_program.h b/src/mesa/drivers/dri/i965/brw_program.h
index 4d6299f..7649f8a 100644
--- a/src/mesa/drivers/dri/i965/brw_program.h
+++ b/src/mesa/drivers/dri/i965/brw_program.h
@@ -62,10 +62,12 @@ void
 brw_dump_ir(const char *stage, struct gl_shader_program *shader_prog,
             struct gl_shader *shader, struct gl_program *prog);
 
-void brw_upload_tcs_prog(struct brw_context *brw,
-                         uint64_t per_vertex_slots, uint32_t per_patch_slots);
-void brw_upload_tes_prog(struct brw_context *brw,
-                         uint64_t per_vertex_slots, uint32_t per_patch_slots);
+void brw_upload_tcs_prog(struct brw_context *brw);
+void brw_tcs_populate_key(struct brw_context *brw,
+                          struct brw_tcs_prog_key *key);
+void brw_upload_tes_prog(struct brw_context *brw);
+void brw_tes_populate_key(struct brw_context *brw,
+                          struct brw_tes_prog_key *key);
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/src/mesa/drivers/dri/i965/brw_state_upload.c b/src/mesa/drivers/dri/i965/brw_state_upload.c
index e2e39ba..ec27830 100644
--- a/src/mesa/drivers/dri/i965/brw_state_upload.c
+++ b/src/mesa/drivers/dri/i965/brw_state_upload.c
@@ -678,22 +678,8 @@ static inline void
 brw_upload_tess_programs(struct brw_context *brw)
 {
    if (brw->tess_eval_program) {
-      uint64_t per_vertex_slots = brw->tess_eval_program->Base.InputsRead;
-      uint32_t per_patch_slots =
-         brw->tess_eval_program->Base.PatchInputsRead;
-
-      /* The TCS may have additional outputs which aren't read by the
-       * TES (possibly for cross-thread communication).  These need to
-       * be stored in the Patch URB Entry as well.
-       */
-      if (brw->tess_ctrl_program) {
-         per_vertex_slots |= brw->tess_ctrl_program->Base.OutputsWritten;
-         per_patch_slots |=
-            brw->tess_ctrl_program->Base.PatchOutputsWritten;
-      }
-
-      brw_upload_tcs_prog(brw, per_vertex_slots, per_patch_slots);
-      brw_upload_tes_prog(brw, per_vertex_slots, per_patch_slots);
+      brw_upload_tcs_prog(brw);
+      brw_upload_tes_prog(brw);
    } else {
       brw->tcs.prog_data = NULL;
       brw->tcs.base.prog_data = NULL;
diff --git a/src/mesa/drivers/dri/i965/brw_tcs.c b/src/mesa/drivers/dri/i965/brw_tcs.c
index 8b86c69..17fa91a 100644
--- a/src/mesa/drivers/dri/i965/brw_tcs.c
+++ b/src/mesa/drivers/dri/i965/brw_tcs.c
@@ -310,53 +310,69 @@ brw_codegen_tcs_prog(struct brw_context *brw,
    return true;
 }
 
-
 void
-brw_upload_tcs_prog(struct brw_context *brw,
-                    uint64_t per_vertex_slots,
-                    uint32_t per_patch_slots)
+brw_tcs_populate_key(struct brw_context *brw,
+                     struct brw_tcs_prog_key *key)
 {
-   struct gl_context *ctx = &brw->ctx;
-   struct gl_shader_program **current = ctx->_Shader->CurrentProgram;
-   struct brw_stage_state *stage_state = &brw->tcs.base;
-   struct brw_tcs_prog_key key;
-   /* BRW_NEW_TESS_PROGRAMS */
+   uint64_t per_vertex_slots = brw->tess_eval_program->Base.InputsRead;
+   uint32_t per_patch_slots = brw->tess_eval_program->Base.PatchInputsRead;
+
    struct brw_tess_ctrl_program *tcp =
       (struct brw_tess_ctrl_program *) brw->tess_ctrl_program;
    struct brw_tess_eval_program *tep =
       (struct brw_tess_eval_program *) brw->tess_eval_program;
-   assert(tep);
-
-   if (!brw_state_dirty(brw,
-                        _NEW_TEXTURE,
-                        BRW_NEW_PATCH_PRIMITIVE |
-                        BRW_NEW_TESS_PROGRAMS))
-      return;
-
    struct gl_program *prog = &tcp->program.Base;
+   struct brw_stage_state *stage_state = &brw->tcs.base;
 
-   memset(&key, 0, sizeof(key));
+   memset(key, 0, sizeof(*key));
+
+   if (brw->tess_ctrl_program) {
+      per_vertex_slots |= brw->tess_ctrl_program->Base.OutputsWritten;
+      per_patch_slots |= brw->tess_ctrl_program->Base.PatchOutputsWritten;
+   }
 
    if (brw->gen < 8 || !tcp)
-      key.input_vertices = ctx->TessCtrlProgram.patch_vertices;
-   key.outputs_written = per_vertex_slots;
-   key.patch_outputs_written = per_patch_slots;
+      key->input_vertices = brw->ctx.TessCtrlProgram.patch_vertices;
+   key->outputs_written = per_vertex_slots;
+   key->patch_outputs_written = per_patch_slots;
 
    /* We need to specialize our code generation for tessellation levels
     * based on the domain the DS is expecting to tessellate.
     */
-   key.tes_primitive_mode = tep->program.PrimitiveMode;
+   key->tes_primitive_mode = tep->program.PrimitiveMode;
 
    if (tcp) {
-      key.program_string_id = tcp->id;
+      key->program_string_id = tcp->id;
 
       /* _NEW_TEXTURE */
-      brw_populate_sampler_prog_key_data(ctx, prog, stage_state->sampler_count,
-                                         &key.tex);
+      brw_populate_sampler_prog_key_data(&brw->ctx, prog,
+                                         stage_state->sampler_count,
+                                         &key->tex);
    } else {
-      key.outputs_written = tep->program.Base.InputsRead;
+      key->outputs_written = tep->program.Base.InputsRead;
    }
+}
+
+void
+brw_upload_tcs_prog(struct brw_context *brw)
+{
+   struct gl_shader_program **current = brw->ctx._Shader->CurrentProgram;
+   struct brw_stage_state *stage_state = &brw->tcs.base;
+   struct brw_tcs_prog_key key;
+   /* BRW_NEW_TESS_PROGRAMS */
+   struct brw_tess_ctrl_program *tcp =
+      (struct brw_tess_ctrl_program *) brw->tess_ctrl_program;
+   struct brw_tess_eval_program *tep =
+      (struct brw_tess_eval_program *) brw->tess_eval_program;
+   assert(tep);
+
+   if (!brw_state_dirty(brw,
+                        _NEW_TEXTURE,
+                        BRW_NEW_PATCH_PRIMITIVE |
+                        BRW_NEW_TESS_PROGRAMS))
+      return;
 
+   brw_tcs_populate_key(brw, &key);
 
    if (!brw_search_cache(&brw->cache, BRW_CACHE_TCS_PROG,
                          &key, sizeof(key),
diff --git a/src/mesa/drivers/dri/i965/brw_tes.c b/src/mesa/drivers/dri/i965/brw_tes.c
index bac9949..ba9b038 100644
--- a/src/mesa/drivers/dri/i965/brw_tes.c
+++ b/src/mesa/drivers/dri/i965/brw_tes.c
@@ -228,42 +228,62 @@ brw_codegen_tes_prog(struct brw_context *brw,
    return true;
 }
 
-
 void
-brw_upload_tes_prog(struct brw_context *brw,
-                    uint64_t per_vertex_slots,
-                    uint32_t per_patch_slots)
+brw_tes_populate_key(struct brw_context *brw,
+                     struct brw_tes_prog_key *key)
 {
-   struct gl_context *ctx = &brw->ctx;
-   struct gl_shader_program **current = ctx->_Shader->CurrentProgram;
-   struct brw_stage_state *stage_state = &brw->tes.base;
-   struct brw_tes_prog_key key;
-   /* BRW_NEW_TESS_PROGRAMS */
-   struct brw_tess_eval_program *tep =
-      (struct brw_tess_eval_program *) brw->tess_eval_program;
 
-   if (!brw_state_dirty(brw,
-                        _NEW_TEXTURE,
-                        BRW_NEW_TESS_PROGRAMS))
-      return;
+   uint64_t per_vertex_slots = brw->tess_eval_program->Base.InputsRead;
+   uint32_t per_patch_slots = brw->tess_eval_program->Base.PatchInputsRead;
 
+   struct brw_tess_eval_program *tep =
+      (struct brw_tess_eval_program *) brw->tess_eval_program;
    struct gl_program *prog = &tep->program.Base;
+   struct brw_stage_state *stage_state = &brw->tes.base;
 
-   memset(&key, 0, sizeof(key));
+   memset(key, 0, sizeof(*key));
 
-   key.program_string_id = tep->id;
+   key->program_string_id = tep->id;
+
+   /* The TCS may have additional outputs which aren't read by the
+    * TES (possibly for cross-thread communication).  These need to
+    * be stored in the Patch URB Entry as well.
+    */
+   if (brw->tess_ctrl_program) {
+      per_vertex_slots |= brw->tess_ctrl_program->Base.OutputsWritten;
+      per_patch_slots |= brw->tess_ctrl_program->Base.PatchOutputsWritten;
+   }
 
    /* Ignore gl_TessLevelInner/Outer - we treat them as system values,
     * not inputs, and they're always present in the URB entry regardless
     * of whether or not we read them.
     */
-   key.inputs_read = per_vertex_slots &
+   key->inputs_read = per_vertex_slots &
       ~(VARYING_BIT_TESS_LEVEL_INNER | VARYING_BIT_TESS_LEVEL_OUTER);
-   key.patch_inputs_read = per_patch_slots;
+   key->patch_inputs_read = per_patch_slots;
 
    /* _NEW_TEXTURE */
-   brw_populate_sampler_prog_key_data(ctx, prog, stage_state->sampler_count,
-                                      &key.tex);
+   brw_populate_sampler_prog_key_data(&brw->ctx, prog,
+                                      stage_state->sampler_count,
+                                      &key->tex);
+}
+
+void
+brw_upload_tes_prog(struct brw_context *brw)
+{
+   struct gl_shader_program **current = brw->ctx._Shader->CurrentProgram;
+   struct brw_stage_state *stage_state = &brw->tes.base;
+   struct brw_tes_prog_key key;
+   /* BRW_NEW_TESS_PROGRAMS */
+   struct brw_tess_eval_program *tep =
+      (struct brw_tess_eval_program *) brw->tess_eval_program;
+
+   if (!brw_state_dirty(brw,
+                        _NEW_TEXTURE,
+                        BRW_NEW_TESS_PROGRAMS))
+      return;
+
+   brw_tes_populate_key(brw, &key);
 
    if (!brw_search_cache(&brw->cache, BRW_CACHE_TES_PROG,
                          &key, sizeof(key),
-- 
2.5.5



More information about the mesa-dev mailing list