[Mesa-dev] [PATCH 4/7] mesa/st: a bit of basic_variant refactoring
Marek Olšák
maraeo at gmail.com
Mon Sep 12 13:11:43 UTC 2016
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Marek
On Thu, Sep 8, 2016 at 10:30 PM, Rob Clark <robdclark at gmail.com> wrote:
> Add a helper to initialize the key, and pass the key into the helper
> that iterates the variants, similar to how it works for vp/fp variants.
>
> The 'prog' arg to the helper gets used in a following patch, and is the
> reason to pass the key into st_get_basic_variant().
>
> Signed-off-by: Rob Clark <robdclark at gmail.com>
> ---
> src/mesa/state_tracker/st_atom_shader.c | 16 ++++++++++++----
> src/mesa/state_tracker/st_program.c | 34 ++++++++++++++++-----------------
> src/mesa/state_tracker/st_program.h | 16 ++++++++++++++--
> 3 files changed, 42 insertions(+), 24 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
> index 2f700a2..c2e4fc8 100644
> --- a/src/mesa/state_tracker/st_atom_shader.c
> +++ b/src/mesa/state_tracker/st_atom_shader.c
> @@ -217,6 +217,7 @@ 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);
> @@ -227,8 +228,9 @@ update_gp( struct st_context *st )
> stgp = st_geometry_program(st->ctx->GeometryProgram._Current);
> assert(stgp->Base.Base.Target == GL_GEOMETRY_PROGRAM_NV);
>
> + key = st_get_basic_variant_key(st, &stgp->Base.Base);
> st->gp_variant = st_get_basic_variant(st, PIPE_SHADER_GEOMETRY,
> - &stgp->tgsi, &stgp->variants);
> + &stgp->tgsi, &stgp->variants, &key);
>
> st_reference_geomprog(st, &st->gp, stgp);
>
> @@ -246,6 +248,7 @@ 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);
> @@ -256,8 +259,9 @@ update_tcp( struct st_context *st )
> sttcp = st_tessctrl_program(st->ctx->TessCtrlProgram._Current);
> assert(sttcp->Base.Base.Target == GL_TESS_CONTROL_PROGRAM_NV);
>
> + key = st_get_basic_variant_key(st, &sttcp->Base.Base);
> st->tcp_variant = st_get_basic_variant(st, PIPE_SHADER_TESS_CTRL,
> - &sttcp->tgsi, &sttcp->variants);
> + &sttcp->tgsi, &sttcp->variants, &key);
>
> st_reference_tesscprog(st, &st->tcp, sttcp);
>
> @@ -275,6 +279,7 @@ 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);
> @@ -285,8 +290,9 @@ update_tep( struct st_context *st )
> sttep = st_tesseval_program(st->ctx->TessEvalProgram._Current);
> assert(sttep->Base.Base.Target == GL_TESS_EVALUATION_PROGRAM_NV);
>
> + key = st_get_basic_variant_key(st, &sttep->Base.Base);
> st->tep_variant = st_get_basic_variant(st, PIPE_SHADER_TESS_EVAL,
> - &sttep->tgsi, &sttep->variants);
> + &sttep->tgsi, &sttep->variants, &key);
>
> st_reference_tesseprog(st, &st->tep, sttep);
>
> @@ -304,6 +310,7 @@ static void
> update_cp( struct st_context *st )
> {
> struct st_compute_program *stcp;
> + struct st_basic_variant_key key;
>
> if (!st->ctx->ComputeProgram._Current) {
> cso_set_compute_shader_handle(st->cso_context, NULL);
> @@ -314,7 +321,8 @@ update_cp( struct st_context *st )
> stcp = st_compute_program(st->ctx->ComputeProgram._Current);
> assert(stcp->Base.Base.Target == GL_COMPUTE_PROGRAM_NV);
>
> - st->cp_variant = st_get_cp_variant(st, &stcp->tgsi, &stcp->variants);
> + key = st_get_basic_variant_key(st, &stcp->Base.Base);
> + st->cp_variant = st_get_cp_variant(st, &stcp->tgsi, &stcp->variants, &key);
>
> st_reference_compprog(st, &st->cp, stcp);
>
> diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
> index 91887dc..284cc22 100644
> --- a/src/mesa/state_tracker/st_program.c
> +++ b/src/mesa/state_tracker/st_program.c
> @@ -1533,18 +1533,15 @@ struct st_basic_variant *
> st_get_basic_variant(struct st_context *st,
> unsigned pipe_shader,
> struct pipe_shader_state *tgsi,
> - struct st_basic_variant **variants)
> + struct st_basic_variant **variants,
> + const struct st_basic_variant_key *key)
> {
> 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 (v = *variants; v; v = v->next) {
> - if (memcmp(&v->key, &key, sizeof(key)) == 0) {
> + if (memcmp(&v->key, key, sizeof(*key)) == 0) {
> break;
> }
> }
> @@ -1570,7 +1567,7 @@ st_get_basic_variant(struct st_context *st,
> return NULL;
> }
>
> - v->key = key;
> + v->key = *key;
>
> /* insert into list */
> v->next = *variants;
> @@ -1689,18 +1686,15 @@ st_translate_compute_program(struct st_context *st,
> struct st_basic_variant *
> st_get_cp_variant(struct st_context *st,
> struct pipe_compute_state *tgsi,
> - struct st_basic_variant **variants)
> + struct st_basic_variant **variants,
> + const struct st_basic_variant_key *key)
> {
> 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 (v = *variants; v; v = v->next) {
> - if (memcmp(&v->key, &key, sizeof(key)) == 0) {
> + if (memcmp(&v->key, key, sizeof(*key)) == 0) {
> break;
> }
> }
> @@ -1711,7 +1705,7 @@ st_get_cp_variant(struct st_context *st,
> if (v) {
> /* fill in new variant */
> v->driver_shader = pipe->create_compute_state(pipe, tgsi);
> - v->key = key;
> + v->key = *key;
>
> /* insert into list */
> v->next = *variants;
> @@ -1929,19 +1923,22 @@ st_precompile_shader_variant(struct st_context *st,
>
> case GL_TESS_CONTROL_PROGRAM_NV: {
> struct st_tessctrl_program *p = (struct st_tessctrl_program *)prog;
> - st_get_basic_variant(st, PIPE_SHADER_TESS_CTRL, &p->tgsi, &p->variants);
> + struct st_basic_variant_key key = st_get_basic_variant_key(st, prog);
> + st_get_basic_variant(st, PIPE_SHADER_TESS_CTRL, &p->tgsi, &p->variants, &key);
> break;
> }
>
> case GL_TESS_EVALUATION_PROGRAM_NV: {
> struct st_tesseval_program *p = (struct st_tesseval_program *)prog;
> - st_get_basic_variant(st, PIPE_SHADER_TESS_EVAL, &p->tgsi, &p->variants);
> + struct st_basic_variant_key key = st_get_basic_variant_key(st, prog);
> + st_get_basic_variant(st, PIPE_SHADER_TESS_EVAL, &p->tgsi, &p->variants, &key);
> break;
> }
>
> case GL_GEOMETRY_PROGRAM_NV: {
> struct st_geometry_program *p = (struct st_geometry_program *)prog;
> - st_get_basic_variant(st, PIPE_SHADER_GEOMETRY, &p->tgsi, &p->variants);
> + struct st_basic_variant_key key = st_get_basic_variant_key(st, prog);
> + st_get_basic_variant(st, PIPE_SHADER_GEOMETRY, &p->tgsi, &p->variants, &key);
> break;
> }
>
> @@ -1957,7 +1954,8 @@ st_precompile_shader_variant(struct st_context *st,
>
> case GL_COMPUTE_PROGRAM_NV: {
> struct st_compute_program *p = (struct st_compute_program *)prog;
> - st_get_cp_variant(st, &p->tgsi, &p->variants);
> + struct st_basic_variant_key key = st_get_basic_variant_key(st, prog);
> + st_get_cp_variant(st, &p->tgsi, &p->variants, &key);
> break;
> }
>
> diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
> index ea55d47..f4e572a 100644
> --- a/src/mesa/state_tracker/st_program.h
> +++ b/src/mesa/state_tracker/st_program.h
> @@ -230,6 +230,16 @@ struct st_basic_variant_key
> struct st_context *st; /**< variants are per-context */
> };
>
> +static inline struct st_basic_variant_key
> +st_get_basic_variant_key(struct st_context *st, struct gl_program *prog)
> +{
> + struct st_basic_variant_key key;
> +
> + memset(&key, 0, sizeof(key));
> + key.st = st->has_shareable_shaders ? NULL : st;
> +
> + return key;
> +}
>
> /**
> * Geometry program variant.
> @@ -438,13 +448,15 @@ st_get_fp_variant(struct st_context *st,
> extern struct st_basic_variant *
> st_get_cp_variant(struct st_context *st,
> struct pipe_compute_state *tgsi,
> - struct st_basic_variant **variants);
> + struct st_basic_variant **variants,
> + const struct st_basic_variant_key *key);
>
> extern struct st_basic_variant *
> st_get_basic_variant(struct st_context *st,
> unsigned pipe_shader,
> struct pipe_shader_state *tgsi,
> - struct st_basic_variant **variants);
> + struct st_basic_variant **variants,
> + const struct st_basic_variant_key *key);
>
> extern void
> st_release_vp_variants( struct st_context *st,
> --
> 2.7.4
>
More information about the mesa-dev
mailing list