[Mesa-dev] [PATCH 08/17] st/mesa: simplify code due to unification to st_common_program
Brian Paul
brianp at vmware.com
Mon May 1 16:41:05 UTC 2017
On 05/01/2017 06:52 AM, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> ---
> src/mesa/state_tracker/st_cb_program.c | 51 ++++++------------------------
> src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 16 +++-------
> src/mesa/state_tracker/st_program.c | 9 ++----
> src/mesa/state_tracker/st_shader_cache.c | 22 +++----------
> 4 files changed, 20 insertions(+), 78 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
> index 531d20d..82e5ff1 100644
> --- a/src/mesa/state_tracker/st_cb_program.c
> +++ b/src/mesa/state_tracker/st_cb_program.c
> @@ -61,33 +61,25 @@ st_new_program(struct gl_context *ctx, GLenum target, GLuint id,
> case GL_VERTEX_PROGRAM_ARB: {
> struct st_vertex_program *prog = rzalloc(NULL,
> struct st_vertex_program);
> return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
> }
> case GL_FRAGMENT_PROGRAM_ARB: {
> struct st_fragment_program *prog = rzalloc(NULL,
> struct st_fragment_program);
> return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
> }
> + case GL_TESS_CONTROL_PROGRAM_NV:
> + case GL_TESS_EVALUATION_PROGRAM_NV:
> case GL_GEOMETRY_PROGRAM_NV: {
> struct st_common_program *prog = rzalloc(NULL,
> - struct st_common_program);
> - return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
> - }
> - case GL_TESS_CONTROL_PROGRAM_NV: {
> - struct st_common_program *prog = rzalloc(NULL,
> - struct st_common_program);
> - return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
> - }
> - case GL_TESS_EVALUATION_PROGRAM_NV: {
> - struct st_common_program *prog = rzalloc(NULL,
> - struct st_common_program);
> + struct st_common_program);
> return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
> }
> case GL_COMPUTE_PROGRAM_NV: {
> struct st_compute_program *prog = rzalloc(NULL,
> struct st_compute_program);
> return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
> }
> default:
> assert(0);
> return NULL;
> @@ -106,67 +98,44 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog)
> switch( prog->Target ) {
> case GL_VERTEX_PROGRAM_ARB:
> {
> struct st_vertex_program *stvp = (struct st_vertex_program *) prog;
> st_release_vp_variants( st, stvp );
>
> if (stvp->glsl_to_tgsi)
> free_glsl_to_tgsi_visitor(stvp->glsl_to_tgsi);
> }
> break;
> + case GL_TESS_CONTROL_PROGRAM_NV:
> + case GL_TESS_EVALUATION_PROGRAM_NV:
> case GL_GEOMETRY_PROGRAM_NV:
> {
> - struct st_common_program *stgp =
> - (struct st_common_program *) prog;
> + struct st_common_program *p = (struct st_common_program *)prog;
>
> - st_release_basic_variants(st, stgp->Base.Target, &stgp->variants,
> - &stgp->tgsi);
> + st_release_basic_variants(st, p->Base.Target, &p->variants,
> + &p->tgsi);
>
> - if (stgp->glsl_to_tgsi)
> - free_glsl_to_tgsi_visitor(stgp->glsl_to_tgsi);
> + if (p->glsl_to_tgsi)
> + free_glsl_to_tgsi_visitor(p->glsl_to_tgsi);
> }
> break;
> case GL_FRAGMENT_PROGRAM_ARB:
> {
> struct st_fragment_program *stfp =
> (struct st_fragment_program *) prog;
>
> st_release_fp_variants(st, stfp);
>
> if (stfp->glsl_to_tgsi)
> free_glsl_to_tgsi_visitor(stfp->glsl_to_tgsi);
> }
> break;
> - case GL_TESS_CONTROL_PROGRAM_NV:
> - {
> - struct st_common_program *sttcp =
> - (struct st_common_program *) prog;
> -
> - st_release_basic_variants(st, sttcp->Base.Target, &sttcp->variants,
> - &sttcp->tgsi);
> -
> - if (sttcp->glsl_to_tgsi)
> - free_glsl_to_tgsi_visitor(sttcp->glsl_to_tgsi);
> - }
> - break;
> - case GL_TESS_EVALUATION_PROGRAM_NV:
> - {
> - struct st_common_program *sttep =
> - (struct st_common_program *) prog;
> -
> - st_release_basic_variants(st, sttep->Base.Target,
> - &sttep->variants, &sttep->tgsi);
> -
> - if (sttep->glsl_to_tgsi)
> - free_glsl_to_tgsi_visitor(sttep->glsl_to_tgsi);
> - }
> - break;
> case GL_COMPUTE_PROGRAM_NV:
> {
> struct st_compute_program *stcp =
> (struct st_compute_program *) prog;
>
> st_release_cp_variants(st, stcp);
>
> if (stcp->glsl_to_tgsi)
> free_glsl_to_tgsi_visitor(stcp->glsl_to_tgsi);
> }
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index de1d6f9..0b25f0e 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -6789,45 +6789,37 @@ get_mesa_program_tgsi(struct gl_context *ctx,
> _mesa_associate_uniform_storage(ctx, shader_program, prog->Parameters,
> true);
> if (!shader_program->data->LinkStatus) {
> free_glsl_to_tgsi_visitor(v);
> _mesa_reference_program(ctx, &shader->Program, NULL);
> return NULL;
> }
>
> struct st_vertex_program *stvp;
> struct st_fragment_program *stfp;
> - struct st_common_program *stgp;
> - struct st_common_program *sttcp;
> - struct st_common_program *sttep;
> + struct st_common_program *stp;
> struct st_compute_program *stcp;
>
> switch (shader->Stage) {
> case MESA_SHADER_VERTEX:
> stvp = (struct st_vertex_program *)prog;
> stvp->glsl_to_tgsi = v;
> break;
> case MESA_SHADER_FRAGMENT:
> stfp = (struct st_fragment_program *)prog;
> stfp->glsl_to_tgsi = v;
> break;
> - case MESA_SHADER_GEOMETRY:
> - stgp = (struct st_common_program *)prog;
> - stgp->glsl_to_tgsi = v;
> - break;
> case MESA_SHADER_TESS_CTRL:
> - sttcp = (struct st_common_program *)prog;
> - sttcp->glsl_to_tgsi = v;
> - break;
> case MESA_SHADER_TESS_EVAL:
> - sttep = (struct st_common_program *)prog;
> - sttep->glsl_to_tgsi = v;
> + case MESA_SHADER_GEOMETRY:
> + stp = (struct st_common_program *)prog;
> + stp->glsl_to_tgsi = v;
> break;
> case MESA_SHADER_COMPUTE:
> stcp = (struct st_compute_program *)prog;
> stcp->glsl_to_tgsi = v;
> break;
The TESS_CTRL, TESS_EVAL cases are no longer needed? Maybe there should
be a comment about that?
> default:
> assert(!"should not be reached");
> return NULL;
> }
>
> diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
> index 943b7d1..41ffac4 100644
> --- a/src/mesa/state_tracker/st_program.c
> +++ b/src/mesa/state_tracker/st_program.c
> @@ -1898,30 +1898,25 @@ destroy_program_variants(struct st_context *st, struct gl_program *target)
> }
> fpv = next;
> }
> }
> break;
> case GL_GEOMETRY_PROGRAM_NV:
> case GL_TESS_CONTROL_PROGRAM_NV:
> case GL_TESS_EVALUATION_PROGRAM_NV:
> case GL_COMPUTE_PROGRAM_NV:
> {
> - struct st_common_program *gp = (struct st_common_program*)target;
> - struct st_common_program *tcp = (struct st_common_program*)target;
> - struct st_common_program *tep = (struct st_common_program*)target;
> + struct st_common_program *p = (struct st_common_program*)target;
st_common_program() cast wrapper?
> struct st_compute_program *cp = (struct st_compute_program*)target;
> struct st_basic_variant **variants =
> - target->Target == GL_GEOMETRY_PROGRAM_NV ? &gp->variants :
> - target->Target == GL_TESS_CONTROL_PROGRAM_NV ? &tcp->variants :
> - target->Target == GL_TESS_EVALUATION_PROGRAM_NV ? &tep->variants :
> target->Target == GL_COMPUTE_PROGRAM_NV ? &cp->variants :
> - NULL;
> + &p->variants;
> struct st_basic_variant *v, **prevPtr = variants;
>
> for (v = *variants; v; ) {
> struct st_basic_variant *next = v->next;
> if (v->key.st == st) {
> /* unlink from list */
> *prevPtr = next;
> /* destroy this variant */
> delete_basic_variant(st, v, target->Target);
> }
> diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c
> index 0771ca6..393cc4e 100644
> --- a/src/mesa/state_tracker/st_shader_cache.c
> +++ b/src/mesa/state_tracker/st_shader_cache.c
> @@ -79,39 +79,25 @@ st_store_tgsi_in_disk_cache(struct st_context *st, struct gl_program *prog,
> blob_write_uint32(blob, stvp->num_inputs);
> blob_write_bytes(blob, stvp->index_to_input,
> sizeof(stvp->index_to_input));
> blob_write_bytes(blob, stvp->result_to_output,
> sizeof(stvp->result_to_output));
>
> write_stream_out_to_cache(blob, &stvp->tgsi);
> write_tgsi_to_cache(blob, &stvp->tgsi, st, sha1, num_tokens);
> break;
> }
> - case MESA_SHADER_TESS_CTRL: {
> - struct st_common_program *stcp = (struct st_common_program *) prog;
> - sha1 = stcp->sha1;
> -
> - write_stream_out_to_cache(blob, out_state);
> - write_tgsi_to_cache(blob, out_state, st, sha1, num_tokens);
> - break;
> - }
> - case MESA_SHADER_TESS_EVAL: {
> - struct st_common_program *step = (struct st_common_program *) prog;
> - sha1 = step->sha1;
> -
> - write_stream_out_to_cache(blob, out_state);
> - write_tgsi_to_cache(blob, out_state, st, sha1, num_tokens);
> - break;
> - }
> + case MESA_SHADER_TESS_CTRL:
> + case MESA_SHADER_TESS_EVAL:
> case MESA_SHADER_GEOMETRY: {
> - struct st_common_program *stgp = (struct st_common_program *) prog;
> - sha1 = stgp->sha1;
> + struct st_common_program *p = (struct st_common_program *) prog;
> + sha1 = p->sha1;
>
> write_stream_out_to_cache(blob, out_state);
> write_tgsi_to_cache(blob, out_state, st, sha1, num_tokens);
> break;
> }
> case MESA_SHADER_FRAGMENT: {
> struct st_fragment_program *stfp = (struct st_fragment_program *) prog;
> sha1 = stfp->sha1;
>
> write_tgsi_to_cache(blob, &stfp->tgsi, st, sha1, num_tokens);
>
Other than those nits, the series LGTM.
Reviewed-by: Brian Paul <brianp at vmware.com>
-Brian
More information about the mesa-dev
mailing list