[Mesa-dev] [PATCH 01/68] i965: move program id generation

Timothy Arceri timothy.arceri at collabora.com
Wed Jun 1 06:22:42 UTC 2016


This generates the program ids at cache upload time rather than at
program creation time.

Moving the id generation here will be useful for on-disk shader
cache support because it means we don't generate ids if there was
a cache miss and we had to fall back to compiling from source.
This increases the likelyhood of finding a match.

This also changes the workaround that checked for an id of 0 to
dectect a missing TCS. Now we check for the name "tcs_passthrough"
since id will now always be 0 at this point.
---
 src/mesa/drivers/dri/i965/brw_blorp_blit.cpp  |  4 +-
 src/mesa/drivers/dri/i965/brw_blorp_clear.cpp |  2 +-
 src/mesa/drivers/dri/i965/brw_clip.c          |  2 +-
 src/mesa/drivers/dri/i965/brw_cs.c            |  2 +-
 src/mesa/drivers/dri/i965/brw_ff_gs.c         |  2 +-
 src/mesa/drivers/dri/i965/brw_gs.c            |  2 +-
 src/mesa/drivers/dri/i965/brw_program.c       | 31 +----------
 src/mesa/drivers/dri/i965/brw_sf.c            |  2 +-
 src/mesa/drivers/dri/i965/brw_state.h         |  4 +-
 src/mesa/drivers/dri/i965/brw_state_cache.c   | 75 ++++++++++++++++++++++++++-
 src/mesa/drivers/dri/i965/brw_tcs.c           |  2 +-
 src/mesa/drivers/dri/i965/brw_tes.c           |  2 +-
 src/mesa/drivers/dri/i965/brw_vs.c            |  3 +-
 src/mesa/drivers/dri/i965/brw_wm.c            |  2 +-
 14 files changed, 90 insertions(+), 45 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp b/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp
index 1b8e112..dd1477c 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp
+++ b/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp
@@ -1524,10 +1524,10 @@ brw_blorp_get_blit_kernel(struct brw_context *brw,
                                           &prog_data, &program_size);
 
    brw_upload_cache(&brw->cache, BRW_CACHE_BLORP_PROG,
-                    prog_key, sizeof(*prog_key),
+                    (void *) prog_key, sizeof(*prog_key),
                     program, program_size,
                     &prog_data, sizeof(prog_data),
-                    &params->wm_prog_kernel, &params->wm_prog_data);
+                    &params->wm_prog_kernel, &params->wm_prog_data, NULL);
 }
 
 static void
diff --git a/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp b/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp
index 2515a04..37950a8 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp
+++ b/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp
@@ -91,7 +91,7 @@ brw_blorp_params_get_clear_kernel(struct brw_context *brw,
                     &blorp_key, sizeof(blorp_key),
                     program, program_size,
                     &prog_data, sizeof(prog_data),
-                    &params->wm_prog_kernel, &params->wm_prog_data);
+                    &params->wm_prog_kernel, &params->wm_prog_data, NULL);
 
    ralloc_free(mem_ctx);
 }
diff --git a/src/mesa/drivers/dri/i965/brw_clip.c b/src/mesa/drivers/dri/i965/brw_clip.c
index 4c9d5c5..2ea3b91 100644
--- a/src/mesa/drivers/dri/i965/brw_clip.c
+++ b/src/mesa/drivers/dri/i965/brw_clip.c
@@ -126,7 +126,7 @@ static void compile_clip_prog( struct brw_context *brw,
 		    &c.key, sizeof(c.key),
 		    program, program_size,
 		    &c.prog_data, sizeof(c.prog_data),
-		    &brw->clip.prog_offset, &brw->clip.prog_data);
+                    &brw->clip.prog_offset, &brw->clip.prog_data, NULL);
    ralloc_free(mem_ctx);
 }
 
diff --git a/src/mesa/drivers/dri/i965/brw_cs.c b/src/mesa/drivers/dri/i965/brw_cs.c
index a9cbde9..d553609 100644
--- a/src/mesa/drivers/dri/i965/brw_cs.c
+++ b/src/mesa/drivers/dri/i965/brw_cs.c
@@ -157,7 +157,7 @@ brw_codegen_cs_prog(struct brw_context *brw,
                     key, sizeof(*key),
                     program, program_size,
                     &prog_data, sizeof(prog_data),
-                    &brw->cs.base.prog_offset, &brw->cs.prog_data);
+                    &brw->cs.base.prog_offset, &brw->cs.prog_data, cp);
    ralloc_free(mem_ctx);
 
    return true;
