mesa: optimize set_varying_vp_inputs by precomputing the conditions

set_varying_vp_inputs is called every draw call, which checks
_Maintain*Program. Let's move that checking out of there.

This adds a new flag that determines whether set_varying_vp_inputs
should do anything.

All code that changes _Maintain*Program must now reinitialize the new
flag. This is done by new function _mesa_reset_vertex_processing_mode.

Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8798>
This commit is contained in:
Marek Olšák
2021-01-25 16:47:38 -05:00
committed by Marge Bot
parent 4cea48437d
commit 99e25d183d
9 changed files with 33 additions and 14 deletions

View File

@@ -30,6 +30,7 @@
#include "main/framebuffer.h" #include "main/framebuffer.h"
#include "main/extensions.h" #include "main/extensions.h"
#include "main/macros.h" #include "main/macros.h"
#include "main/state.h"
#include "main/version.h" #include "main/version.h"
#include "main/vtxfmt.h" #include "main/vtxfmt.h"
#include "intel_chipset.h" #include "intel_chipset.h"
@@ -255,6 +256,7 @@ i915CreateContext(int api,
ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumInt; ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumInt;
ctx->FragmentProgram._MaintainTexEnvProgram = true; ctx->FragmentProgram._MaintainTexEnvProgram = true;
_mesa_reset_vertex_processing_mode(ctx);
/* FINISHME: Are there other options that should be enabled for software /* FINISHME: Are there other options that should be enabled for software
* FINISHME: vertex shaders? * FINISHME: vertex shaders?

View File

@@ -1127,6 +1127,7 @@ brwCreateContext(gl_api api,
ctx->VertexProgram._MaintainTnlProgram = true; ctx->VertexProgram._MaintainTnlProgram = true;
ctx->FragmentProgram._MaintainTexEnvProgram = true; ctx->FragmentProgram._MaintainTexEnvProgram = true;
_mesa_reset_vertex_processing_mode(ctx);
brw_draw_init( brw ); brw_draw_init( brw );

View File

@@ -71,6 +71,7 @@
#include "main/framebuffer.h" #include "main/framebuffer.h"
#include "main/macros.h" #include "main/macros.h"
#include "main/renderbuffer.h" #include "main/renderbuffer.h"
#include "main/state.h"
#include "main/teximage.h" #include "main/teximage.h"
#include "main/version.h" #include "main/version.h"
#include "main/vtxfmt.h" #include "main/vtxfmt.h"
@@ -920,6 +921,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
if (0) { if (0) {
mesaCtx->VertexProgram._MaintainTnlProgram = GL_TRUE; mesaCtx->VertexProgram._MaintainTnlProgram = GL_TRUE;
mesaCtx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; mesaCtx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
_mesa_reset_vertex_processing_mode(ctx);
} }
_mesa_enable_sw_extensions(mesaCtx); _mesa_enable_sw_extensions(mesaCtx);

View File

@@ -1247,6 +1247,7 @@ _mesa_initialize_context(struct gl_context *ctx,
if (ctx->VertexProgram._MaintainTnlProgram) { if (ctx->VertexProgram._MaintainTnlProgram) {
/* this is required... */ /* this is required... */
ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
_mesa_reset_vertex_processing_mode(ctx);
} }
/* Mesa core handles all the formats that mesa core knows about. /* Mesa core handles all the formats that mesa core knows about.
@@ -1287,6 +1288,7 @@ _mesa_initialize_context(struct gl_context *ctx,
case API_OPENGLES2: case API_OPENGLES2:
ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
_mesa_reset_vertex_processing_mode(ctx);
break; break;
} }

View File

@@ -2382,6 +2382,8 @@ struct gl_vertex_program_state
GLboolean _Overriden; GLboolean _Overriden;
bool _VPModeOptimizesConstantAttribs;
/** /**
* If we have a vertex program, a TNL program or no program at all. * If we have a vertex program, a TNL program or no program at all.
* Note that this value should be kept up to date all the time, * Note that this value should be kept up to date all the time,

View File

@@ -571,19 +571,8 @@ _mesa_update_state( struct gl_context *ctx )
static void static void
set_varying_vp_inputs(struct gl_context *ctx, GLbitfield varying_inputs) set_varying_vp_inputs(struct gl_context *ctx, GLbitfield varying_inputs)
{ {
/* if (ctx->VertexProgram._VPModeOptimizesConstantAttribs &&
* The gl_context::varying_vp_inputs value is only used when in ctx->varying_vp_inputs != varying_inputs) {
* VP_MODE_FF mode.
*/
if (VP_MODE_FF != ctx->VertexProgram._VPMode)
return;
/* Only fixed-func generated programs ever uses varying_vp_inputs. */
if (!ctx->VertexProgram._MaintainTnlProgram &&
!ctx->FragmentProgram._MaintainTexEnvProgram)
return;
if (ctx->varying_vp_inputs != varying_inputs) {
ctx->varying_vp_inputs = varying_inputs; ctx->varying_vp_inputs = varying_inputs;
ctx->NewState |= _NEW_VARYING_VP_INPUTS; ctx->NewState |= _NEW_VARYING_VP_INPUTS;
} }
@@ -622,6 +611,14 @@ set_vertex_processing_mode(struct gl_context *ctx, gl_vertex_processing_mode m)
/* Finally memorize the value */ /* Finally memorize the value */
ctx->VertexProgram._VPMode = m; ctx->VertexProgram._VPMode = m;
/* The gl_context::varying_vp_inputs value is only used when in
* VP_MODE_FF mode and the fixed-func pipeline is emulated by shaders.
*/
ctx->VertexProgram._VPModeOptimizesConstantAttribs =
m == VP_MODE_FF &&
ctx->VertexProgram._MaintainTnlProgram &&
ctx->FragmentProgram._MaintainTexEnvProgram;
/* Since we only track the varying inputs while being in fixed function /* Since we only track the varying inputs while being in fixed function
* vertex processing mode, we may need to recheck for the * vertex processing mode, we may need to recheck for the
* _NEW_VARYING_VP_INPUTS bit. * _NEW_VARYING_VP_INPUTS bit.
@@ -649,6 +646,13 @@ _mesa_update_vertex_processing_mode(struct gl_context *ctx)
} }
void
_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. * Set the _DrawVAO and the net enabled arrays.
* The vao->_Enabled bitmask is transformed due to position/generic0 * The vao->_Enabled bitmask is transformed due to position/generic0

View File

@@ -54,6 +54,9 @@ _mesa_set_vp_override(struct gl_context *ctx, GLboolean flag);
extern void extern void
_mesa_update_vertex_processing_mode(struct gl_context *ctx); _mesa_update_vertex_processing_mode(struct gl_context *ctx);
extern void
_mesa_reset_vertex_processing_mode(struct gl_context *ctx);
/** /**
* Set the _DrawVAO and the net enabled arrays. * Set the _DrawVAO and the net enabled arrays.

View File

@@ -35,6 +35,7 @@
#include "main/hash.h" #include "main/hash.h"
#include "main/macros.h" #include "main/macros.h"
#include "main/shaderobj.h" #include "main/shaderobj.h"
#include "main/state.h"
#include "program.h" #include "program.h"
#include "prog_cache.h" #include "prog_cache.h"
#include "prog_parameter.h" #include "prog_parameter.h"
@@ -100,7 +101,7 @@ _mesa_init_program(struct gl_context *ctx)
ctx->Shared->DefaultFragmentProgram); ctx->Shared->DefaultFragmentProgram);
assert(ctx->FragmentProgram.Current); assert(ctx->FragmentProgram.Current);
ctx->FragmentProgram.Cache = _mesa_new_program_cache(); ctx->FragmentProgram.Cache = _mesa_new_program_cache();
ctx->VertexProgram._VPMode = VP_MODE_FF; _mesa_reset_vertex_processing_mode(ctx);
/* XXX probably move this stuff */ /* XXX probably move this stuff */
ctx->ATIFragmentShader.Enabled = GL_FALSE; ctx->ATIFragmentShader.Enabled = GL_FALSE;

View File

@@ -33,6 +33,7 @@
#include "main/glthread.h" #include "main/glthread.h"
#include "main/samplerobj.h" #include "main/samplerobj.h"
#include "main/shaderobj.h" #include "main/shaderobj.h"
#include "main/state.h"
#include "main/version.h" #include "main/version.h"
#include "main/vtxfmt.h" #include "main/vtxfmt.h"
#include "main/hash.h" #include "main/hash.h"
@@ -649,6 +650,7 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
*/ */
ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
_mesa_reset_vertex_processing_mode(ctx);
if (no_error) if (no_error)
ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR; ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;