From b23967a5e1855d58538c1d4bd1f4ec6df692188f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 11 Oct 2019 14:53:15 -0400 Subject: [PATCH] st/mesa: move vertex program preparation code into st_prepare_vertex_program Reviewed-by: Timothy Arceri --- src/mesa/state_tracker/st_program.c | 70 ++++++++++++++++------------- src/mesa/state_tracker/st_program.h | 3 ++ 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index b0605cf28ba..1435429255b 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -413,35 +413,22 @@ st_translate_prog_to_nir(struct st_context *st, struct gl_program *prog, return nir; } -/** - * Translate a vertex program. - */ -bool -st_translate_vertex_program(struct st_context *st, - struct st_vertex_program *stvp) +void +st_prepare_vertex_program(struct st_vertex_program *stvp) { - struct ureg_program *ureg; - enum pipe_error error; - unsigned num_outputs = 0; - unsigned attr; - ubyte output_semantic_name[VARYING_SLOT_MAX] = {0}; - ubyte output_semantic_index[VARYING_SLOT_MAX] = {0}; - stvp->num_inputs = 0; memset(stvp->input_to_index, ~0, sizeof(stvp->input_to_index)); + memset(stvp->result_to_output, ~0, sizeof(stvp->result_to_output)); - if (stvp->Base.arb.IsPositionInvariant) - _mesa_insert_mvp_code(st->ctx, &stvp->Base); - - /* - * Determine number of inputs, the mappings between VERT_ATTRIB_x + /* Determine number of inputs, the mappings between VERT_ATTRIB_x * and TGSI generic input indexes, plus input attrib semantic info. */ - for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) { + for (unsigned attr = 0; attr < VERT_ATTRIB_MAX; attr++) { if ((stvp->Base.info.inputs_read & BITFIELD64_BIT(attr)) != 0) { stvp->input_to_index[attr] = stvp->num_inputs; stvp->index_to_input[stvp->num_inputs] = attr; stvp->num_inputs++; + if ((stvp->Base.DualSlotInputs & BITFIELD64_BIT(attr)) != 0) { /* add placeholder for second part of a double attribute */ stvp->index_to_input[stvp->num_inputs] = ST_DOUBLE_ATTRIB_PLACEHOLDER; @@ -449,21 +436,43 @@ st_translate_vertex_program(struct st_context *st, } } } - /* bit of a hack, presetup potentially unused edgeflag input */ + /* pre-setup potentially unused edgeflag input */ stvp->input_to_index[VERT_ATTRIB_EDGEFLAG] = stvp->num_inputs; stvp->index_to_input[stvp->num_inputs] = VERT_ATTRIB_EDGEFLAG; - /* Compute mapping of vertex program outputs to slots. - */ - for (attr = 0; attr < VARYING_SLOT_MAX; attr++) { - if ((stvp->Base.info.outputs_written & BITFIELD64_BIT(attr)) == 0) { - stvp->result_to_output[attr] = ~0; - } - else { - unsigned slot = num_outputs++; + /* Compute mapping of vertex program outputs to slots. */ + unsigned num_outputs = 0; + for (unsigned attr = 0; attr < VARYING_SLOT_MAX; attr++) { + if (stvp->Base.info.outputs_written & BITFIELD64_BIT(attr)) + stvp->result_to_output[attr] = num_outputs++; + } + /* pre-setup potentially unused edgeflag output */ + stvp->result_to_output[VARYING_SLOT_EDGE] = num_outputs; +} + +/** + * Translate a vertex program. + */ +bool +st_translate_vertex_program(struct st_context *st, + struct st_vertex_program *stvp) +{ + struct ureg_program *ureg; + enum pipe_error error; + unsigned num_outputs = 0; + unsigned attr; + ubyte output_semantic_name[VARYING_SLOT_MAX] = {0}; + ubyte output_semantic_index[VARYING_SLOT_MAX] = {0}; - stvp->result_to_output[attr] = slot; + if (stvp->Base.arb.IsPositionInvariant) + _mesa_insert_mvp_code(st->ctx, &stvp->Base); + + st_prepare_vertex_program(stvp); + /* Get semantic names and indices. */ + for (attr = 0; attr < VARYING_SLOT_MAX; attr++) { + if (stvp->Base.info.outputs_written & BITFIELD64_BIT(attr)) { + unsigned slot = num_outputs++; unsigned semantic_name, semantic_index; tgsi_get_gl_varying_semantic(attr, st->needs_texcoord_semantic, &semantic_name, &semantic_index); @@ -471,8 +480,7 @@ st_translate_vertex_program(struct st_context *st, output_semantic_index[slot] = semantic_index; } } - /* similar hack to above, presetup potentially unused edgeflag output */ - stvp->result_to_output[VARYING_SLOT_EDGE] = num_outputs; + /* pre-setup potentially unused edgeflag output */ output_semantic_name[num_outputs] = TGSI_SEMANTIC_EDGEFLAG; output_semantic_index[num_outputs] = 0; diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index b8ad86a4738..874ef211a82 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -416,6 +416,9 @@ st_release_basic_variants(struct st_context *st, struct st_common_program *p); extern void st_destroy_program_variants(struct st_context *st); +extern void +st_prepare_vertex_program(struct st_vertex_program *stvp); + extern bool st_translate_vertex_program(struct st_context *st, struct st_vertex_program *stvp); -- 2.30.2