[Mesa-dev] [PATCH 01/65] i965: move program id generation
Timothy Arceri
timothy.arceri at collabora.com
Fri Apr 29 13:33:00 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 | 2 +-
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 | 4 +-
src/mesa/drivers/dri/i965/brw_tes.c | 2 +-
src/mesa/drivers/dri/i965/brw_vec4_tcs.cpp | 2 +-
src/mesa/drivers/dri/i965/brw_vs.c | 3 +-
src/mesa/drivers/dri/i965/brw_wm.c | 2 +-
15 files changed, 91 insertions(+), 46 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp b/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp
index ab2ceec..672bb0c 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp
+++ b/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp
@@ -2198,7 +2198,7 @@ brw_blorp_blit_miptrees(struct brw_context *brw,
&wm_prog_key, sizeof(wm_prog_key),
program, program_size,
&prog.prog_data, sizeof(prog.prog_data),
- ¶ms.wm_prog_kernel, ¶ms.wm_prog_data);
+ ¶ms.wm_prog_kernel, ¶ms.wm_prog_data, NULL);
}
params.src.swizzle = src_swizzle;
diff --git a/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp b/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp
index ed537ba..c271d75 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp
+++ b/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp
@@ -111,7 +111,7 @@ brw_blorp_params_get_clear_kernel(struct brw_context *brw,
wm_prog_key, sizeof(*wm_prog_key),
program, program_size,
&prog.prog_data, sizeof(prog.prog_data),
- ¶ms->wm_prog_kernel, ¶ms->wm_prog_data);
+ ¶ms->wm_prog_kernel, ¶ms->wm_prog_data, NULL);
}
}
diff --git a/src/mesa/drivers/dri/i965/brw_clip.c b/src/mesa/drivers/dri/i965/brw_clip.c
index 9baaddd..ba10fcc 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 0ab9ebd..c91ff04 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 c329ece..8bb569c 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 c888ef2..962220a 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_gs.c
@@ -188,7 +188,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 3112c0c..f368ce8 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"
@@ -45,29 +44,15 @@
#include "brw_nir.h"
#include "intel_batchbuffer.h"
-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;
@@ -76,9 +61,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;
@@ -87,8 +70,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;
@@ -98,8 +79,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;
@@ -109,8 +88,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;
@@ -120,8 +97,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;
@@ -157,7 +132,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);
@@ -177,7 +151,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 c03af82..1fd4317 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 e89b388..071d3ca 100644
--- a/src/mesa/drivers/dri/i965/brw_state.h
+++ b/src/mesa/drivers/dri/i965/brw_state.h
@@ -231,13 +231,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 c6aa134..3779195 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)
{
@@ -270,14 +281,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);
@@ -286,6 +298,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 7e41426..4687eaa 100644
--- a/src/mesa/drivers/dri/i965/brw_tcs.c
+++ b/src/mesa/drivers/dri/i965/brw_tcs.c
@@ -108,7 +108,7 @@ brw_codegen_tcs_prog(struct brw_context *brw,
nir->info.outputs_written = key->outputs_written;
nir->info.inputs_read = key->outputs_written;
nir->info.tcs.vertices_out = key->input_vertices;
- nir->info.name = ralloc_strdup(nir, "passthrough");
+ nir->info.name = ralloc_strdup(nir, "tcs_passthrough");
}
memset(&prog_data, 0, sizeof(prog_data));
@@ -218,7 +218,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 27dc7e5..0cbbbad 100644
--- a/src/mesa/drivers/dri/i965/brw_tes.c
+++ b/src/mesa/drivers/dri/i965/brw_tes.c
@@ -222,7 +222,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_vec4_tcs.cpp b/src/mesa/drivers/dri/i965/brw_vec4_tcs.cpp
index 8043948..cbc0868 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_tcs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_tcs.cpp
@@ -50,7 +50,7 @@ vec4_tcs_visitor::vec4_tcs_visitor(const struct brw_compiler *compiler,
void
vec4_tcs_visitor::emit_nir_code()
{
- if (key->program_string_id != 0) {
+ if (strcmp(nir->info.name, "tcs_passthrough") != 0) {
/* We have a real application-supplied TCS, emit real code. */
vec4_visitor::emit_nir_code();
} else {
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index 3095d82..8cebdec 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -216,7 +216,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 dbc626c..4c77a20 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -173,7 +173,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