r600g: emit the border color only when it's needed
authorMarek Olšák <maraeo@gmail.com>
Sun, 14 Oct 2012 02:12:32 +0000 (04:12 +0200)
committerMarek Olšák <maraeo@gmail.com>
Mon, 15 Oct 2012 14:04:09 +0000 (16:04 +0200)
That depends on the texture wrap modes and filtering.

src/gallium/drivers/r600/evergreen_state.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_state.c
src/gallium/drivers/r600/r600_state_common.c

index baef36731a42900baa4eb027382f7d53656a567b..3ee125c82090b4d467a5fe31aec2d276489dea13 100644 (file)
@@ -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] =
index d68a06c78b078faafe40ee9ea77b40756f12c375..2e1d677c79e798ef53e2bf06a5e8dbd65ee0bb25 100644 (file)
@@ -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
index b74c11ee2b0ef5daa3a290cb78d18ae11858004d..7d07008f16d5af10e7662da146a769142a599666 100644 (file)
@@ -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] =
index ef18f6bcea265c11c28682a0ed7a75d2078a283c..65985c7653db77811227a1e9fa9ac7e2e6db2a06 100644 (file)
@@ -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)
 {