[Mesa-dev] [PATCH] i965/fs: Don't emit saturates to do UNORM color clamping.

Eric Anholt eric at anholt.net
Fri Mar 21 14:01:24 PDT 2014


Kenneth Graunke <kenneth at whitecape.org> writes:

> Traditionally, we've implemented fragment color clamping by emitting
> "mov.sat" in the fragment shader's final color write code, clamping
> the output to [0, 1] prior to blending.  (When clamping is off, we
> use a regular "mov".)  This means we have to recompile based on the
> GL_CLAMP_FRAGMENT_COLOR state, and because GL_FIXED_ONLY is an option,
> we need to consider the render target format.

> ---
>  src/mesa/drivers/dri/i965/brw_fs.cpp | 2 --
>  src/mesa/drivers/dri/i965/brw_wm.c   | 3 ++-
>  2 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
> index 1b32d63..bd44952 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
> @@ -3616,8 +3616,6 @@ brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
>                                           BRW_FS_VARYING_INPUT_MASK) > 16)
>        key.input_slots_valid = fp->Base.InputsRead | VARYING_BIT_POS;
>  
> -   key.clamp_fragment_color = ctx->API == API_OPENGL_COMPAT;
> -
>     unsigned sampler_count = _mesa_fls(fp->Base.SamplersUsed);
>     for (unsigned i = 0; i < sampler_count; i++) {
>        if (fp->Base.ShadowSamplers & (1 << i)) {
> diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
> index 0d0d6ec..baf001f 100644
> --- a/src/mesa/drivers/dri/i965/brw_wm.c
> +++ b/src/mesa/drivers/dri/i965/brw_wm.c
> @@ -488,7 +488,8 @@ static void brw_wm_populate_key( struct brw_context *brw,
>     key->flat_shade = (ctx->Light.ShadeModel == GL_FLAT);
>  
>     /* _NEW_FRAG_CLAMP | _NEW_BUFFERS */
> -   key->clamp_fragment_color = ctx->Color._ClampFragmentColor;
> +   key->clamp_fragment_color = ctx->Color._ClampFragmentColor &&
> +                               ctx->DrawBuffer->_HasSNormOrFloatColorBuffer;
>  
>     /* _NEW_TEXTURE */
>     brw_populate_sampler_prog_key_data(ctx, prog, brw->wm.base.sampler_count,

Given Roland's note about how _ClampFragmentColor is set, I think we
only need the brw_fs.cpp hunk and not the brw_wm.c hunk.  For just the
one hunk,

Reviewed-by: Eric Anholt <eric at anholt.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140321/98d56249/attachment.sig>


More information about the mesa-dev mailing list