[Mesa-dev] [PATCH 2/3] st/mesa: decouple shaders from contexts if they are shareable

Rob Clark robdclark at gmail.com
Mon Oct 19 14:47:27 PDT 2015


On Sat, Oct 10, 2015 at 9:09 PM, Marek Olšák <maraeo at gmail.com> wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> ---
>  src/mesa/state_tracker/st_atom_shader.c   | 10 +++++-----
>  src/mesa/state_tracker/st_cb_bitmap.c     |  2 +-
>  src/mesa/state_tracker/st_cb_drawpixels.c |  2 +-
>  src/mesa/state_tracker/st_context.c       |  3 ++-
>  src/mesa/state_tracker/st_context.h       |  1 +
>  src/mesa/state_tracker/st_program.c       | 16 +++++++++++-----
>  6 files changed, 21 insertions(+), 13 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
> index 1e880a1..3941454 100644
> --- a/src/mesa/state_tracker/st_atom_shader.c
> +++ b/src/mesa/state_tracker/st_atom_shader.c
> @@ -64,7 +64,7 @@ update_fp( struct st_context *st )
>     assert(stfp->Base.Base.Target == GL_FRAGMENT_PROGRAM_ARB);
>
>     memset(&key, 0, sizeof(key));
> -   key.st = st;
> +   key.st = st->has_shareable_shaders ? NULL : st;
>
>     /* _NEW_FRAG_CLAMP */
>     key.clamp_color = st->clamp_frag_color_in_shader &&
> @@ -119,7 +119,7 @@ update_vp( struct st_context *st )
>     assert(stvp->Base.Base.Target == GL_VERTEX_PROGRAM_ARB);
>
>     memset(&key, 0, sizeof key);
> -   key.st = st;  /* variants are per-context */
> +   key.st = st->has_shareable_shaders ? NULL : st;
>
>     /* When this is true, we will add an extra input to the vertex
>      * shader translation (for edgeflags), an extra output with
> @@ -174,7 +174,7 @@ update_gp( struct st_context *st )
>     assert(stgp->Base.Base.Target == GL_GEOMETRY_PROGRAM_NV);
>
>     memset(&key, 0, sizeof(key));
> -   key.st = st;
> +   key.st = st->has_shareable_shaders ? NULL : st;
>
>     st->gp_variant = st_get_gp_variant(st, stgp, &key);
>
> @@ -210,7 +210,7 @@ update_tcp( struct st_context *st )
>     assert(sttcp->Base.Base.Target == GL_TESS_CONTROL_PROGRAM_NV);
>
>     memset(&key, 0, sizeof(key));
> -   key.st = st;
> +   key.st = st->has_shareable_shaders ? NULL : st;
>
>     st->tcp_variant = st_get_tcp_variant(st, sttcp, &key);
>
> @@ -246,7 +246,7 @@ update_tep( struct st_context *st )
>     assert(sttep->Base.Base.Target == GL_TESS_EVALUATION_PROGRAM_NV);
>
>     memset(&key, 0, sizeof(key));
> -   key.st = st;
> +   key.st = st->has_shareable_shaders ? NULL : st;
>
>     st->tep_variant = st_get_tep_variant(st, sttep, &key);
>
> diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
> index bb6dfe8..cbc6845 100644
> --- a/src/mesa/state_tracker/st_cb_bitmap.c
> +++ b/src/mesa/state_tracker/st_cb_bitmap.c
> @@ -269,7 +269,7 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
>     struct pipe_resource *vbuf = NULL;
>
>     memset(&key, 0, sizeof(key));
> -   key.st = st;
> +   key.st = st->has_shareable_shaders ? NULL : st;
>     key.bitmap = GL_TRUE;
>     key.clamp_color = st->clamp_frag_color_in_shader &&
>                       st->ctx->Color._ClampFragmentColor;
> diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
> index 7e8633e..20cbfde 100644
> --- a/src/mesa/state_tracker/st_cb_drawpixels.c
> +++ b/src/mesa/state_tracker/st_cb_drawpixels.c
> @@ -914,7 +914,7 @@ get_color_fp_variant(struct st_context *st)
>
>     memset(&key, 0, sizeof(key));
>
> -   key.st = st;
> +   key.st = st->has_shareable_shaders ? NULL : st;
>     key.drawpixels = 1;
>     key.scaleAndBias = (ctx->Pixel.RedBias != 0.0 ||
>                         ctx->Pixel.RedScale != 1.0 ||
> diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
> index bef7307..6256c0b 100644
> --- a/src/mesa/state_tracker/st_context.c
> +++ b/src/mesa/state_tracker/st_context.c
> @@ -237,7 +237,8 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
>                                PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER);
>     st->can_force_persample_interp = screen->get_param(screen,
>                                            PIPE_CAP_FORCE_PERSAMPLE_INTERP);
> -
> +   st->has_shareable_shaders = screen->get_param(screen,
> +                                                 PIPE_CAP_SHAREABLE_SHADERS);
>     st->needs_texcoord_semantic =
>        screen->get_param(screen, PIPE_CAP_TGSI_TEXCOORD);
>     st->apply_texture_swizzle_to_border_color =
> diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
> index f187d82..446fe5d 100644
> --- a/src/mesa/state_tracker/st_context.h
> +++ b/src/mesa/state_tracker/st_context.h
> @@ -99,6 +99,7 @@ struct st_context
>     boolean has_etc2;
>     boolean prefer_blit_based_texture_transfer;
>     boolean can_force_persample_interp;
> +   boolean has_shareable_shaders;
>
>     boolean needs_texcoord_semantic;
>     boolean apply_texture_swizzle_to_border_color;
> diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
> index 6a69ba7..87571a8 100644
> --- a/src/mesa/state_tracker/st_program.c
> +++ b/src/mesa/state_tracker/st_program.c
> @@ -1728,6 +1728,12 @@ destroy_program_variants_cb(GLuint key, void *data, void *userData)
>  void
>  st_destroy_program_variants(struct st_context *st)
>  {
> +   /* If shaders can be shared with other contexts, the last context will
> +    * call DeleteProgram on all shaders, releasing everything.
> +    */
> +   if (st->has_shareable_shaders)
> +      return;