diff --git a/src/mesa/drivers/dri/i965/brw_ff_gs.c b/src/mesa/drivers/dri/i965/brw_ff_gs.c
index 9065e08..792f907 100644
--- a/src/mesa/drivers/dri/i965/brw_ff_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_ff_gs.c
@@ -144,7 +144,7 @@ brw_codegen_ff_gs_prog(struct brw_context *brw,
 		    &c.key, sizeof(c.key),
 		    program, program_size,
 		    &c.prog_data, sizeof(c.prog_data),
-		    &brw->ff_gs.prog_offset, &brw->ff_gs.prog_data);
+		    &brw->ff_gs.prog_offset, &brw->ff_gs.prog_data, NULL);
    ralloc_free(mem_ctx);
 }
 
diff --git a/src/mesa/drivers/dri/i965/brw_gs.c b/src/mesa/drivers/dri/i965/brw_gs.c
index 7ead182..6861b38 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_gs.c
@@ -190,7 +190,7 @@ brw_codegen_gs_prog(struct brw_context *brw,
                     key, sizeof(*key),
                     program, program_size,
                     &prog_data, sizeof(prog_data),
-                    &stage_state->prog_offset, &brw->gs.prog_data);
+                    &stage_state->prog_offset, &brw->gs.prog_data, gp);
    ralloc_free(mem_ctx);
 
    return true;
diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c
index 792f81b..4b678c0 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -29,7 +29,6 @@
   *   Keith Whitwell <keithw at vmware.com>
   */
 
-#include <pthread.h>
 #include "main/imports.h"
 #include "program/prog_parameter.h"
 #include "program/prog_print.h"
@@ -113,29 +112,15 @@ brw_create_nir(struct brw_context *brw,
    return nir;
 }
 
