From de2f0b7ce3ac0a82e49e75a0ddd7d34c6f4179ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 26 Jan 2021 01:22:30 -0500 Subject: [PATCH] mesa: inline _mesa_set_draw_vao and set_varying_vp_inputs for draw calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This just moves the functions to draw.c. It's inlined because the function name disappears in the profiler. It improves performance. Reviewed-by: Zoltán Böszörményi Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/draw.c | 77 +++++++++++++++++++++++++++++++++++++++++ src/mesa/main/draw.h | 12 ++++++- src/mesa/main/state.c | 80 +------------------------------------------ src/mesa/main/state.h | 8 ----- 4 files changed, 89 insertions(+), 88 deletions(-) diff --git a/src/mesa/main/draw.c b/src/mesa/main/draw.c index de65a7306dd..455bd081974 100644 --- a/src/mesa/main/draw.c +++ b/src/mesa/main/draw.c @@ -58,6 +58,83 @@ typedef struct { } DrawElementsIndirectCommand; +/** + * Want to figure out which fragment program inputs are actually + * constant/current values from ctx->Current. These should be + * referenced as a tracked state variable rather than a fragment + * program input, to save the overhead of putting a constant value in + * every submitted vertex, transferring it to hardware, interpolating + * it across the triangle, etc... + * + * When there is a VP bound, just use vp->outputs. But when we're + * generating vp from fixed function state, basically want to + * calculate: + * + * vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) | + * potential_vp_outputs ) + * + * Where potential_vp_outputs is calculated by looking at enabled + * texgen, etc. + * + * The generated fragment program should then only declare inputs that + * may vary or otherwise differ from the ctx->Current values. + * Otherwise, the fp should track them as state values instead. + */ +void +_mesa_set_varying_vp_inputs(struct gl_context *ctx, GLbitfield varying_inputs) +{ + if (ctx->VertexProgram._VPModeOptimizesConstantAttribs && + ctx->VertexProgram._VaryingInputs != varying_inputs) { + ctx->VertexProgram._VaryingInputs = varying_inputs; + ctx->NewState |= _NEW_VARYING_VP_INPUTS; + } +} + + +/** + * Set the _DrawVAO and the net enabled arrays. + * The vao->_Enabled bitmask is transformed due to position/generic0 + * as stored in vao->_AttributeMapMode. Then the filter bitmask is applied + * to filter out arrays unwanted for the currently executed draw operation. + * For example, the generic attributes are masked out form the _DrawVAO's + * enabled arrays when a fixed function array draw is executed. + */ +void +_mesa_set_draw_vao(struct gl_context *ctx, struct gl_vertex_array_object *vao, + GLbitfield filter) +{ + struct gl_vertex_array_object **ptr = &ctx->Array._DrawVAO; + bool new_array = false; + if (*ptr != vao) { + _mesa_reference_vao_(ctx, ptr, vao); + + new_array = true; + } + + if (vao->NewArrays) { + _mesa_update_vao_derived_arrays(ctx, vao); + vao->NewArrays = 0; + + new_array = true; + } + + assert(vao->_EnabledWithMapMode == + _mesa_vao_enable_to_vp_inputs(vao->_AttributeMapMode, vao->Enabled)); + + /* Filter out unwanted arrays. */ + const GLbitfield enabled = filter & vao->_EnabledWithMapMode; + if (ctx->Array._DrawVAOEnabledAttribs != enabled) { + ctx->Array._DrawVAOEnabledAttribs = enabled; + new_array = true; + } + + if (new_array) + ctx->NewDriverState |= ctx->DriverFlags.NewArray; + + _mesa_set_varying_vp_inputs(ctx, enabled); +} + + #define MAX_ALLOCA_PRIMS(prim) (50000 / sizeof(*prim)) /* Use calloc for large allocations and alloca for small allocations. */ diff --git a/src/mesa/main/draw.h b/src/mesa/main/draw.h index f8dc1a451ed..11e89272a73 100644 --- a/src/mesa/main/draw.h +++ b/src/mesa/main/draw.h @@ -39,7 +39,7 @@ extern "C" { #endif struct gl_context; - +struct gl_vertex_array_object; struct _mesa_prim { GLubyte mode; /**< GL_POINTS, GL_LINES, GL_QUAD_STRIP, etc */ @@ -77,6 +77,16 @@ struct _mesa_index_buffer }; +void +_mesa_set_varying_vp_inputs(struct gl_context *ctx, GLbitfield varying_inputs); + +/** + * Set the _DrawVAO and the net enabled arrays. + */ +void +_mesa_set_draw_vao(struct gl_context *ctx, struct gl_vertex_array_object *vao, + GLbitfield filter); + void _mesa_draw_gallium_fallback(struct gl_context *ctx, struct pipe_draw_info *info, diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index d5c54c49e0e..2335a08437e 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -544,41 +544,6 @@ _mesa_update_state( struct gl_context *ctx ) } - - -/** - * Want to figure out which fragment program inputs are actually - * constant/current values from ctx->Current. These should be - * referenced as a tracked state variable rather than a fragment - * program input, to save the overhead of putting a constant value in - * every submitted vertex, transferring it to hardware, interpolating - * it across the triangle, etc... - * - * When there is a VP bound, just use vp->outputs. But when we're - * generating vp from fixed function state, basically want to - * calculate: - * - * vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) | - * potential_vp_outputs ) - * - * Where potential_vp_outputs is calculated by looking at enabled - * texgen, etc. - * - * The generated fragment program should then only declare inputs that - * may vary or otherwise differ from the ctx->Current values. - * Otherwise, the fp should track them as state values instead. - */ -static void -set_varying_vp_inputs(struct gl_context *ctx, GLbitfield varying_inputs) -{ - if (ctx->VertexProgram._VPModeOptimizesConstantAttribs && - ctx->VertexProgram._VaryingInputs != varying_inputs) { - ctx->VertexProgram._VaryingInputs = varying_inputs; - ctx->NewState |= _NEW_VARYING_VP_INPUTS; - } -} - - /** * Used by drivers to tell core Mesa that the driver is going to * install/ use its own vertex program. In particular, this will @@ -660,7 +625,7 @@ set_vertex_processing_mode(struct gl_context *ctx, gl_vertex_processing_mode m) * vertex processing mode, we may need to recheck for the * _NEW_VARYING_VP_INPUTS bit. */ - set_varying_vp_inputs(ctx, ctx->Array._DrawVAOEnabledAttribs); + _mesa_set_varying_vp_inputs(ctx, ctx->Array._DrawVAOEnabledAttribs); } @@ -689,46 +654,3 @@ _mesa_reset_vertex_processing_mode(struct gl_context *ctx) ctx->VertexProgram._VPMode = -1; /* force the update */ _mesa_update_vertex_processing_mode(ctx); } - -/** - * Set the _DrawVAO and the net enabled arrays. - * The vao->_Enabled bitmask is transformed due to position/generic0 - * as stored in vao->_AttributeMapMode. Then the filter bitmask is applied - * to filter out arrays unwanted for the currently executed draw operation. - * For example, the generic attributes are masked out form the _DrawVAO's - * enabled arrays when a fixed function array draw is executed. - */ -void -_mesa_set_draw_vao(struct gl_context *ctx, struct gl_vertex_array_object *vao, - GLbitfield filter) -{ - struct gl_vertex_array_object **ptr = &ctx->Array._DrawVAO; - bool new_array = false; - if (*ptr != vao) { - _mesa_reference_vao_(ctx, ptr, vao); - - new_array = true; - } - - if (vao->NewArrays) { - _mesa_update_vao_derived_arrays(ctx, vao); - vao->NewArrays = 0; - - new_array = true; - } - - assert(vao->_EnabledWithMapMode == - _mesa_vao_enable_to_vp_inputs(vao->_AttributeMapMode, vao->Enabled)); - - /* Filter out unwanted arrays. */ - const GLbitfield enabled = filter & vao->_EnabledWithMapMode; - if (ctx->Array._DrawVAOEnabledAttribs != enabled) { - ctx->Array._DrawVAOEnabledAttribs = enabled; - new_array = true; - } - - if (new_array) - ctx->NewDriverState |= ctx->DriverFlags.NewArray; - - set_varying_vp_inputs(ctx, enabled); -} diff --git a/src/mesa/main/state.h b/src/mesa/main/state.h index d9b4584e417..957fd37d320 100644 --- a/src/mesa/main/state.h +++ b/src/mesa/main/state.h @@ -58,14 +58,6 @@ extern void _mesa_reset_vertex_processing_mode(struct gl_context *ctx); -/** - * Set the _DrawVAO and the net enabled arrays. - */ -void -_mesa_set_draw_vao(struct gl_context *ctx, struct gl_vertex_array_object *vao, - GLbitfield filter); - - static inline bool _mesa_ati_fragment_shader_enabled(const struct gl_context *ctx) {