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 <brianp@vmware.com>
This commit is contained in:
parent
21d407c1b8
commit
755648c37f
|
@ -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) {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue