From: Marek Olšák Date: Thu, 28 Mar 2013 00:56:01 +0000 (+0100) Subject: mesa: don't set _ClampFragmentColor to TRUE if it has no effect X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=755648c37fc7a54ed0b11c868fd4c7fe28b2f861;p=mesa.git mesa: don't set _ClampFragmentColor to TRUE if it has no effect This should reduce shader recompilations with drivers that emulate fragment color clamping, because we want the clamping to be enabled only if there is a signed normalized or floating-point colorbuffer. Reviewed-by: Brian Paul --- diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c index 88bf3654c10..15b0dc759cd 100644 --- a/src/mesa/main/blend.c +++ b/src/mesa/main/blend.c @@ -863,7 +863,7 @@ void _mesa_init_color( struct gl_context * ctx ) } ctx->Color.ClampFragmentColor = GL_FIXED_ONLY_ARB; - ctx->Color._ClampFragmentColor = GL_TRUE; + ctx->Color._ClampFragmentColor = GL_FALSE; ctx->Color.ClampReadColor = GL_FIXED_ONLY_ARB; if (ctx->API == API_OPENGLES2) { diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index 67c116163db..fc2b2620bbf 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -785,6 +785,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx, fb->Width = 0; fb->Height = 0; fb->_AllColorBuffersFixedPoint = GL_TRUE; + fb->_HasSNormOrFloatColorBuffer = GL_FALSE; /* Start at -2 to more easily loop over all attachment points. * -2: depth buffer @@ -901,13 +902,17 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx, /* check if integer color */ fb->_IntegerColor = _mesa_is_format_integer_color(attFormat); - /* Update _AllColorBuffersFixedPoint. */ + /* Update _AllColorBuffersFixedPoint and _HasSNormOrFloatColorBuffer. */ if (i >= 0) { GLenum type = _mesa_get_format_datatype(attFormat); fb->_AllColorBuffersFixedPoint = fb->_AllColorBuffersFixedPoint && (type == GL_UNSIGNED_NORMALIZED || type == GL_SIGNED_NORMALIZED); + + fb->_HasSNormOrFloatColorBuffer = + fb->_HasSNormOrFloatColorBuffer || + type == GL_SIGNED_NORMALIZED || type == GL_FLOAT; } /* Error-check width, height, format */ diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c index 5fb36776b45..757c4b055d1 100644 --- a/src/mesa/main/framebuffer.c +++ b/src/mesa/main/framebuffer.c @@ -155,6 +155,7 @@ _mesa_initialize_window_framebuffer(struct gl_framebuffer *fb, fb->Delete = _mesa_destroy_framebuffer; fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT; fb->_AllColorBuffersFixedPoint = !visual->floatMode; + fb->_HasSNormOrFloatColorBuffer = visual->floatMode; compute_depth_max(fb); } diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c index 582ef319806..244e3ead6e7 100644 --- a/src/mesa/main/get.c +++ b/src/mesa/main/get.c @@ -24,6 +24,7 @@ #include "glheader.h" #include "context.h" +#include "blend.h" #include "enable.h" #include "enums.h" #include "extensions.h" @@ -767,13 +768,13 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu break; case GL_FOG_COLOR: - if(ctx->Color._ClampFragmentColor) + if (_mesa_get_clamp_fragment_color(ctx)) COPY_4FV(v->value_float_4, ctx->Fog.Color); else COPY_4FV(v->value_float_4, ctx->Fog.ColorUnclamped); break; case GL_COLOR_CLEAR_VALUE: - if(ctx->Color._ClampFragmentColor) { + if (_mesa_get_clamp_fragment_color(ctx)) { v->value_float_4[0] = CLAMP(ctx->Color.ClearColor.f[0], 0.0F, 1.0F); v->value_float_4[1] = CLAMP(ctx->Color.ClearColor.f[1], 0.0F, 1.0F); v->value_float_4[2] = CLAMP(ctx->Color.ClearColor.f[2], 0.0F, 1.0F); @@ -782,13 +783,13 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu COPY_4FV(v->value_float_4, ctx->Color.ClearColor.f); break; case GL_BLEND_COLOR_EXT: - if(ctx->Color._ClampFragmentColor) + if (_mesa_get_clamp_fragment_color(ctx)) COPY_4FV(v->value_float_4, ctx->Color.BlendColor); else COPY_4FV(v->value_float_4, ctx->Color.BlendColorUnclamped); break; case GL_ALPHA_TEST_REF: - if(ctx->Color._ClampFragmentColor) + if (_mesa_get_clamp_fragment_color(ctx)) v->value_float = ctx->Color.AlphaRef; else v->value_float = ctx->Color.AlphaRefUnclamped; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 40a567620ee..008f68bda08 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2662,6 +2662,7 @@ struct gl_framebuffer /* ARB_color_buffer_float */ GLboolean _AllColorBuffersFixedPoint; /* no integer, no float */ + GLboolean _HasSNormOrFloatColorBuffer; /** Array of all renderbuffer attachments, indexed by BUFFER_* tokens. */ struct gl_renderbuffer_attachment Attachment[BUFFER_COUNT]; diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index c94a2449930..73c5a1c263f 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -314,7 +314,17 @@ update_multisample(struct gl_context *ctx) static void update_clamp_fragment_color(struct gl_context *ctx) { - ctx->Color._ClampFragmentColor = _mesa_get_clamp_fragment_color(ctx); + struct gl_framebuffer *fb = ctx->DrawBuffer; + + /* Don't clamp if: + * - there is no colorbuffer + * - all colorbuffers are unsigned normalized, so clamping has no effect + * - there is an integer colorbuffer + */ + if (!fb || !fb->_HasSNormOrFloatColorBuffer || fb->_IntegerColor) + ctx->Color._ClampFragmentColor = GL_FALSE; + else + ctx->Color._ClampFragmentColor = _mesa_get_clamp_fragment_color(ctx); } diff --git a/src/mesa/main/texenv.c b/src/mesa/main/texenv.c index 0fe5fbd7a64..2979e6706e3 100644 --- a/src/mesa/main/texenv.c +++ b/src/mesa/main/texenv.c @@ -32,6 +32,7 @@ #include "main/glheader.h" #include "main/context.h" +#include "main/blend.h" #include "main/enums.h" #include "main/macros.h" #include "main/mtypes.h" @@ -680,7 +681,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params ) if (pname == GL_TEXTURE_ENV_COLOR) { if(ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP)) _mesa_update_state(ctx); - if(ctx->Color._ClampFragmentColor) + if (_mesa_get_clamp_fragment_color(ctx)) COPY_4FV( params, texUnit->EnvColor ); else COPY_4FV( params, texUnit->EnvColorUnclamped ); diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c index 898eabd3b0d..f60eb204e28 100644 --- a/src/mesa/main/texparam.c +++ b/src/mesa/main/texparam.c @@ -31,6 +31,7 @@ #include #include "main/glheader.h" +#include "main/blend.h" #include "main/colormac.h" #include "main/context.h" #include "main/enums.h" @@ -1415,7 +1416,7 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params ) if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP)) _mesa_update_state_locked(ctx); - if (ctx->Color._ClampFragmentColor) { + if (_mesa_get_clamp_fragment_color(ctx)) { params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F); params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F); params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F); diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c index ccc590dd8c0..09d2a568a0b 100644 --- a/src/mesa/program/prog_statevars.c +++ b/src/mesa/program/prog_statevars.c @@ -31,6 +31,7 @@ #include "main/glheader.h" #include "main/context.h" +#include "main/blend.h" #include "main/imports.h" #include "main/macros.h" #include "main/mtypes.h" @@ -239,14 +240,14 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[], { /* state[1] is the texture unit */ const GLuint unit = (GLuint) state[1]; - if(ctx->Color._ClampFragmentColor) + if (_mesa_get_clamp_fragment_color(ctx)) COPY_4V(value, ctx->Texture.Unit[unit].EnvColor); else COPY_4V(value, ctx->Texture.Unit[unit].EnvColorUnclamped); } return; case STATE_FOG_COLOR: - if(ctx->Color._ClampFragmentColor) + if (_mesa_get_clamp_fragment_color(ctx)) COPY_4V(value, ctx->Fog.Color); else COPY_4V(value, ctx->Fog.ColorUnclamped); diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index 866e5627d7f..62464b4750b 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -227,8 +227,7 @@ static void update_raster_state( struct st_context *st ) /* _NEW_FRAG_CLAMP */ raster->clamp_fragment_color = !st->clamp_frag_color_in_shader && - ctx->Color._ClampFragmentColor && - !ctx->DrawBuffer->_IntegerColor; + ctx->Color._ClampFragmentColor; raster->gl_rasterization_rules = 1; /* _NEW_RASTERIZER_DISCARD */ diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index c1d7c80bb3a..c0239e9297c 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -86,8 +86,7 @@ update_fp( struct st_context *st ) /* _NEW_FRAG_CLAMP */ key.clamp_color = st->clamp_frag_color_in_shader && - st->ctx->Color._ClampFragmentColor && - !st->ctx->DrawBuffer->_IntegerColor; + st->ctx->Color._ClampFragmentColor; st->fp_variant = st_get_fp_variant(st, stfp, &key); diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 05138146ab4..b3ca4050102 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -417,8 +417,7 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z, key.st = st; key.bitmap = GL_TRUE; key.clamp_color = st->clamp_frag_color_in_shader && - st->ctx->Color._ClampFragmentColor && - !st->ctx->DrawBuffer->_IntegerColor; + st->ctx->Color._ClampFragmentColor; fpv = st_get_fp_variant(st, st->fp, &key); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index b25b77629f3..f5a1e27f79b 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -710,8 +710,7 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z, struct pipe_rasterizer_state rasterizer; memset(&rasterizer, 0, sizeof(rasterizer)); rasterizer.clamp_fragment_color = !st->clamp_frag_color_in_shader && - ctx->Color._ClampFragmentColor && - !ctx->DrawBuffer->_IntegerColor; + ctx->Color._ClampFragmentColor; rasterizer.gl_rasterization_rules = 1; rasterizer.depth_clip = !ctx->Transform.DepthClamp; rasterizer.scissor = ctx->Scissor.Enabled; @@ -1037,8 +1036,7 @@ get_color_fp_variant(struct st_context *st) ctx->Pixel.AlphaScale != 1.0); key.pixelMaps = ctx->Pixel.MapColorFlag; key.clamp_color = st->clamp_frag_color_in_shader && - st->ctx->Color._ClampFragmentColor && - !st->ctx->DrawBuffer->_IntegerColor; + st->ctx->Color._ClampFragmentColor; fpv = st_get_fp_variant(st, st->fp, &key);