[Mesa-dev] [PATCH 2/4] st/mesa: unify get_variant functions for TCS, TES, GS
Michael Schellenberger Costa
mschellenbergercosta at googlemail.com
Sat Jan 30 23:12:42 PST 2016
Hi
Am 30/01/2016 um 16:50 schrieb Marek Olšák:
> From: Marek Olšák <marek.olsak at amd.com>
>
> ---
> src/mesa/state_tracker/st_atom_shader.c | 18 +---
> src/mesa/state_tracker/st_program.c | 164 +++++---------------------------
> src/mesa/state_tracker/st_program.h | 17 +---
> 3 files changed, 28 insertions(+), 171 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
> index 2d8a3c3..23b7abf 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 133869b..2dfb41e 100644
> --- a/src/mesa/state_tracker/st_program.c
> +++ b/src/mesa/state_tracker/st_program.c
> @@ -1266,49 +1266,41 @@ 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.
> */
You might want to update that comment.
Michael
> 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 pipe_context *pipe = st->pipe;
> struct st_basic_variant *gpv;
> + 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 (gpv = *variants; gpv; gpv = gpv->next) {
> + if (memcmp(&gpv->key, &key, sizeof(key)) == 0) {
> break;
> }
> }
>
> if (!gpv) {
> /* create new */
> - gpv = st_create_gp_variant(st, stgp, key);
> + struct st_basic_variant *gpv;
> +
> + gpv = CALLOC_STRUCT(st_basic_variant);
> if (gpv) {
> + /* fill in new variant */
> + gpv->driver_shader = pipe->create_gs_state(pipe, tgsi);
> + gpv->key = key;
> +
> /* insert into list */
> - gpv->next = stgp->variants;
> - stgp->variants = gpv;
> + gpv->next = *variants;
> + *variants = gpv;
> }
> }
>
> @@ -1341,56 +1333,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 +1380,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 +1623,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 80d6f81..7717d02 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,
>
More information about the mesa-dev
mailing list