r600g: cleanup create_sampler_state functions
authorMarek Olšák <maraeo@gmail.com>
Sun, 14 Oct 2012 01:53:09 +0000 (03:53 +0200)
committerMarek Olšák <maraeo@gmail.com>
Mon, 15 Oct 2012 14:04:09 +0000 (16:04 +0200)
- stopped using util_color
- reformatted to occupy less characters per line.
- used memcpy for the border color
- used pipe_color_union in the state structure

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

index 330c0212a18d10952ec118b932264d37281e6dda..baef36731a42900baa4eb027382f7d53656a567b 100644 (file)
@@ -933,44 +933,38 @@ static void *evergreen_create_sampler_state(struct pipe_context *ctx,
                                        const struct pipe_sampler_state *state)
 {
        struct r600_pipe_sampler_state *ss = CALLOC_STRUCT(r600_pipe_sampler_state);
-       union util_color uc;
        unsigned aniso_flag_offset = state->max_anisotropy > 1 ? 2 : 0;
 
        if (ss == NULL) {
                return NULL;
        }
 
-       /* directly into sampler avoid r6xx code to emit useless reg */
-       ss->seamless_cube_map = false;
-       util_pack_color(state->border_color.f, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
-       ss->border_color_use = false;
+       ss->border_color_use = state->border_color.ui[0] || state->border_color.ui[1] ||
+                              state->border_color.ui[2] || state->border_color.ui[3];
+
        /* R_03C000_SQ_TEX_SAMPLER_WORD0_0 */
-       ss->tex_sampler_words[0] = S_03C000_CLAMP_X(r600_tex_wrap(state->wrap_s)) |
-                               S_03C000_CLAMP_Y(r600_tex_wrap(state->wrap_t)) |
-                               S_03C000_CLAMP_Z(r600_tex_wrap(state->wrap_r)) |
-                               S_03C000_XY_MAG_FILTER(r600_tex_filter(state->mag_img_filter) | aniso_flag_offset) |
-                               S_03C000_XY_MIN_FILTER(r600_tex_filter(state->min_img_filter) | aniso_flag_offset) |
-                               S_03C000_MIP_FILTER(r600_tex_mipfilter(state->min_mip_filter)) |
-                               S_03C000_MAX_ANISO(r600_tex_aniso_filter(state->max_anisotropy)) |
-                               S_03C000_DEPTH_COMPARE_FUNCTION(r600_tex_compare(state->compare_func)) |
-                               S_03C000_BORDER_COLOR_TYPE(uc.ui ? V_03C000_SQ_TEX_BORDER_COLOR_REGISTER : 0);
+       ss->tex_sampler_words[0] =
+               S_03C000_CLAMP_X(r600_tex_wrap(state->wrap_s)) |
+               S_03C000_CLAMP_Y(r600_tex_wrap(state->wrap_t)) |
+               S_03C000_CLAMP_Z(r600_tex_wrap(state->wrap_r)) |
+               S_03C000_XY_MAG_FILTER(r600_tex_filter(state->mag_img_filter) | aniso_flag_offset) |
+               S_03C000_XY_MIN_FILTER(r600_tex_filter(state->min_img_filter) | aniso_flag_offset) |
+               S_03C000_MIP_FILTER(r600_tex_mipfilter(state->min_mip_filter)) |
+               S_03C000_MAX_ANISO(r600_tex_aniso_filter(state->max_anisotropy)) |
+               S_03C000_DEPTH_COMPARE_FUNCTION(r600_tex_compare(state->compare_func)) |
+               S_03C000_BORDER_COLOR_TYPE(ss->border_color_use ? V_03C000_SQ_TEX_BORDER_COLOR_REGISTER : 0);
        /* R_03C004_SQ_TEX_SAMPLER_WORD1_0 */
-       ss->tex_sampler_words[1] = S_03C004_MIN_LOD(S_FIXED(CLAMP(state->min_lod, 0, 15), 8)) |
-                               S_03C004_MAX_LOD(S_FIXED(CLAMP(state->max_lod, 0, 15), 8));
+       ss->tex_sampler_words[1] =
+               S_03C004_MIN_LOD(S_FIXED(CLAMP(state->min_lod, 0, 15), 8)) |
+               S_03C004_MAX_LOD(S_FIXED(CLAMP(state->max_lod, 0, 15), 8));
        /* R_03C008_SQ_TEX_SAMPLER_WORD2_0 */
-       ss->tex_sampler_words[2] = S_03C008_LOD_BIAS(S_FIXED(CLAMP(state->lod_bias, -16, 16), 8)) |
-                               (state->seamless_cube_map ? 0 : S_03C008_DISABLE_CUBE_WRAP(1)) |
-                               S_03C008_TYPE(1);
-       if (uc.ui) {
-               ss->border_color_use = true;
-               /* R_00A400_TD_PS_SAMPLER0_BORDER_RED */
-               ss->border_color[0] = fui(state->border_color.f[0]);
-               /* R_00A404_TD_PS_SAMPLER0_BORDER_GREEN */
-               ss->border_color[1] = fui(state->border_color.f[1]);
-               /* R_00A408_TD_PS_SAMPLER0_BORDER_BLUE */
-               ss->border_color[2] = fui(state->border_color.f[2]);
-               /* R_00A40C_TD_PS_SAMPLER0_BORDER_ALPHA */
-               ss->border_color[3] = fui(state->border_color.f[3]);
+       ss->tex_sampler_words[2] =
+               S_03C008_LOD_BIAS(S_FIXED(CLAMP(state->lod_bias, -16, 16), 8)) |
+               (state->seamless_cube_map ? 0 : S_03C008_DISABLE_CUBE_WRAP(1)) |
+               S_03C008_TYPE(1);
+
+       if (ss->border_color_use) {
+               memcpy(&ss->border_color, &state->border_color, sizeof(state->border_color));
        }
        return ss;
 }
@@ -2313,7 +2307,7 @@ static void evergreen_emit_sampler_states(struct r600_context *rctx,
                if (rstate->border_color_use) {
                        r600_write_config_reg_seq(cs, border_index_reg, 5);
                        r600_write_value(cs, i);
-                       r600_write_array(cs, 4, rstate->border_color);
+                       r600_write_array(cs, 4, rstate->border_color.ui);
                }
        }
        texinfo->states.dirty_mask = 0;
index 578cbbe57d92a242bd8b91189c485ae1aabf7aac..d68a06c78b078faafe40ee9ea77b40756f12c375 100644 (file)
@@ -264,7 +264,7 @@ struct r600_pipe_shader_selector {
 
 struct r600_pipe_sampler_state {
        uint32_t                        tex_sampler_words[3];
-       uint32_t                        border_color[4];
+       union pipe_color_union          border_color;
        bool                            border_color_use;
        bool                            seamless_cube_map;
 };
index 7ae45584a15a40c2207300854f843dbc8b568ab1..b74c11ee2b0ef5daa3a290cb78d18ae11858004d 100644 (file)
@@ -941,7 +941,6 @@ static void *r600_create_sampler_state(struct pipe_context *ctx,
                                        const struct pipe_sampler_state *state)
 {
        struct r600_pipe_sampler_state *ss = CALLOC_STRUCT(r600_pipe_sampler_state);
-       union util_color uc;
        unsigned aniso_flag_offset = state->max_anisotropy > 1 ? 4 : 0;
 
        if (ss == NULL) {
@@ -949,34 +948,30 @@ static void *r600_create_sampler_state(struct pipe_context *ctx,
        }
 
        ss->seamless_cube_map = state->seamless_cube_map;
-       ss->border_color_use = false;
-       util_pack_color(state->border_color.f, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
+       ss->border_color_use = state->border_color.ui[0] || state->border_color.ui[1] ||
+                              state->border_color.ui[2] || state->border_color.ui[3];
+
        /* R_03C000_SQ_TEX_SAMPLER_WORD0_0 */
-       ss->tex_sampler_words[0] = S_03C000_CLAMP_X(r600_tex_wrap(state->wrap_s)) |
-                               S_03C000_CLAMP_Y(r600_tex_wrap(state->wrap_t)) |
-                               S_03C000_CLAMP_Z(r600_tex_wrap(state->wrap_r)) |
-                               S_03C000_XY_MAG_FILTER(r600_tex_filter(state->mag_img_filter) | aniso_flag_offset) |
-                               S_03C000_XY_MIN_FILTER(r600_tex_filter(state->min_img_filter) | aniso_flag_offset) |
-                               S_03C000_MIP_FILTER(r600_tex_mipfilter(state->min_mip_filter)) |
-                               S_03C000_MAX_ANISO(r600_tex_aniso_filter(state->max_anisotropy)) |
-                               S_03C000_DEPTH_COMPARE_FUNCTION(r600_tex_compare(state->compare_func)) |
-                               S_03C000_BORDER_COLOR_TYPE(uc.ui ? V_03C000_SQ_TEX_BORDER_COLOR_REGISTER : 0);
+       ss->tex_sampler_words[0] =
+               S_03C000_CLAMP_X(r600_tex_wrap(state->wrap_s)) |
+               S_03C000_CLAMP_Y(r600_tex_wrap(state->wrap_t)) |
+               S_03C000_CLAMP_Z(r600_tex_wrap(state->wrap_r)) |
+               S_03C000_XY_MAG_FILTER(r600_tex_filter(state->mag_img_filter) | aniso_flag_offset) |
+               S_03C000_XY_MIN_FILTER(r600_tex_filter(state->min_img_filter) | aniso_flag_offset) |
+               S_03C000_MIP_FILTER(r600_tex_mipfilter(state->min_mip_filter)) |
+               S_03C000_MAX_ANISO(r600_tex_aniso_filter(state->max_anisotropy)) |
+               S_03C000_DEPTH_COMPARE_FUNCTION(r600_tex_compare(state->compare_func)) |
+               S_03C000_BORDER_COLOR_TYPE(ss->border_color_use ? V_03C000_SQ_TEX_BORDER_COLOR_REGISTER : 0);
        /* R_03C004_SQ_TEX_SAMPLER_WORD1_0 */
-       ss->tex_sampler_words[1] = S_03C004_MIN_LOD(S_FIXED(CLAMP(state->min_lod, 0, 15), 6)) |
-                               S_03C004_MAX_LOD(S_FIXED(CLAMP(state->max_lod, 0, 15), 6)) |
-                               S_03C004_LOD_BIAS(S_FIXED(CLAMP(state->lod_bias, -16, 16), 6));
+       ss->tex_sampler_words[1] =
+               S_03C004_MIN_LOD(S_FIXED(CLAMP(state->min_lod, 0, 15), 6)) |
+               S_03C004_MAX_LOD(S_FIXED(CLAMP(state->max_lod, 0, 15), 6)) |
+               S_03C004_LOD_BIAS(S_FIXED(CLAMP(state->lod_bias, -16, 16), 6));
        /* R_03C008_SQ_TEX_SAMPLER_WORD2_0 */
        ss->tex_sampler_words[2] = S_03C008_TYPE(1);
-       if (uc.ui) {
-               ss->border_color_use = true;
-               /* R_00A400_TD_PS_SAMPLER0_BORDER_RED */
-               ss->border_color[0] = fui(state->border_color.f[0]);
-               /* R_00A404_TD_PS_SAMPLER0_BORDER_GREEN */
-               ss->border_color[1] = fui(state->border_color.f[1]);
-               /* R_00A408_TD_PS_SAMPLER0_BORDER_BLUE */
-               ss->border_color[2] = fui(state->border_color.f[2]);
-               /* R_00A40C_TD_PS_SAMPLER0_BORDER_ALPHA */
-               ss->border_color[3] = fui(state->border_color.f[3]);
+
+       if (ss->border_color_use) {
+               memcpy(&ss->border_color, &state->border_color, sizeof(state->border_color));
        }
        return ss;
 }
@@ -2070,7 +2065,7 @@ static void r600_emit_sampler_states(struct r600_context *rctx,
                        offset = border_color_reg;
                        offset += i * 16;
                        r600_write_config_reg_seq(cs, offset, 4);
-                       r600_write_array(cs, 4, rstate->border_color);
+                       r600_write_array(cs, 4, rstate->border_color.ui);
                }
        }
        texinfo->states.dirty_mask = 0;