From f764725b3ef5dccbc66e9bee887964c60b1f3919 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 17 Oct 2019 22:41:54 -0400 Subject: [PATCH] st/mesa: replace pipe_shader_state with tgsi_token* in st_vp_variant we don't need more than that Reviewed-by: Kenneth Graunke --- src/mesa/state_tracker/st_debug.c | 2 +- src/mesa/state_tracker/st_draw_feedback.c | 8 ++- src/mesa/state_tracker/st_program.c | 72 +++++++++++++---------- src/mesa/state_tracker/st_program.h | 2 +- 4 files changed, 48 insertions(+), 36 deletions(-) diff --git a/src/mesa/state_tracker/st_debug.c b/src/mesa/state_tracker/st_debug.c index 88a788518a1..06e2456ac98 100644 --- a/src/mesa/state_tracker/st_debug.c +++ b/src/mesa/state_tracker/st_debug.c @@ -93,7 +93,7 @@ st_print_current(void) #endif if (st->vp->variants) - tgsi_dump( st->vp->variants[0].state.tokens, 0 ); + tgsi_dump(st->vp->variants[0].tokens, 0); if (st->vp->Base.Parameters) _mesa_print_parameter_list(st->vp->Base.Parameters); diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c index e0aae5aef44..118b7d0b2fb 100644 --- a/src/mesa/state_tracker/st_draw_feedback.c +++ b/src/mesa/state_tracker/st_draw_feedback.c @@ -108,7 +108,6 @@ st_feedback_draw_vbo(struct gl_context *ctx, struct draw_context *draw = st_get_draw_context(st); const struct st_vertex_program *vp; struct st_vp_variant *vp_variant; - const struct pipe_shader_state *vs; struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS]; unsigned num_vbuffers = 0; struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; @@ -139,10 +138,13 @@ st_feedback_draw_vbo(struct gl_context *ctx, /* must get these after state validation! */ vp = st->vp; vp_variant = st->vp_variant; - vs = &vp_variant->state; + + struct pipe_shader_state state = {0}; + state.type = PIPE_SHADER_IR_TGSI; + state.tokens = vp_variant->tokens; if (!vp_variant->draw_shader) { - vp_variant->draw_shader = draw_create_vertex_shader(draw, vs); + vp_variant->draw_shader = draw_create_vertex_shader(draw, &state); } /* diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index f909ada7a1a..684599e4ef5 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -244,7 +244,8 @@ delete_vp_variant(struct st_context *st, struct st_vp_variant *vpv) if (vpv->draw_shader) draw_delete_vertex_shader( st->draw, vpv->draw_shader ); - delete_ir(&vpv->state); + if (vpv->tokens) + ureg_free_tokens(vpv->tokens); free( vpv ); } @@ -647,36 +648,30 @@ st_create_vp_variant(struct st_context *st, { struct st_vp_variant *vpv = CALLOC_STRUCT(st_vp_variant); struct pipe_context *pipe = st->pipe; + struct pipe_shader_state state = {0}; static const gl_state_index16 point_size_state[STATE_LENGTH] = { STATE_INTERNAL, STATE_POINT_SIZE_CLAMPED, 0 }; struct gl_program_parameter_list *params = stvp->Base.Parameters; vpv->key = *key; - vpv->state.stream_output = stvp->state.stream_output; vpv->num_inputs = stvp->num_inputs; - /* When generating a NIR program, we usually don't have TGSI tokens. - * However, we do create them for ARB_vertex_program / fixed-function VS - * programs which we may need to use with the draw module for legacy - * feedback/select emulation. If they exist, copy them. - */ - if (stvp->state.tokens) - vpv->state.tokens = tgsi_dup_tokens(stvp->state.tokens); + state.stream_output = stvp->state.stream_output; if (stvp->state.type == PIPE_SHADER_IR_NIR) { - vpv->state.type = PIPE_SHADER_IR_NIR; - vpv->state.ir.nir = nir_shader_clone(NULL, stvp->state.ir.nir); + state.type = PIPE_SHADER_IR_NIR; + state.ir.nir = nir_shader_clone(NULL, stvp->state.ir.nir); if (key->clamp_color) - NIR_PASS_V(vpv->state.ir.nir, nir_lower_clamp_color_outputs); + NIR_PASS_V(state.ir.nir, nir_lower_clamp_color_outputs); if (key->passthrough_edgeflags) { - NIR_PASS_V(vpv->state.ir.nir, nir_lower_passthrough_edgeflags); + NIR_PASS_V(state.ir.nir, nir_lower_passthrough_edgeflags); vpv->num_inputs++; } if (key->lower_point_size) { _mesa_add_state_reference(params, point_size_state); - NIR_PASS_V(vpv->state.ir.nir, nir_lower_point_size_mov, + NIR_PASS_V(state.ir.nir, nir_lower_point_size_mov, point_size_state); } @@ -699,21 +694,34 @@ st_create_vp_variant(struct st_context *st, _mesa_add_state_reference(params, clipplane_state[i]); } - NIR_PASS_V(vpv->state.ir.nir, nir_lower_clip_vs, key->lower_ucp, + NIR_PASS_V(state.ir.nir, nir_lower_clip_vs, key->lower_ucp, true, can_compact, clipplane_state); - NIR_PASS_V(vpv->state.ir.nir, nir_lower_io_to_temporaries, - nir_shader_get_entrypoint(vpv->state.ir.nir), true, false); + NIR_PASS_V(state.ir.nir, nir_lower_io_to_temporaries, + nir_shader_get_entrypoint(state.ir.nir), true, false); } st_finalize_nir(st, &stvp->Base, stvp->shader_program, - vpv->state.ir.nir); + state.ir.nir); + + vpv->driver_shader = pipe->create_vs_state(pipe, &state); + + /* When generating a NIR program, we usually don't have TGSI tokens. + * However, we do create them for ARB_vertex_program / fixed-function VS + * programs which we may need to use with the draw module for legacy + * feedback/select emulation. If they exist, copy them. + * + * TODO: Lowering for shader variants is not applied to TGSI when + * generating a NIR shader. + */ + if (stvp->state.tokens) + vpv->tokens = tgsi_dup_tokens(stvp->state.tokens); - vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->state); - /* driver takes ownership of IR: */ - vpv->state.ir.nir = NULL; return vpv; } + state.type = PIPE_SHADER_IR_TGSI; + state.tokens = tgsi_dup_tokens(stvp->state.tokens); + /* Emulate features. */ if (key->clamp_color || key->passthrough_edgeflags) { const struct tgsi_token *tokens; @@ -721,11 +729,11 @@ st_create_vp_variant(struct st_context *st, (key->clamp_color ? TGSI_EMU_CLAMP_COLOR_OUTPUTS : 0) | (key->passthrough_edgeflags ? TGSI_EMU_PASSTHROUGH_EDGEFLAG : 0); - tokens = tgsi_emulate(vpv->state.tokens, flags); + tokens = tgsi_emulate(state.tokens, flags); if (tokens) { - tgsi_free_tokens(vpv->state.tokens); - vpv->state.tokens = tokens; + tgsi_free_tokens(state.tokens); + state.tokens = tokens; if (key->passthrough_edgeflags) vpv->num_inputs++; @@ -738,19 +746,21 @@ st_create_vp_variant(struct st_context *st, _mesa_add_state_reference(params, depth_range_state); const struct tgsi_token *tokens; - tokens = st_tgsi_lower_depth_clamp(vpv->state.tokens, depth_range_const, + tokens = st_tgsi_lower_depth_clamp(state.tokens, depth_range_const, key->clip_negative_one_to_one); - if (tokens != vpv->state.tokens) - tgsi_free_tokens(vpv->state.tokens); - vpv->state.tokens = tokens; + if (tokens != state.tokens) + tgsi_free_tokens(state.tokens); + state.tokens = tokens; } if (ST_DEBUG & DEBUG_TGSI) { - tgsi_dump(vpv->state.tokens, 0); + tgsi_dump(state.tokens, 0); debug_printf("\n"); } - vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->state); + vpv->driver_shader = pipe->create_vs_state(pipe, &state); + /* Save this for selection/feedback/rasterpos. */ + vpv->tokens = state.tokens; return vpv; } @@ -1942,7 +1952,7 @@ st_print_current_vertex_program(void) for (stv = stvp->variants; stv; stv = stv->next) { debug_printf("variant %p\n", stv); - tgsi_dump(stv->state.tokens, 0); + tgsi_dump(stv->tokens, 0); } } } diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index ee443628b78..d698e7b633f 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -198,7 +198,7 @@ struct st_vp_variant * The shader variant saved for the draw module to later emulate * selection/feedback/rasterpos. */ - struct pipe_shader_state state; + const struct tgsi_token *tokens; /** Driver's compiled shader */ void *driver_shader; -- 2.30.2