From bc99b22a305be5e5a5f8fdbf57105d220cf4b0ab Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Wed, 27 Nov 2019 22:25:00 -0500 Subject: [PATCH] st/mesa: use a separate VS variant for the draw module instead of keeping the IR indefinitely in st_vp_variant. This trivially fixes Selection/Feedback/RasterPos for NIR. Reviewed-by: Dave Airlie --- src/mesa/state_tracker/st_draw_feedback.c | 17 +++++------ src/mesa/state_tracker/st_program.c | 35 +++++++---------------- src/mesa/state_tracker/st_program.h | 14 ++++----- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c index c3c31f3e9f6..f03063dc7c8 100644 --- a/src/mesa/state_tracker/st_draw_feedback.c +++ b/src/mesa/state_tracker/st_draw_feedback.c @@ -137,16 +137,13 @@ st_feedback_draw_vbo(struct gl_context *ctx, vbo_get_minmax_indices(ctx, prims, ib, &min_index, &max_index, nr_prims); /* must get these after state validation! */ - vp = (struct st_vertex_program *)st->vp; - vp_variant = st->vp_variant; - - struct pipe_shader_state state = {0}; - state.type = PIPE_SHADER_IR_TGSI; - state.tokens = vp_variant->tokens; + struct st_common_variant_key key; + /* We have to use memcpy to make sure that all bits are copied. */ + memcpy(&key, &st->vp_variant->key, sizeof(key)); + key.is_draw_shader = true; - if (!vp_variant->draw_shader) { - vp_variant->draw_shader = draw_create_vertex_shader(draw, &state); - } + vp = (struct st_vertex_program *)st->vp; + vp_variant = st_get_vp_variant(st, st->vp, &key); /* * Set up the draw module's state. @@ -158,7 +155,7 @@ st_feedback_draw_vbo(struct gl_context *ctx, draw_set_viewport_states(draw, 0, 1, &st->state.viewport[0]); draw_set_clip_state(draw, &st->state.clip); draw_set_rasterizer_state(draw, &st->state.rasterizer, NULL); - draw_bind_vertex_shader(draw, vp_variant->draw_shader); + draw_bind_vertex_shader(draw, vp_variant->base.driver_shader); set_feedback_vertex_format(ctx); /* Must setup these after state validation! */ diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 2dd9227ddd7..12b588d0193 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -41,6 +41,7 @@ #include "program/programopt.h" #include "compiler/nir/nir.h" +#include "draw/draw_context.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -254,16 +255,6 @@ delete_variant(struct st_context *st, struct st_variant *v, GLenum target) } } - if (target == GL_VERTEX_PROGRAM_ARB) { - struct st_vp_variant *vpv = (struct st_vp_variant *)v; - - if (vpv->draw_shader) - draw_delete_vertex_shader( st->draw, vpv->draw_shader ); - - if (vpv->tokens) - ureg_free_tokens(vpv->tokens); - } - free(v); } @@ -656,18 +647,10 @@ st_create_vp_variant(struct st_context *st, if (ST_DEBUG & DEBUG_PRINT_IR) nir_print_shader(state.ir.nir, stderr); - vpv->base.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); + if (key->is_draw_shader) + vpv->base.driver_shader = draw_create_vertex_shader(st->draw, &state); + else + vpv->base.driver_shader = pipe->create_vs_state(pipe, &state); return vpv; } @@ -709,9 +692,11 @@ st_create_vp_variant(struct st_context *st, if (ST_DEBUG & DEBUG_PRINT_IR) tgsi_dump(state.tokens, 0); - vpv->base.driver_shader = pipe->create_vs_state(pipe, &state); - /* Save this for selection/feedback/rasterpos. */ - vpv->tokens = state.tokens; + if (key->is_draw_shader) + vpv->base.driver_shader = draw_create_vertex_shader(st->draw, &state); + else + vpv->base.driver_shader = pipe->create_vs_state(pipe, &state); + return vpv; } diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 62d82c2bf84..65c1577e03c 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -190,6 +190,11 @@ struct st_common_variant_key /* for user-defined clip-planes */ uint8_t lower_ucp; + + /* Whether st_variant::driver_shader is for the draw module, + * not for the driver. + */ + bool is_draw_shader; }; @@ -206,15 +211,6 @@ struct st_vp_variant */ struct st_common_variant_key key; - /** - * The shader variant saved for the draw module to later emulate - * selection/feedback/rasterpos. - */ - const struct tgsi_token *tokens; - - /** For using our private draw module (glRasterPos) */ - struct draw_vertex_shader *draw_shader; - /** similar to that in st_vertex_program, but with edgeflags info too */ GLuint num_inputs; -- 2.30.2