-static unsigned
-get_new_program_id(struct intel_screen *screen)
-{
-   static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
-   pthread_mutex_lock(&m);
-   unsigned id = screen->program_id++;
-   pthread_mutex_unlock(&m);
-   return id;
-}
-
 static struct gl_program *brwNewProgram( struct gl_context *ctx,
 				      GLenum target,
 				      GLuint id )
 {
-   struct brw_context *brw = brw_context(ctx);
-
    switch (target) {
    case GL_VERTEX_PROGRAM_ARB: {
       struct brw_vertex_program *prog = CALLOC_STRUCT(brw_vertex_program);
       if (prog) {
-	 prog->id = get_new_program_id(brw->intelScreen);
-
-	 return _mesa_init_gl_program(&prog->program.Base, target, id);
+         return _mesa_init_gl_program(&prog->program.Base, target, id);
       }
       else
 	 return NULL;
@@ -144,9 +129,7 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
    case GL_FRAGMENT_PROGRAM_ARB: {
       struct brw_fragment_program *prog = CALLOC_STRUCT(brw_fragment_program);
       if (prog) {
-	 prog->id = get_new_program_id(brw->intelScreen);
-
-	 return _mesa_init_gl_program(&prog->program.Base, target, id);
+         return _mesa_init_gl_program(&prog->program.Base, target, id);
       }
       else
 	 return NULL;
@@ -155,8 +138,6 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
    case GL_GEOMETRY_PROGRAM_NV: {
       struct brw_geometry_program *prog = CALLOC_STRUCT(brw_geometry_program);
       if (prog) {
-         prog->id = get_new_program_id(brw->intelScreen);
-
          return _mesa_init_gl_program(&prog->program.Base, target, id);
       } else {
          return NULL;
@@ -166,8 +147,6 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
    case GL_TESS_CONTROL_PROGRAM_NV: {
       struct brw_tess_ctrl_program *prog = CALLOC_STRUCT(brw_tess_ctrl_program);
       if (prog) {
-         prog->id = get_new_program_id(brw->intelScreen);
-
          return _mesa_init_gl_program(&prog->program.Base, target, id);
       } else {
          return NULL;
@@ -177,8 +156,6 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
    case GL_TESS_EVALUATION_PROGRAM_NV: {
       struct brw_tess_eval_program *prog = CALLOC_STRUCT(brw_tess_eval_program);
       if (prog) {
-         prog->id = get_new_program_id(brw->intelScreen);
-
          return _mesa_init_gl_program(&prog->program.Base, target, id);
       } else {
          return NULL;
@@ -188,8 +165,6 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
    case GL_COMPUTE_PROGRAM_NV: {
       struct brw_compute_program *prog = CALLOC_STRUCT(brw_compute_program);
       if (prog) {
-         prog->id = get_new_program_id(brw->intelScreen);
-
          return _mesa_init_gl_program(&prog->program.Base, target, id);
       } else {
          return NULL;
@@ -225,7 +200,6 @@ brwProgramStringNotify(struct gl_context *ctx,
 
       if (newFP == curFP)
 	 brw->ctx.NewDriverState |= BRW_NEW_FRAGMENT_PROGRAM;
-      newFP->id = get_new_program_id(brw->intelScreen);
 
       brw_add_texrect_params(prog);
 
@@ -245,7 +219,6 @@ brwProgramStringNotify(struct gl_context *ctx,
       if (newVP->program.IsPositionInvariant) {
 	 _mesa_insert_mvp_code(ctx, &newVP->program);
       }
-      newVP->id = get_new_program_id(brw->intelScreen);
 
       /* Also tell tnl about it:
        */
diff --git a/src/mesa/drivers/dri/i965/brw_sf.c b/src/mesa/drivers/dri/i965/brw_sf.c
index c85d8bc..39eca0a 100644
--- a/src/mesa/drivers/dri/i965/brw_sf.c
+++ b/src/mesa/drivers/dri/i965/brw_sf.c
@@ -127,7 +127,7 @@ static void compile_sf_prog( struct brw_context *brw,
 		    &c.key, sizeof(c.key),
 		    program, program_size,
 		    &c.prog_data, sizeof(c.prog_data),
-		    &brw->sf.prog_offset, &brw->sf.prog_data);
+                    &brw->sf.prog_offset, &brw->sf.prog_data, NULL);
    ralloc_free(mem_ctx);
 }
 
diff --git a/src/mesa/drivers/dri/i965/brw_state.h b/src/mesa/drivers/dri/i965/brw_state.h
index 0a4c21f..3e828e7 100644
--- a/src/mesa/drivers/dri/i965/brw_state.h
+++ b/src/mesa/drivers/dri/i965/brw_state.h
@@ -226,13 +226,13 @@ brw_select_pipeline(struct brw_context *brw, enum brw_pipeline pipeline)
 
 void brw_upload_cache(struct brw_cache *cache,
 		      enum brw_cache_id cache_id,
-		      const void *key,
+                      void *key,
 		      GLuint key_sz,
 		      const void *data,
 		      GLuint data_sz,
 		      const void *aux,
 		      GLuint aux_sz,
-		      uint32_t *out_offset, void *out_aux);
+                      uint32_t *out_offset, void *out_aux, void *prog);
 
 bool brw_search_cache(struct brw_cache *cache,
 		      enum brw_cache_id cache_id,
diff --git a/src/mesa/drivers/dri/i965/brw_state_cache.c b/src/mesa/drivers/dri/i965/brw_state_cache.c
index 0e98e65..e6d05a0 100644
--- a/src/mesa/drivers/dri/i965/brw_state_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_state_cache.c
@@ -44,6 +44,7 @@
  * big we throw out all of the cache data and let it get regenerated.
  */
 
+#include <pthread.h>
 #include "main/imports.h"
 #include "intel_batchbuffer.h"
 #include "brw_state.h"
@@ -55,6 +56,16 @@
 
 #define FILE_DEBUG_FLAG DEBUG_STATE
 
+static unsigned
+get_new_program_id(struct intel_screen *screen)
+{
+   static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+   pthread_mutex_lock(&m);
+   unsigned id = screen->program_id++;
+   pthread_mutex_unlock(&m);
+   return id;
+}
+
 static GLuint
 hash_key(struct brw_cache_item *item)
 {
@@ -271,14 +282,15 @@ brw_alloc_item_data(struct brw_cache *cache, uint32_t size)
 void
 brw_upload_cache(struct brw_cache *cache,
 		 enum brw_cache_id cache_id,
-		 const void *key,
+                 void *key,
 		 GLuint key_size,
 		 const void *data,
 		 GLuint data_size,
 		 const void *aux,
 		 GLuint aux_size,
 		 uint32_t *out_offset,
-		 void *out_aux)
+                 void *out_aux,
+                 void *prog)
 {
    struct brw_context *brw = cache->brw;
    struct brw_cache_item *item = CALLOC_STRUCT(brw_cache_item);
@@ -287,6 +299,65 @@ brw_upload_cache(struct brw_cache *cache,
    GLuint hash;
    void *tmp;
 
+   switch (cache_id) {
+   case BRW_CACHE_VS_PROG: {
+      struct brw_vertex_program *p = (struct brw_vertex_program *) prog;
+      if (p->id == 0) {
+         struct brw_vs_prog_key *k = (struct brw_vs_prog_key *) key;
+         p->id = get_new_program_id(brw->intelScreen);
+         k->program_string_id = p->id;
+      }
+      break;
+   }
+   case BRW_CACHE_TCS_PROG: {
+      struct brw_tess_ctrl_program *p = (struct brw_tess_ctrl_program *) prog;
+      if (p && p->id == 0) {
+         struct brw_tcs_prog_key *k = (struct brw_tcs_prog_key *) key;
+         p->id = get_new_program_id(brw->intelScreen);
+         k->program_string_id = p->id;
+      }
+      break;
+   }
+   case BRW_CACHE_TES_PROG: {
+      struct brw_tess_eval_program *p = (struct brw_tess_eval_program *) prog;
+      if (p->id == 0) {
+         struct brw_tes_prog_key *k = (struct brw_tes_prog_key *) key;
+         p->id = get_new_program_id(brw->intelScreen);
+         k->program_string_id = p->id;
+      }
+      break;
+   }
+   case BRW_CACHE_GS_PROG: {
+      struct brw_geometry_program *p = (struct brw_geometry_program *) prog;
+      if (p->id == 0) {
+         struct brw_gs_prog_key *k = (struct brw_gs_prog_key *) key;
+         p->id = get_new_program_id(brw->intelScreen);
+         k->program_string_id = p->id;
+      }
+      break;
+   }
+   case BRW_CACHE_FS_PROG: {
+      struct brw_fragment_program *p = (struct brw_fragment_program *) prog;
+      if (p->id == 0) {
+         struct brw_wm_prog_key *k = (struct brw_wm_prog_key *) key;
+         p->id = get_new_program_id(brw->intelScreen);
+         k->program_string_id = p->id;
+      }
+      break;
+   }
+   case BRW_CACHE_CS_PROG: {
+      struct brw_compute_program *p = (struct brw_compute_program *) prog;
+      if (p->id == 0) {
+         struct brw_cs_prog_key *k = (struct brw_cs_prog_key *) key;
+         p->id = get_new_program_id(brw->intelScreen);
+         k->program_string_id = p->id;
+      }
+      break;
+   }
+   default:
+      ; /* Do nothing */
+   }
+
    item->cache_id = cache_id;
    item->size = data_size;
    item->key = key;
diff --git a/src/mesa/drivers/dri/i965/brw_tcs.c b/src/mesa/drivers/dri/i965/brw_tcs.c
index 5a514ef..8582045 100644
--- a/src/mesa/drivers/dri/i965/brw_tcs.c
+++ b/src/mesa/drivers/dri/i965/brw_tcs.c
@@ -299,7 +299,7 @@ brw_codegen_tcs_prog(struct brw_context *brw,
                     key, sizeof(*key),
                     program, program_size,
                     &prog_data, sizeof(prog_data),
-                    &stage_state->prog_offset, &brw->tcs.prog_data);
+                    &stage_state->prog_offset, &brw->tcs.prog_data, tcp);
    ralloc_free(mem_ctx);
    if (!tcs)
       ralloc_free(nir);
diff --git a/src/mesa/drivers/dri/i965/brw_tes.c b/src/mesa/drivers/dri/i965/brw_tes.c
index a4cd4da..5beb672 100644
--- a/src/mesa/drivers/dri/i965/brw_tes.c
+++ b/src/mesa/drivers/dri/i965/brw_tes.c
@@ -224,7 +224,7 @@ brw_codegen_tes_prog(struct brw_context *brw,
                     key, sizeof(*key),
                     program, program_size,
                     &prog_data, sizeof(prog_data),
-                    &stage_state->prog_offset, &brw->tes.prog_data);
+                    &stage_state->prog_offset, &brw->tes.prog_data, tep);
    ralloc_free(mem_ctx);
 
    return true;
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index abf03b1..fd1d8df 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -218,7 +218,8 @@ brw_codegen_vs_prog(struct brw_context *brw,
 		    key, sizeof(struct brw_vs_prog_key),
 		    program, program_size,
 		    &prog_data, sizeof(prog_data),
-		    &brw->vs.base.prog_offset, &brw->vs.prog_data);
+		    &brw->vs.base.prog_offset, &brw->vs.prog_data, vp);
+
    ralloc_free(mem_ctx);
 
    return true;
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index c9c5d5e..aa8ba0d 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -175,7 +175,7 @@ brw_codegen_wm_prog(struct brw_context *brw,
 		    key, sizeof(struct brw_wm_prog_key),
 		    program, program_size,
 		    &prog_data, sizeof(prog_data),
-		    &brw->wm.base.prog_offset, &brw->wm.prog_data);
+		    &brw->wm.base.prog_offset, &brw->wm.prog_data, fp);
 
    ralloc_free(mem_ctx);
 
-- 
2.5.5



More information about the mesa-dev mailing list