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 <airlied@redhat.com>
This commit is contained in:
Marek Olšák
2019-11-27 22:25:00 -05:00
parent 17e8839a2f
commit bc99b22a30
3 changed files with 22 additions and 44 deletions

View File

@@ -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! */
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;
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;
if (!vp_variant->draw_shader) {
vp_variant->draw_shader = draw_create_vertex_shader(draw, &state);
}
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! */

View File

@@ -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;
}

View File

@@ -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;