st/mesa: translate vertex shaders into TGSI when we get them

The translate functions is split into two:
- translation to TGSI
- creating the variant (TGSI transformations only)

Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Tested-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
Marek Olšák
2015-10-05 02:47:37 +02:00
parent de6a004035
commit 46021ace51
3 changed files with 45 additions and 37 deletions

View File

@@ -249,7 +249,9 @@ st_program_string_notify( struct gl_context *ctx,
else if (target == GL_VERTEX_PROGRAM_ARB) { else if (target == GL_VERTEX_PROGRAM_ARB) {
struct st_vertex_program *stvp = (struct st_vertex_program *) prog; struct st_vertex_program *stvp = (struct st_vertex_program *) prog;
st_release_vp_variants( st, stvp ); st_release_vp_variants(st, stvp);
if (!st_translate_vertex_program(st, stvp))
return false;
if (st->vp == stvp) if (st->vp == stvp)
st->dirty.st |= ST_NEW_VERTEX_PROGRAM; st->dirty.st |= ST_NEW_VERTEX_PROGRAM;

View File

@@ -94,6 +94,11 @@ st_release_vp_variants( struct st_context *st,
} }
stvp->variants = NULL; stvp->variants = NULL;
if (stvp->tgsi.tokens) {
tgsi_free_tokens(stvp->tgsi.tokens);
stvp->tgsi.tokens = NULL;
}
} }
@@ -230,15 +235,12 @@ st_release_tep_variants(struct st_context *st, struct st_tesseval_program *sttep
/** /**
* Translate a vertex program to create a new variant. * Translate a vertex program.
*/ */
static struct st_vp_variant * bool
st_translate_vertex_program(struct st_context *st, st_translate_vertex_program(struct st_context *st,
struct st_vertex_program *stvp, struct st_vertex_program *stvp)
const struct st_vp_variant_key *key)
{ {
struct st_vp_variant *vpv = CALLOC_STRUCT(st_vp_variant);
struct pipe_context *pipe = st->pipe;
struct ureg_program *ureg; struct ureg_program *ureg;
enum pipe_error error; enum pipe_error error;
unsigned num_outputs = 0; unsigned num_outputs = 0;
@@ -372,12 +374,8 @@ st_translate_vertex_program(struct st_context *st,
_mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_OUTPUT); _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_OUTPUT);
ureg = ureg_create_with_screen(TGSI_PROCESSOR_VERTEX, st->pipe->screen); ureg = ureg_create_with_screen(TGSI_PROCESSOR_VERTEX, st->pipe->screen);
if (ureg == NULL) { if (ureg == NULL)
free(vpv); return false;
return NULL;
}
vpv->key = *key;
if (ST_DEBUG & DEBUG_MESA) { if (ST_DEBUG & DEBUG_MESA) {
_mesa_print_program(&stvp->Base.Base); _mesa_print_program(&stvp->Base.Base);
@@ -385,7 +383,7 @@ st_translate_vertex_program(struct st_context *st,
debug_printf("\n"); debug_printf("\n");
} }
if (stvp->glsl_to_tgsi) if (stvp->glsl_to_tgsi) {
error = st_translate_program(st->ctx, error = st_translate_program(st->ctx,
TGSI_PROCESSOR_VERTEX, TGSI_PROCESSOR_VERTEX,
ureg, ureg,
@@ -405,7 +403,11 @@ st_translate_vertex_program(struct st_context *st,
output_slot_to_attr, output_slot_to_attr,
output_semantic_name, output_semantic_name,
output_semantic_index); output_semantic_index);
else
st_translate_stream_output_info(stvp->glsl_to_tgsi,
stvp->result_to_output,
&stvp->tgsi.stream_output);
} else
error = st_translate_mesa_program(st->ctx, error = st_translate_mesa_program(st->ctx,
TGSI_PROCESSOR_VERTEX, TGSI_PROCESSOR_VERTEX,
ureg, ureg,
@@ -422,21 +424,29 @@ st_translate_vertex_program(struct st_context *st,
output_semantic_name, output_semantic_name,
output_semantic_index); output_semantic_index);
if (error) if (error) {
goto fail; debug_printf("%s: failed to translate Mesa program:\n", __func__);
_mesa_print_program(&stvp->Base.Base);
vpv->tgsi.tokens = ureg_get_tokens( ureg, NULL ); debug_assert(0);
if (!vpv->tgsi.tokens) return false;
goto fail;
ureg_destroy( ureg );
if (stvp->glsl_to_tgsi) {
st_translate_stream_output_info(stvp->glsl_to_tgsi,
stvp->result_to_output,
&vpv->tgsi.stream_output);
} }
stvp->tgsi.tokens = ureg_get_tokens(ureg, NULL);
ureg_destroy(ureg);
return stvp->tgsi.tokens != NULL;
}
static struct st_vp_variant *
st_create_vp_variant(struct st_context *st,
struct st_vertex_program *stvp,
const struct st_vp_variant_key *key)
{
struct st_vp_variant *vpv = CALLOC_STRUCT(st_vp_variant);
struct pipe_context *pipe = st->pipe;
vpv->key = *key;
vpv->tgsi.tokens = tgsi_dup_tokens(stvp->tgsi.tokens);
vpv->tgsi.stream_output = stvp->tgsi.stream_output;
vpv->num_inputs = stvp->num_inputs; vpv->num_inputs = stvp->num_inputs;
/* Emulate features. */ /* Emulate features. */
@@ -465,14 +475,6 @@ st_translate_vertex_program(struct st_context *st,
vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi); vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi);
return vpv; return vpv;
fail:
debug_printf("%s: failed to translate Mesa program:\n", __func__);
_mesa_print_program(&stvp->Base.Base);
debug_assert(0);
ureg_destroy( ureg );
return NULL;
} }
@@ -495,7 +497,7 @@ st_get_vp_variant(struct st_context *st,
if (!vpv) { if (!vpv) {
/* create now */ /* create now */
vpv = st_translate_vertex_program(st, stvp, key); vpv = st_create_vp_variant(st, stvp, key);
if (vpv) { if (vpv) {
/* insert into list */ /* insert into list */
vpv->next = stvp->variants; vpv->next = stvp->variants;

View File

@@ -155,6 +155,7 @@ struct st_vp_variant
struct st_vertex_program struct st_vertex_program
{ {
struct gl_vertex_program Base; /**< The Mesa vertex program */ struct gl_vertex_program Base; /**< The Mesa vertex program */
struct pipe_shader_state tgsi;
struct glsl_to_tgsi_visitor* glsl_to_tgsi; struct glsl_to_tgsi_visitor* glsl_to_tgsi;
/** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */ /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
@@ -434,6 +435,9 @@ st_release_tep_variants(struct st_context *st,
extern void extern void
st_destroy_program_variants(struct st_context *st); st_destroy_program_variants(struct st_context *st);
extern bool
st_translate_vertex_program(struct st_context *st,
struct st_vertex_program *stvp);
extern void extern void
st_print_current_vertex_program(void); st_print_current_vertex_program(void);