From: Marek Olšák Date: Sun, 14 Oct 2012 01:53:09 +0000 (+0200) Subject: r600g: cleanup create_sampler_state functions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=33dda8f4fb4298d6c8e04d2b5fe569b56043b28d;p=mesa.git r600g: cleanup create_sampler_state functions - 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 --- diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c index 330c0212a18..baef36731a4 100644 --- a/src/gallium/drivers/r600/evergreen_state.c +++ b/src/gallium/drivers/r600/evergreen_state.c @@ -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; diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h index 578cbbe57d9..d68a06c78b0 100644 --- a/src/gallium/drivers/r600/r600_pipe.h +++ b/src/gallium/drivers/r600/r600_pipe.h @@ -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; }; diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c index 7ae45584a15..b74c11ee2b0 100644 --- a/src/gallium/drivers/r600/r600_state.c +++ b/src/gallium/drivers/r600/r600_state.c @@ -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;