From: Marek Olšák Date: Fri, 11 Oct 2019 19:08:40 +0000 (-0400) Subject: st/mesa: unify transform feedback info translation code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=45378689e02ac8ee89ebf8b419bc0a808e57f426;p=mesa.git st/mesa: unify transform feedback info translation code Reviewed-by: Timothy Arceri --- diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 9c7b00922c4..3e73b4dc576 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -7453,35 +7453,3 @@ st_link_tgsi(struct gl_context *ctx, struct gl_shader_program *prog) return GL_TRUE; } - -extern "C" { - -void -st_translate_stream_output_info(struct gl_transform_feedback_info *info, - const ubyte outputMapping[], - struct pipe_stream_output_info *so) -{ - unsigned i; - - if (!info) { - so->num_outputs = 0; - return; - } - - for (i = 0; i < info->NumOutputs; i++) { - so->output[i].register_index = - outputMapping[info->Outputs[i].OutputRegister]; - so->output[i].start_component = info->Outputs[i].ComponentOffset; - so->output[i].num_components = info->Outputs[i].NumComponents; - so->output[i].output_buffer = info->Outputs[i].OutputBuffer; - so->output[i].dst_offset = info->Outputs[i].DstOffset; - so->output[i].stream = info->Outputs[i].StreamId; - } - - for (i = 0; i < PIPE_MAX_SO_BUFFERS; i++) { - so->stride[i] = info->Buffers[i].Stride; - } - so->num_outputs = info->NumOutputs; -} - -} /* extern "C" */ diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.h b/src/mesa/state_tracker/st_glsl_to_tgsi.h index fb89c39fb88..dda75ee93b8 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.h +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.h @@ -61,11 +61,6 @@ void free_glsl_to_tgsi_visitor(struct glsl_to_tgsi_visitor *v); GLboolean st_link_tgsi(struct gl_context *ctx, struct gl_shader_program *prog); -void -st_translate_stream_output_info(struct gl_transform_feedback_info *info, - const ubyte outputMapping[], - struct pipe_stream_output_info *so); - enum tgsi_semantic _mesa_sysval_to_semantic(unsigned sysval); diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 1435429255b..0e231618044 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -450,6 +450,46 @@ st_prepare_vertex_program(struct st_vertex_program *stvp) stvp->result_to_output[VARYING_SLOT_EDGE] = num_outputs; } +void +st_translate_stream_output_info(struct gl_program *prog) +{ + struct gl_transform_feedback_info *info = prog->sh.LinkedTransformFeedback; + if (!info) + return; + + /* Determine the (default) output register mapping for each output. */ + unsigned num_outputs = 0; + ubyte output_mapping[VARYING_SLOT_TESS_MAX]; + memset(output_mapping, 0, sizeof(output_mapping)); + + for (unsigned attr = 0; attr < VARYING_SLOT_MAX; attr++) { + if (prog->info.outputs_written & BITFIELD64_BIT(attr)) + output_mapping[attr] = num_outputs++; + } + + /* Translate stream output info. */ + struct pipe_stream_output_info *so_info = NULL; + if (prog->info.stage == MESA_SHADER_VERTEX) + so_info = &((struct st_vertex_program*)prog)->tgsi.stream_output; + else + so_info = &((struct st_common_program*)prog)->tgsi.stream_output; + + for (unsigned i = 0; i < info->NumOutputs; i++) { + so_info->output[i].register_index = + output_mapping[info->Outputs[i].OutputRegister]; + so_info->output[i].start_component = info->Outputs[i].ComponentOffset; + so_info->output[i].num_components = info->Outputs[i].NumComponents; + so_info->output[i].output_buffer = info->Outputs[i].OutputBuffer; + so_info->output[i].dst_offset = info->Outputs[i].DstOffset; + so_info->output[i].stream = info->Outputs[i].StreamId; + } + + for (unsigned i = 0; i < PIPE_MAX_SO_BUFFERS; i++) { + so_info->stride[i] = info->Buffers[i].Stride; + } + so_info->num_outputs = info->NumOutputs; +} + /** * Translate a vertex program. */ @@ -502,10 +542,7 @@ st_translate_vertex_program(struct st_context *st, } if (stvp->shader_program) { - st_translate_stream_output_info(stvp->Base.sh.LinkedTransformFeedback, - stvp->result_to_output, - &stvp->tgsi.stream_output); - + st_translate_stream_output_info(&stvp->Base); st_store_ir_in_disk_cache(st, &stvp->Base, true); return true; } @@ -546,9 +583,7 @@ st_translate_vertex_program(struct st_context *st, output_semantic_name, output_semantic_index); - st_translate_stream_output_info(stvp->Base.sh.LinkedTransformFeedback, - stvp->result_to_output, - &stvp->tgsi.stream_output); + st_translate_stream_output_info(&stvp->Base); free_glsl_to_tgsi_visitor(stvp->glsl_to_tgsi); } else @@ -1403,41 +1438,6 @@ st_get_fp_variant(struct st_context *st, return fpv; } -/** - * Update stream-output info for GS/TCS/TES. Normally this is done in - * st_translate_program_common() but that is not called for glsl_to_nir - * case. - */ -static void -st_translate_program_stream_output(struct gl_program *prog, - struct pipe_stream_output_info *stream_output) -{ - if (!prog->sh.LinkedTransformFeedback) - return; - - ubyte outputMapping[VARYING_SLOT_TESS_MAX]; - GLuint attr; - uint num_outputs = 0; - - memset(outputMapping, 0, sizeof(outputMapping)); - - /* - * Determine number of outputs, the (default) output register - * mapping and the semantic information for each output. - */ - for (attr = 0; attr < VARYING_SLOT_MAX; attr++) { - if (prog->info.outputs_written & BITFIELD64_BIT(attr)) { - GLuint slot = num_outputs++; - - outputMapping[attr] = slot; - } - } - - st_translate_stream_output_info(prog->sh.LinkedTransformFeedback, - outputMapping, - stream_output); -} - /** * Translate a program. This is common code for geometry and tessellation * shaders. @@ -1452,10 +1452,8 @@ st_translate_common_program(struct st_context *st, st_finalize_nir(st, &stcp->Base, stcp->shader_program, stcp->tgsi.ir.nir); if (stcp->Base.info.stage == MESA_SHADER_TESS_EVAL || - stcp->Base.info.stage == MESA_SHADER_GEOMETRY) { - st_translate_program_stream_output(&stcp->Base, - &stcp->tgsi.stream_output); - } + stcp->Base.info.stage == MESA_SHADER_GEOMETRY) + st_translate_stream_output_info(&stcp->Base); st_store_ir_in_disk_cache(st, &stcp->Base, true); return true; } @@ -1628,9 +1626,7 @@ st_translate_common_program(struct st_context *st, ureg_destroy(ureg); - st_translate_stream_output_info(prog->sh.LinkedTransformFeedback, - outputMapping, - &stcp->tgsi.stream_output); + st_translate_stream_output_info(prog); st_store_ir_in_disk_cache(st, prog, false); diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 874ef211a82..b74eb09280e 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -419,6 +419,9 @@ st_destroy_program_variants(struct st_context *st); extern void st_prepare_vertex_program(struct st_vertex_program *stvp); +extern void +st_translate_stream_output_info(struct gl_program *prog); + extern bool st_translate_vertex_program(struct st_context *st, struct st_vertex_program *stvp);