From 75be3ee9f9f7078a415498547637365035650cf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 30 Jan 2016 16:24:29 +0100 Subject: [PATCH] st/mesa: unify get_variant functions for TCS, TES, GS Reviewed-by: Edward O'Callaghan --- src/mesa/state_tracker/st_atom_shader.c | 18 +-- src/mesa/state_tracker/st_program.c | 172 ++++-------------------- src/mesa/state_tracker/st_program.h | 17 +-- 3 files changed, 31 insertions(+), 176 deletions(-) diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 2d8a3c3fb57..23b7abfc1c5 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -163,7 +163,6 @@ static void update_gp( struct st_context *st ) { struct st_geometry_program *stgp; - struct st_basic_variant_key key; if (!st->ctx->GeometryProgram._Current) { cso_set_geometry_shader_handle(st->cso_context, NULL); @@ -173,10 +172,7 @@ update_gp( struct st_context *st ) stgp = st_geometry_program(st->ctx->GeometryProgram._Current); assert(stgp->Base.Base.Target == GL_GEOMETRY_PROGRAM_NV); - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - - st->gp_variant = st_get_gp_variant(st, stgp, &key); + st->gp_variant = st_get_basic_variant(st, &stgp->tgsi, &stgp->variants); st_reference_geomprog(st, &st->gp, stgp); @@ -199,7 +195,6 @@ static void update_tcp( struct st_context *st ) { struct st_tessctrl_program *sttcp; - struct st_basic_variant_key key; if (!st->ctx->TessCtrlProgram._Current) { cso_set_tessctrl_shader_handle(st->cso_context, NULL); @@ -209,10 +204,7 @@ update_tcp( struct st_context *st ) sttcp = st_tessctrl_program(st->ctx->TessCtrlProgram._Current); assert(sttcp->Base.Base.Target == GL_TESS_CONTROL_PROGRAM_NV); - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - - st->tcp_variant = st_get_tcp_variant(st, sttcp, &key); + st->tcp_variant = st_get_basic_variant(st, &sttcp->tgsi, &sttcp->variants); st_reference_tesscprog(st, &st->tcp, sttcp); @@ -235,7 +227,6 @@ static void update_tep( struct st_context *st ) { struct st_tesseval_program *sttep; - struct st_basic_variant_key key; if (!st->ctx->TessEvalProgram._Current) { cso_set_tesseval_shader_handle(st->cso_context, NULL); @@ -245,10 +236,7 @@ update_tep( struct st_context *st ) sttep = st_tesseval_program(st->ctx->TessEvalProgram._Current); assert(sttep->Base.Base.Target == GL_TESS_EVALUATION_PROGRAM_NV); - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - - st->tep_variant = st_get_tep_variant(st, sttep, &key); + st->tep_variant = st_get_basic_variant(st, &sttep->tgsi, &sttep->variants); st_reference_tesseprog(st, &st->tep, sttep); diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 133869bc8c4..d8b7f376a02 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -1266,53 +1266,43 @@ st_translate_geometry_program(struct st_context *st, } -static struct st_basic_variant * -st_create_gp_variant(struct st_context *st, - struct st_geometry_program *stgp, - const struct st_basic_variant_key *key) -{ - struct pipe_context *pipe = st->pipe; - struct st_basic_variant *gpv; - - gpv = CALLOC_STRUCT(st_basic_variant); - if (!gpv) - return NULL; - - /* fill in new variant */ - gpv->driver_shader = pipe->create_gs_state(pipe, &stgp->tgsi); - gpv->key = *key; - return gpv; -} - - /** - * Get/create geometry program variant. + * Get/create a basic program variant. */ struct st_basic_variant * -st_get_gp_variant(struct st_context *st, - struct st_geometry_program *stgp, - const struct st_basic_variant_key *key) +st_get_basic_variant(struct st_context *st, + struct pipe_shader_state *tgsi, + struct st_basic_variant **variants) { - struct st_basic_variant *gpv; + struct pipe_context *pipe = st->pipe; + struct st_basic_variant *v; + struct st_basic_variant_key key; + + memset(&key, 0, sizeof(key)); + key.st = st->has_shareable_shaders ? NULL : st; /* Search for existing variant */ - for (gpv = stgp->variants; gpv; gpv = gpv->next) { - if (memcmp(&gpv->key, key, sizeof(*key)) == 0) { + for (v = *variants; v; v = v->next) { + if (memcmp(&v->key, &key, sizeof(key)) == 0) { break; } } - if (!gpv) { + if (!v) { /* create new */ - gpv = st_create_gp_variant(st, stgp, key); - if (gpv) { + v = CALLOC_STRUCT(st_basic_variant); + if (v) { + /* fill in new variant */ + v->driver_shader = pipe->create_gs_state(pipe, tgsi); + v->key = key; + /* insert into list */ - gpv->next = stgp->variants; - stgp->variants = gpv; + v->next = *variants; + *variants = v; } } - return gpv; + return v; } @@ -1341,56 +1331,6 @@ st_translate_tessctrl_program(struct st_context *st, } -static struct st_basic_variant * -st_create_tcp_variant(struct st_context *st, - struct st_tessctrl_program *sttcp, - const struct st_basic_variant_key *key) -{ - struct pipe_context *pipe = st->pipe; - struct st_basic_variant *tcpv; - - tcpv = CALLOC_STRUCT(st_basic_variant); - if (!tcpv) - return NULL; - - /* fill in new variant */ - tcpv->driver_shader = pipe->create_tcs_state(pipe, &sttcp->tgsi); - tcpv->key = *key; - return tcpv; -} - - -/** - * Get/create tessellation control program variant. - */ -struct st_basic_variant * -st_get_tcp_variant(struct st_context *st, - struct st_tessctrl_program *sttcp, - const struct st_basic_variant_key *key) -{ - struct st_basic_variant *tcpv; - - /* Search for existing variant */ - for (tcpv = sttcp->variants; tcpv; tcpv = tcpv->next) { - if (memcmp(&tcpv->key, key, sizeof(*key)) == 0) { - break; - } - } - - if (!tcpv) { - /* create new */ - tcpv = st_create_tcp_variant(st, sttcp, key); - if (tcpv) { - /* insert into list */ - tcpv->next = sttcp->variants; - sttcp->variants = tcpv; - } - } - - return tcpv; -} - - /** * Translate a tessellation evaluation program to create a new variant. */ @@ -1438,56 +1378,6 @@ st_translate_tesseval_program(struct st_context *st, } -static struct st_basic_variant * -st_create_tep_variant(struct st_context *st, - struct st_tesseval_program *sttep, - const struct st_basic_variant_key *key) -{ - struct pipe_context *pipe = st->pipe; - struct st_basic_variant *tepv; - - tepv = CALLOC_STRUCT(st_basic_variant); - if (!tepv) - return NULL; - - /* fill in new variant */ - tepv->driver_shader = pipe->create_tes_state(pipe, &sttep->tgsi); - tepv->key = *key; - return tepv; -} - - -/** - * Get/create tessellation evaluation program variant. - */ -struct st_basic_variant * -st_get_tep_variant(struct st_context *st, - struct st_tesseval_program *sttep, - const struct st_basic_variant_key *key) -{ - struct st_basic_variant *tepv; - - /* Search for existing variant */ - for (tepv = sttep->variants; tepv; tepv = tepv->next) { - if (memcmp(&tepv->key, key, sizeof(*key)) == 0) { - break; - } - } - - if (!tepv) { - /* create new */ - tepv = st_create_tep_variant(st, sttep, key); - if (tepv) { - /* insert into list */ - tepv->next = sttep->variants; - sttep->variants = tepv; - } - } - - return tepv; -} - - /** * Vert/Geom/Frag programs have per-context variants. Free all the * variants attached to the given program which match the given context. @@ -1731,31 +1621,19 @@ st_precompile_shader_variant(struct st_context *st, case GL_TESS_CONTROL_PROGRAM_NV: { struct st_tessctrl_program *p = (struct st_tessctrl_program *)prog; - struct st_basic_variant_key key; - - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - st_get_tcp_variant(st, p, &key); + st_get_basic_variant(st, &p->tgsi, &p->variants); break; } case GL_TESS_EVALUATION_PROGRAM_NV: { struct st_tesseval_program *p = (struct st_tesseval_program *)prog; - struct st_basic_variant_key key; - - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - st_get_tep_variant(st, p, &key); + st_get_basic_variant(st, &p->tgsi, &p->variants); break; } case GL_GEOMETRY_PROGRAM_NV: { struct st_geometry_program *p = (struct st_geometry_program *)prog; - struct st_basic_variant_key key; - - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - st_get_gp_variant(st, p, &key); + st_get_basic_variant(st, &p->tgsi, &p->variants); break; } diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 80d6f81d267..7717d02cd3f 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -350,21 +350,10 @@ st_get_fp_variant(struct st_context *st, struct st_fragment_program *stfp, const struct st_fp_variant_key *key); - -extern struct st_basic_variant * -st_get_gp_variant(struct st_context *st, - struct st_geometry_program *stgp, - const struct st_basic_variant_key *key); - -extern struct st_basic_variant * -st_get_tcp_variant(struct st_context *st, - struct st_tessctrl_program *sttcp, - const struct st_basic_variant_key *key); - extern struct st_basic_variant * -st_get_tep_variant(struct st_context *st, - struct st_tesseval_program *sttep, - const struct st_basic_variant_key *key); +st_get_basic_variant(struct st_context *st, + struct pipe_shader_state *tgsi, + struct st_basic_variant **variants); extern void st_release_vp_variants( struct st_context *st, -- 2.30.2