I guess this could result in shaders not being released in some cases
where they otherwise would, for app's w/ multiple contexts.  Not sure
how likely that is in practice..  Or how much harder it would be to
just refcnt shader association w/ st's?

BR,
-R

> +
>     /* ARB vert/frag program */
>     _mesa_HashWalk(st->ctx->Shared->Programs,
>                    destroy_program_variants_cb, st);
> @@ -1774,7 +1780,7 @@ st_precompile_shader_variant(struct st_context *st,
>        struct st_vp_variant_key key;
>
>        memset(&key, 0, sizeof(key));
> -      key.st = st;
> +      key.st = st->has_shareable_shaders ? NULL : st;
>        st_get_vp_variant(st, p, &key);
>        break;
>     }
> @@ -1784,7 +1790,7 @@ st_precompile_shader_variant(struct st_context *st,
>        struct st_tcp_variant_key key;
>
>        memset(&key, 0, sizeof(key));
> -      key.st = st;
> +      key.st = st->has_shareable_shaders ? NULL : st;
>        st_get_tcp_variant(st, p, &key);
>        break;
>     }
> @@ -1794,7 +1800,7 @@ st_precompile_shader_variant(struct st_context *st,
>        struct st_tep_variant_key key;
>
>        memset(&key, 0, sizeof(key));
> -      key.st = st;
> +      key.st = st->has_shareable_shaders ? NULL : st;
>        st_get_tep_variant(st, p, &key);
>        break;
>     }
> @@ -1804,7 +1810,7 @@ st_precompile_shader_variant(struct st_context *st,
>        struct st_gp_variant_key key;
>
>        memset(&key, 0, sizeof(key));
> -      key.st = st;
> +      key.st = st->has_shareable_shaders ? NULL : st;
>        st_get_gp_variant(st, p, &key);
>        break;
>     }
> @@ -1814,7 +1820,7 @@ st_precompile_shader_variant(struct st_context *st,
>        struct st_fp_variant_key key;
>
>        memset(&key, 0, sizeof(key));
> -      key.st = st;
> +      key.st = st->has_shareable_shaders ? NULL : st;
>        st_get_fp_variant(st, p, &key);
>        break;
>     }
> --
> 2.1.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list