Module: Mesa Branch: main Commit: 15c66adc8a65b61447260cfa012aec81a80e07e0 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=15c66adc8a65b61447260cfa012aec81a80e07e0
Author: Rob Clark <[email protected]> Date: Sat May 20 06:37:32 2023 -0700 mesa: Skip update_gl_clamp() if samplers need clamp update_gl_clamp() was ~12% of drawoverhead -test 40.. this turns it into a no-op when no clamp lowering is needed. Signed-off-by: Rob Clark <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23149> --- src/mesa/main/mtypes.h | 2 ++ src/mesa/main/samplerobj.h | 6 ++++++ src/mesa/state_tracker/st_atom_shader.c | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 386927ac586..dd3f68cf13d 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1323,6 +1323,8 @@ struct gl_texture_attrib /** GL_ARB_seamless_cubemap */ GLboolean CubeMapSeamless; + GLshort NumSamplersWithClamp; + struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS]; struct gl_fixedfunc_texture_unit FixedFuncUnit[MAX_TEXTURE_COORD_UNITS]; }; diff --git a/src/mesa/main/samplerobj.h b/src/mesa/main/samplerobj.h index a716c5dcc3d..eccde38e731 100644 --- a/src/mesa/main/samplerobj.h +++ b/src/mesa/main/samplerobj.h @@ -195,10 +195,16 @@ update_sampler_gl_clamp(struct gl_context *ctx, struct gl_sampler_object *samp, if (cur_state == new_state) return; ctx->NewDriverState |= ctx->DriverFlags.NewSamplersWithClamp; + uint8_t old_mask = samp->glclamp_mask; if (new_state) samp->glclamp_mask |= wrap; else samp->glclamp_mask &= ~wrap; + + if (old_mask && !samp->glclamp_mask) + ctx->Texture.NumSamplersWithClamp--; + else if (samp->glclamp_mask && !old_mask) + ctx->Texture.NumSamplersWithClamp++; } #ifdef __cplusplus } diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 64baede5296..cec6e2b835e 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -79,6 +79,9 @@ update_gl_clamp(struct st_context *st, struct gl_program *prog, uint32_t *gl_cla if (!st->emulate_gl_clamp) return; + if (!st->ctx->Texture.NumSamplersWithClamp) + return; + gl_clamp[0] = gl_clamp[1] = gl_clamp[2] = 0; GLbitfield samplers_used = prog->SamplersUsed; unsigned unit;
