From 1cc866c264c516556ae1e9aa68370e811fd898a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 30 Sep 2019 17:06:45 -0400 Subject: [PATCH] st/mesa: remove st_compute_program in favor of st_common_program The conversion from pipe_shader_state to pipe_compute_state is done at the end. Reviewed-by: Timothy Arceri --- src/mesa/state_tracker/st_atom.c | 4 +- src/mesa/state_tracker/st_atom_constbuf.c | 2 +- src/mesa/state_tracker/st_atom_shader.c | 5 +- src/mesa/state_tracker/st_cb_program.c | 31 ++----- src/mesa/state_tracker/st_context.c | 4 +- src/mesa/state_tracker/st_context.h | 2 +- src/mesa/state_tracker/st_glsl_to_nir.cpp | 8 +- src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 6 +- src/mesa/state_tracker/st_program.c | 95 ++++++---------------- src/mesa/state_tracker/st_program.h | 46 ++--------- src/mesa/state_tracker/st_shader_cache.c | 30 ++----- 11 files changed, 59 insertions(+), 174 deletions(-) diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 49f79ad9d49..74fe5462544 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -219,14 +219,14 @@ void st_validate_state( struct st_context *st, enum st_pipeline pipeline ) break; case ST_PIPELINE_COMPUTE: { - struct st_compute_program *old_cp = st->cp; + struct st_common_program *old_cp = st->cp; struct gl_program *new_cp = ctx->ComputeProgram._Current; if (new_cp != &old_cp->Base) { if (old_cp) st->dirty |= old_cp->affected_states; assert(new_cp); - st->dirty |= st_compute_program(new_cp)->affected_states; + st->dirty |= st_common_program(new_cp)->affected_states; } st->compute_shader_may_be_dirty = false; diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index fa147b89688..eabd854459a 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -188,7 +188,7 @@ st_update_tes_constants(struct st_context *st) void st_update_cs_constants(struct st_context *st) { - struct st_compute_program *cp = st->cp; + struct st_common_program *cp = st->cp; if (cp) st_upload_constants(st, &cp->Base); diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index f9c61c055cc..52294f6da6e 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -301,7 +301,7 @@ st_update_tep(struct st_context *st) void st_update_cp( struct st_context *st ) { - struct st_compute_program *stcp; + struct st_common_program *stcp; if (!st->ctx->ComputeProgram._Current) { cso_set_compute_shader_handle(st->cso_context, NULL); @@ -309,7 +309,7 @@ st_update_cp( struct st_context *st ) return; } - stcp = st_compute_program(st->ctx->ComputeProgram._Current); + stcp = st_common_program(st->ctx->ComputeProgram._Current); assert(stcp->Base.Target == GL_COMPUTE_PROGRAM_NV); void *shader; @@ -318,6 +318,7 @@ st_update_cp( struct st_context *st ) shader = stcp->variants->driver_shader; } else { shader = st_get_cp_variant(st, &stcp->tgsi, + stcp->Base.info.cs.shared_size, &stcp->variants)->driver_shader; } diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 9ca1ada109d..5070268a616 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -71,16 +71,12 @@ st_new_program(struct gl_context *ctx, GLenum target, GLuint id, } case GL_TESS_CONTROL_PROGRAM_NV: case GL_TESS_EVALUATION_PROGRAM_NV: - case GL_GEOMETRY_PROGRAM_NV: { + case GL_GEOMETRY_PROGRAM_NV: + case GL_COMPUTE_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_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; @@ -109,6 +105,7 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog) case GL_TESS_CONTROL_PROGRAM_NV: case GL_TESS_EVALUATION_PROGRAM_NV: case GL_GEOMETRY_PROGRAM_NV: + case GL_COMPUTE_PROGRAM_NV: { struct st_common_program *p = st_common_program(prog); @@ -129,17 +126,6 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog) free_glsl_to_tgsi_visitor(stfp->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); - } - break; default: assert(0); /* problem */ } @@ -223,10 +209,10 @@ st_program_string_notify( struct gl_context *ctx, st->dirty |= sttep->affected_states; } else if (target == GL_COMPUTE_PROGRAM_NV) { - struct st_compute_program *stcp = - (struct st_compute_program *) prog; + struct st_common_program *stcp = + (struct st_common_program *) prog; - st_release_cp_variants(st, stcp); + st_release_basic_variants(st, stcp); if (!st_translate_compute_program(st, stcp)) return false; @@ -292,13 +278,10 @@ st_get_shader_program_completion_status(struct gl_context *ctx, case MESA_SHADER_TESS_CTRL: case MESA_SHADER_TESS_EVAL: case MESA_SHADER_GEOMETRY: + case MESA_SHADER_COMPUTE: if (st_common_program(linked->Program)->variants) sh = st_common_program(linked->Program)->variants->driver_shader; break; - case MESA_SHADER_COMPUTE: - if (st_compute_program(linked->Program)->variants) - sh = st_compute_program(linked->Program)->variants->driver_shader; - break; } unsigned type = pipe_shader_type_from_mesa(i); diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 163f996d64c..545d56996fb 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -147,8 +147,8 @@ st_get_active_states(struct gl_context *ctx) st_common_program(ctx->GeometryProgram._Current); struct st_fragment_program *fp = st_fragment_program(ctx->FragmentProgram._Current); - struct st_compute_program *cp = - st_compute_program(ctx->ComputeProgram._Current); + struct st_common_program *cp = + st_common_program(ctx->ComputeProgram._Current); uint64_t active_shader_states = 0; if (vp) diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 1142e0f71bd..0a14ef9b98c 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -233,7 +233,7 @@ struct st_context struct st_common_program *gp; /**< Currently bound geometry program */ struct st_common_program *tcp; /**< Currently bound tess control program */ struct st_common_program *tep; /**< Currently bound tess eval program */ - struct st_compute_program *cp; /**< Currently bound compute program */ + struct st_common_program *cp; /**< Currently bound compute program */ struct st_vp_variant *vp_variant; diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index dc6429f5671..f34ed7fa6a6 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -504,7 +504,6 @@ set_st_program(struct gl_program *prog, struct st_vertex_program *stvp; struct st_common_program *stp; struct st_fragment_program *stfp; - struct st_compute_program *stcp; switch (prog->info.stage) { case MESA_SHADER_VERTEX: @@ -516,6 +515,7 @@ set_st_program(struct gl_program *prog, case MESA_SHADER_GEOMETRY: case MESA_SHADER_TESS_CTRL: case MESA_SHADER_TESS_EVAL: + case MESA_SHADER_COMPUTE: stp = (struct st_common_program *)prog; stp->shader_program = shader_program; stp->tgsi.type = PIPE_SHADER_IR_NIR; @@ -527,12 +527,6 @@ set_st_program(struct gl_program *prog, stfp->tgsi.type = PIPE_SHADER_IR_NIR; stfp->tgsi.ir.nir = nir; break; - case MESA_SHADER_COMPUTE: - stcp = (struct st_compute_program *)prog; - stcp->shader_program = shader_program; - stcp->tgsi.ir_type = PIPE_SHADER_IR_NIR; - stcp->tgsi.prog = nir; - break; default: unreachable("unknown shader stage"); } diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 1e9138ac1d4..9c7b00922c4 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -7311,7 +7311,6 @@ get_mesa_program_tgsi(struct gl_context *ctx, struct st_vertex_program *stvp; struct st_fragment_program *stfp; struct st_common_program *stp; - struct st_compute_program *stcp; switch (shader->Stage) { case MESA_SHADER_VERTEX: @@ -7325,13 +7324,10 @@ get_mesa_program_tgsi(struct gl_context *ctx, case MESA_SHADER_TESS_CTRL: case MESA_SHADER_TESS_EVAL: case MESA_SHADER_GEOMETRY: + case MESA_SHADER_COMPUTE: stp = 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; 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 73a2bf3d280..4e36d3387da 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -188,7 +188,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog) break; case MESA_SHADER_COMPUTE: - states = &((struct st_compute_program*)prog)->affected_states; + states = &((struct st_common_program*)prog)->affected_states; *states = ST_NEW_CS_STATE; @@ -210,8 +210,10 @@ st_set_prog_affected_state_flags(struct gl_program *prog) static void delete_ir(struct pipe_shader_state *ir) { - if (ir->tokens) + if (ir->tokens) { ureg_free_tokens(ir->tokens); + ir->tokens = NULL; + } /* Note: Any setup of ->ir.nir that has had pipe->create_*_state called on * it has resulted in the driver taking ownership of the NIR. Those @@ -385,43 +387,6 @@ st_release_basic_variants(struct st_context *st, struct st_common_program *p) } -/** - * Free all variants of a compute program. - */ -void -st_release_cp_variants(struct st_context *st, struct st_compute_program *stcp) -{ - struct st_basic_variant **variants = &stcp->variants; - struct st_basic_variant *v; - - for (v = *variants; v; ) { - struct st_basic_variant *next = v->next; - delete_basic_variant(st, v, stcp->Base.Target); - v = next; - } - - *variants = NULL; - - if (stcp->tgsi.prog) { - switch (stcp->tgsi.ir_type) { - case PIPE_SHADER_IR_TGSI: - ureg_free_tokens(stcp->tgsi.prog); - stcp->tgsi.prog = NULL; - break; - case PIPE_SHADER_IR_NIR: - /* pipe driver took ownership of prog */ - break; - case PIPE_SHADER_IR_NATIVE: - /* ??? */ - stcp->tgsi.prog = NULL; - break; - case PIPE_SHADER_IR_NIR_SERIALIZED: - unreachable("serialized nirs aren't passed through st/mesa"); - break; - } - } -} - /** * Translate ARB (asm) program to NIR */ @@ -1556,14 +1521,9 @@ st_translate_program_common(struct st_context *st, output_semantic_name, output_semantic_index); - if (tgsi_processor == PIPE_SHADER_COMPUTE) { - struct st_compute_program *stcp = (struct st_compute_program *) prog; - out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens); - stcp->tgsi.prog = out_state->tokens; - } else { - struct st_common_program *stcp = (struct st_common_program *) prog; - out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens); - } + struct st_common_program *stcp = (struct st_common_program *) prog; + out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens); + ureg_destroy(ureg); st_translate_stream_output_info(prog->sh.LinkedTransformFeedback, @@ -1833,17 +1793,14 @@ st_translate_tesseval_program(struct st_context *st, */ bool st_translate_compute_program(struct st_context *st, - struct st_compute_program *stcp) + struct st_common_program *stcp) { struct ureg_program *ureg; - struct pipe_shader_state prog; - - stcp->tgsi.req_local_mem = stcp->Base.info.cs.shared_size; if (stcp->shader_program) { /* no compute variants: */ st_finalize_nir(st, &stcp->Base, stcp->shader_program, - (struct nir_shader *) stcp->tgsi.prog); + (struct nir_shader *) stcp->tgsi.ir.nir); st_store_ir_in_disk_cache(st, &stcp->Base, true); return true; } @@ -1853,11 +1810,7 @@ st_translate_compute_program(struct st_context *st, return false; st_translate_program_common(st, &stcp->Base, stcp->glsl_to_tgsi, ureg, - PIPE_SHADER_COMPUTE, &prog); - - stcp->tgsi.ir_type = PIPE_SHADER_IR_TGSI; - stcp->tgsi.req_private_mem = 0; - stcp->tgsi.req_input_mem = 0; + PIPE_SHADER_COMPUTE, &stcp->tgsi); free_glsl_to_tgsi_visitor(stcp->glsl_to_tgsi); stcp->glsl_to_tgsi = NULL; @@ -1870,7 +1823,8 @@ 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 pipe_shader_state *tgsi, + unsigned shared_size, struct st_basic_variant **variants) { struct pipe_context *pipe = st->pipe; @@ -1894,9 +1848,16 @@ st_get_cp_variant(struct st_context *st, v = CALLOC_STRUCT(st_basic_variant); if (v) { /* fill in new variant */ - struct pipe_compute_state cs = *tgsi; - if (tgsi->ir_type == PIPE_SHADER_IR_NIR) - cs.prog = nir_shader_clone(NULL, tgsi->prog); + struct pipe_compute_state cs = {0}; + + cs.ir_type = tgsi->type; + cs.req_local_mem = shared_size; + + if (tgsi->type == PIPE_SHADER_IR_NIR) + cs.prog = nir_shader_clone(NULL, tgsi->ir.nir); + else + cs.prog = tgsi->tokens; + v->driver_shader = pipe->create_compute_state(pipe, &cs); v->key = key; @@ -1968,13 +1929,9 @@ destroy_program_variants(struct st_context *st, struct gl_program *target) case GL_COMPUTE_PROGRAM_NV: { struct st_common_program *p = st_common_program(target); - struct st_compute_program *cp = (struct st_compute_program*)target; - struct st_basic_variant **variants = - target->Target == GL_COMPUTE_PROGRAM_NV ? &cp->variants : - &p->variants; - struct st_basic_variant *v, **prevPtr = variants; + struct st_basic_variant *v, **prevPtr = &p->variants; - for (v = *variants; v; ) { + for (v = p->variants; v; ) { struct st_basic_variant *next = v->next; if (v->key.st == st) { /* unlink from list */ @@ -2155,8 +2112,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_common_program *p = (struct st_common_program *)prog; + st_get_cp_variant(st, &p->tgsi, prog->info.cs.shared_size, &p->variants); break; } diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 4b0fcff96a7..a337f529348 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -314,29 +314,6 @@ struct st_common_program }; -/** - * Derived from Mesa gl_program: - */ -struct st_compute_program -{ - struct gl_program Base; /**< The Mesa compute program */ - struct pipe_compute_state tgsi; - struct glsl_to_tgsi_visitor* glsl_to_tgsi; - uint64_t affected_states; /**< ST_NEW_* flags to mark dirty when binding */ - - /* used when bypassing glsl_to_tgsi: */ - struct gl_shader_program *shader_program; - - struct st_basic_variant *variants; - - /** SHA1 hash of linked tgsi shader program, used for on-disk cache */ - unsigned char sha1[20]; - - /* Used by the shader cache and ARB_get_program_binary */ - unsigned num_tgsi_tokens; -}; - - static inline struct st_fragment_program * st_fragment_program( struct gl_program *fp ) { @@ -351,15 +328,9 @@ st_vertex_program( struct gl_program *vp ) } static inline struct st_common_program * -st_common_program( struct gl_program *gp ) -{ - return (struct st_common_program *)gp; -} - -static inline struct st_compute_program * -st_compute_program( struct gl_program *cp ) +st_common_program( struct gl_program *cp ) { - return (struct st_compute_program *)cp; + return (struct st_common_program *)cp; } static inline void @@ -394,8 +365,8 @@ st_reference_prog(struct st_context *st, static inline void st_reference_compprog(struct st_context *st, - struct st_compute_program **ptr, - struct st_compute_program *prog) + struct st_common_program **ptr, + struct st_common_program *prog) { _mesa_reference_program(st->ctx, (struct gl_program **) ptr, @@ -428,7 +399,8 @@ 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 pipe_shader_state *tgsi, + unsigned shared_size, struct st_basic_variant **variants); extern struct st_basic_variant * @@ -445,10 +417,6 @@ extern void st_release_fp_variants( struct st_context *st, struct st_fragment_program *stfp ); -extern void -st_release_cp_variants(struct st_context *st, - struct st_compute_program *stcp); - extern void st_release_basic_variants(struct st_context *st, struct st_common_program *p); @@ -477,7 +445,7 @@ st_translate_tesseval_program(struct st_context *st, extern bool st_translate_compute_program(struct st_context *st, - struct st_compute_program *stcp); + struct st_common_program *stcp); extern void st_print_current_vertex_program(void); diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c index 7bb36b609c9..901918eb7b2 100644 --- a/src/mesa/state_tracker/st_shader_cache.c +++ b/src/mesa/state_tracker/st_shader_cache.c @@ -104,7 +104,8 @@ st_serialise_ir_program(struct gl_context *ctx, struct gl_program *prog, } case MESA_SHADER_TESS_CTRL: case MESA_SHADER_TESS_EVAL: - case MESA_SHADER_GEOMETRY: { + case MESA_SHADER_GEOMETRY: + case MESA_SHADER_COMPUTE: { struct st_common_program *stcp = (struct st_common_program *) prog; if (prog->info.stage == MESA_SHADER_TESS_EVAL || @@ -128,16 +129,6 @@ st_serialise_ir_program(struct gl_context *ctx, struct gl_program *prog, stfp->num_tgsi_tokens); break; } - case MESA_SHADER_COMPUTE: { - struct st_compute_program *stcp = (struct st_compute_program *) prog; - - if (nir) - write_nir_to_cache(&blob, prog); - else - write_tgsi_to_cache(&blob, stcp->tgsi.prog, prog, - stcp->num_tgsi_tokens); - break; - } default: unreachable("Unsupported stage"); } @@ -319,25 +310,20 @@ st_deserialise_ir_program(struct gl_context *ctx, break; } case MESA_SHADER_COMPUTE: { - struct st_compute_program *stcp = (struct st_compute_program *) prog; + struct st_common_program *stcp = (struct st_common_program *) prog; - st_release_cp_variants(st, stcp); + st_release_basic_variants(st, stcp); if (nir) { - stcp->tgsi.ir_type = PIPE_SHADER_IR_NIR; + stcp->tgsi.type = PIPE_SHADER_IR_NIR; + stcp->tgsi.ir.nir = nir_deserialize(NULL, options, &blob_reader); stcp->shader_program = shProg; - stcp->tgsi.prog = nir_deserialize(NULL, options, &blob_reader); - prog->nir = (nir_shader *) stcp->tgsi.prog; + prog->nir = (nir_shader *) stcp->tgsi.ir.nir; } else { - read_tgsi_from_cache(&blob_reader, - (const struct tgsi_token**) &stcp->tgsi.prog, + read_tgsi_from_cache(&blob_reader, &stcp->tgsi.tokens, &stcp->num_tgsi_tokens); } - stcp->tgsi.req_local_mem = stcp->Base.info.cs.shared_size; - stcp->tgsi.req_private_mem = 0; - stcp->tgsi.req_input_mem = 0; - if (st->cp == stcp) st->dirty |= stcp->affected_states; -- 2.30.2