Module: Mesa
Branch: master
Commit: 023dae71ef219307d168dc34389ba80e48e1a1aa
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=023dae71ef219307d168dc34389ba80e48e1a1aa

Author: Marek Olšák <[email protected]>
Date:   Sun Oct 14 04:12:32 2012 +0200

r600g: emit the border color only when it's needed

That depends on the texture wrap modes and filtering.

---

 src/gallium/drivers/r600/evergreen_state.c   |    3 +--
 src/gallium/drivers/r600/r600_pipe.h         |    1 +
 src/gallium/drivers/r600/r600_state.c        |    3 +--
 src/gallium/drivers/r600/r600_state_common.c |   21 +++++++++++++++++++++
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/r600/evergreen_state.c 
b/src/gallium/drivers/r600/evergreen_state.c
index baef367..3ee125c 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -939,8 +939,7 @@ static void *evergreen_create_sampler_state(struct 
pipe_context *ctx,
                return NULL;
        }
 
-       ss->border_color_use = state->border_color.ui[0] || 
state->border_color.ui[1] ||
-                              state->border_color.ui[2] || 
state->border_color.ui[3];
+       ss->border_color_use = sampler_state_needs_border_color(state);
 
        /* R_03C000_SQ_TEX_SAMPLER_WORD0_0 */
        ss->tex_sampler_words[0] =
diff --git a/src/gallium/drivers/r600/r600_pipe.h 
b/src/gallium/drivers/r600/r600_pipe.h
index d68a06c..2e1d677 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -643,6 +643,7 @@ unsigned r600_tex_wrap(unsigned wrap);
 unsigned r600_tex_filter(unsigned filter);
 unsigned r600_tex_mipfilter(unsigned filter);
 unsigned r600_tex_compare(unsigned compare);
+bool sampler_state_needs_border_color(const struct pipe_sampler_state *state);
 
 /*
  * Helpers for building command buffers
diff --git a/src/gallium/drivers/r600/r600_state.c 
b/src/gallium/drivers/r600/r600_state.c
index b74c11e..7d07008 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -948,8 +948,7 @@ static void *r600_create_sampler_state(struct pipe_context 
*ctx,
        }
 
        ss->seamless_cube_map = state->seamless_cube_map;
-       ss->border_color_use = state->border_color.ui[0] || 
state->border_color.ui[1] ||
-                              state->border_color.ui[2] || 
state->border_color.ui[3];
+       ss->border_color_use = sampler_state_needs_border_color(state);
 
        /* R_03C000_SQ_TEX_SAMPLER_WORD0_0 */
        ss->tex_sampler_words[0] =
diff --git a/src/gallium/drivers/r600/r600_state_common.c 
b/src/gallium/drivers/r600/r600_state_common.c
index ef18f6b..65985c7 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -1523,6 +1523,27 @@ unsigned r600_tex_compare(unsigned compare)
        }
 }
 
+static bool wrap_mode_uses_border_color(unsigned wrap, bool linear_filter)
+{
+       return wrap == PIPE_TEX_WRAP_CLAMP_TO_BORDER ||
+              wrap == PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER ||
+              (linear_filter &&
+               (wrap == PIPE_TEX_WRAP_CLAMP ||
+                wrap == PIPE_TEX_WRAP_MIRROR_CLAMP));
+}
+
+bool sampler_state_needs_border_color(const struct pipe_sampler_state *state)
+{
+       bool linear_filter = state->min_img_filter != PIPE_TEX_FILTER_NEAREST ||
+                            state->mag_img_filter != PIPE_TEX_FILTER_NEAREST;
+
+       return (state->border_color.ui[0] || state->border_color.ui[1] ||
+               state->border_color.ui[2] || state->border_color.ui[3]) &&
+              (wrap_mode_uses_border_color(state->wrap_s, linear_filter) ||
+               wrap_mode_uses_border_color(state->wrap_t, linear_filter) ||
+               wrap_mode_uses_border_color(state->wrap_r, linear_filter));
+}
+
 /* keep this at the end of this file, please */
 void r600_init_common_state_functions(struct r600_context *rctx)
 {

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to