mesa: Skip update_gl_clamp() if samplers need clamp
authorRob Clark <robdclark@chromium.org>
Sat, 20 May 2023 13:37:32 +0000 (06:37 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 24 May 2023 00:30:49 +0000 (00:30 +0000)
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 <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23149>

src/mesa/main/mtypes.h
src/mesa/main/samplerobj.h
src/mesa/state_tracker/st_atom_shader.c

index 386927a..dd3f68c 100644 (file)
@@ -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];
 };
index a716c5d..eccde38 100644 (file)
@@ -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
 }
index 64baede..cec6e2b 100644 (file)
@@ -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;