diff options
author | Jerome Glisse <[email protected]> | 2012-08-01 15:53:11 -0400 |
---|---|---|
committer | Jerome Glisse <[email protected]> | 2012-08-06 12:04:55 -0400 |
commit | 2df399c34bb39122a45bdd5b430b48346542e1cb (patch) | |
tree | 032ccdbe4de6827e56b35e03e4a272771f8d8e32 /src/gallium/drivers/r600/evergreen_state.c | |
parent | d3f8000bfcffdbe54c8e89626ce60ebedeba5920 (diff) |
r600g: atomize sampler state v2
Use atom for sampler state. Does not provide new functionality
or fix any bug. Just a step toward full atom base r600g.
v2: Split seamless on r6xx/r7xx into it's own atom. Make sure it's
emited after sampler and with a pipeline flush before otherwise
it does not take effect.
Signed-off-by: Jerome Glisse <[email protected]>
Diffstat (limited to 'src/gallium/drivers/r600/evergreen_state.c')
-rw-r--r-- | src/gallium/drivers/r600/evergreen_state.c | 136 |
1 files changed, 73 insertions, 63 deletions
diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c index 340036c647c..67ae7d3c04c 100644 --- a/src/gallium/drivers/r600/evergreen_state.c +++ b/src/gallium/drivers/r600/evergreen_state.c @@ -911,43 +911,47 @@ static void *evergreen_create_rs_state(struct pipe_context *ctx, static void *evergreen_create_sampler_state(struct pipe_context *ctx, const struct pipe_sampler_state *state) { - struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_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 (rstate == NULL) { + if (ss == NULL) { return NULL; } - rstate->id = R600_PIPE_STATE_SAMPLER; + /* 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); - r600_pipe_state_add_reg_noblock(rstate, R_03C000_SQ_TEX_SAMPLER_WORD0_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), NULL, 0); - r600_pipe_state_add_reg_noblock(rstate, R_03C004_SQ_TEX_SAMPLER_WORD1_0, - 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)), - NULL, 0); - r600_pipe_state_add_reg_noblock(rstate, R_03C008_SQ_TEX_SAMPLER_WORD2_0, - 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), - NULL, 0); - + ss->border_color_use = false; + /* 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); + /* 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)); + /* 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) { - r600_pipe_state_add_reg_noblock(rstate, R_00A404_TD_PS_SAMPLER0_BORDER_RED, fui(state->border_color.f[0]), NULL, 0); - r600_pipe_state_add_reg_noblock(rstate, R_00A408_TD_PS_SAMPLER0_BORDER_GREEN, fui(state->border_color.f[1]), NULL, 0); - r600_pipe_state_add_reg_noblock(rstate, R_00A40C_TD_PS_SAMPLER0_BORDER_BLUE, fui(state->border_color.f[2]), NULL, 0); - r600_pipe_state_add_reg_noblock(rstate, R_00A410_TD_PS_SAMPLER0_BORDER_ALPHA, fui(state->border_color.f[3]), NULL, 0); - } - return rstate; + 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]); + } + return ss; } static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_context *ctx, @@ -1092,37 +1096,6 @@ static void evergreen_set_ps_sampler_views(struct pipe_context *ctx, unsigned co r600_set_sampler_views(rctx, &rctx->ps_samplers, count, views); } -static void evergreen_bind_samplers(struct r600_context *rctx, - struct r600_textures_info *dst, - unsigned count, void **states, - void (*set_sampler)(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id)) -{ - struct r600_pipe_sampler_state **rstates = (struct r600_pipe_sampler_state**)states; - - for (int i = 0; i < count; i++) { - if (rstates[i] != dst->samplers[i]) { - set_sampler(rctx, &rstates[i]->rstate, i); - } - } - - memcpy(dst->samplers, states, sizeof(void*) * count); - dst->n_samplers = count; -} - -static void evergreen_bind_ps_samplers(struct pipe_context *ctx, unsigned count, void **states) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - evergreen_bind_samplers(rctx, &rctx->ps_samplers, count, states, - evergreen_context_pipe_state_set_ps_sampler); -} - -static void evergreen_bind_vs_samplers(struct pipe_context *ctx, unsigned count, void **states) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - evergreen_bind_samplers(rctx, &rctx->vs_samplers, count, states, - evergreen_context_pipe_state_set_vs_sampler); -} - static void evergreen_set_clip_state(struct pipe_context *ctx, const struct pipe_clip_state *state) { @@ -1822,6 +1795,41 @@ static void evergreen_emit_ps_sampler_views(struct r600_context *rctx, struct r6 evergreen_emit_sampler_views(rctx, &rctx->ps_samplers.views, R600_MAX_CONST_BUFFERS); } +static void evergreen_emit_sampler(struct r600_context *rctx, + struct r600_textures_info *texinfo, + unsigned resource_id_base, + unsigned border_index_reg) +{ + struct radeon_winsys_cs *cs = rctx->cs; + unsigned i; + + for (i = 0; i < texinfo->n_samplers; i++) { + + if (texinfo->samplers[i] == NULL) { + continue; + } + r600_write_value(cs, PKT3(PKT3_SET_SAMPLER, 3, 0)); + r600_write_value(cs, (resource_id_base + i) * 3); + r600_write_array(cs, 3, texinfo->samplers[i]->tex_sampler_words); + + if (texinfo->samplers[i]->border_color_use) { + r600_write_config_reg_seq(cs, border_index_reg, 5); + r600_write_value(cs, i); + r600_write_array(cs, 4, texinfo->samplers[i]->border_color); + } + } +} + +static void evergreen_emit_vs_sampler(struct r600_context *rctx, struct r600_atom *atom) +{ + evergreen_emit_sampler(rctx, &rctx->vs_samplers, 18, R_00A414_TD_VS_SAMPLER0_BORDER_INDEX); +} + +static void evergreen_emit_ps_sampler(struct r600_context *rctx, struct r600_atom *atom) +{ + evergreen_emit_sampler(rctx, &rctx->ps_samplers, 0, R_00A400_TD_PS_SAMPLER0_BORDER_INDEX); +} + void evergreen_init_state_functions(struct r600_context *rctx) { r600_init_atom(&rctx->cb_misc_state.atom, evergreen_emit_cb_misc_state, 0, 0); @@ -1835,6 +1843,8 @@ void evergreen_init_state_functions(struct r600_context *rctx) r600_init_atom(&rctx->vs_samplers.views.atom, evergreen_emit_vs_sampler_views, 0, 0); r600_init_atom(&rctx->ps_samplers.views.atom, evergreen_emit_ps_sampler_views, 0, 0); r600_init_atom(&rctx->cs_shader_state.atom, evergreen_emit_cs_shader, 0, 0); + r600_init_atom(&rctx->vs_samplers.atom_sampler, evergreen_emit_vs_sampler, 0, 0); + r600_init_atom(&rctx->ps_samplers.atom_sampler, evergreen_emit_ps_sampler, 0, 0); rctx->context.create_blend_state = evergreen_create_blend_state; rctx->context.create_depth_stencil_alpha_state = evergreen_create_dsa_state; @@ -1846,17 +1856,17 @@ void evergreen_init_state_functions(struct r600_context *rctx) rctx->context.create_vs_state = r600_create_shader_state_vs; rctx->context.bind_blend_state = r600_bind_blend_state; rctx->context.bind_depth_stencil_alpha_state = r600_bind_dsa_state; - rctx->context.bind_fragment_sampler_states = evergreen_bind_ps_samplers; + rctx->context.bind_fragment_sampler_states = r600_bind_ps_samplers; rctx->context.bind_fs_state = r600_bind_ps_shader; rctx->context.bind_rasterizer_state = r600_bind_rs_state; rctx->context.bind_vertex_elements_state = r600_bind_vertex_elements; - rctx->context.bind_vertex_sampler_states = evergreen_bind_vs_samplers; + rctx->context.bind_vertex_sampler_states = r600_bind_vs_samplers; rctx->context.bind_vs_state = r600_bind_vs_shader; rctx->context.delete_blend_state = r600_delete_state; rctx->context.delete_depth_stencil_alpha_state = r600_delete_state; rctx->context.delete_fs_state = r600_delete_ps_shader; rctx->context.delete_rasterizer_state = r600_delete_rs_state; - rctx->context.delete_sampler_state = r600_delete_state; + rctx->context.delete_sampler_state = r600_delete_sampler; rctx->context.delete_vertex_elements_state = r600_delete_vertex_element; rctx->context.delete_vs_state = r600_delete_vs_shader; rctx->context.set_blend_color = r600_set_blend_color; |