From: Marek Olšák Date: Wed, 18 Sep 2013 13:40:21 +0000 (+0200) Subject: radeonsi: simplify and fix MSAA texture sampling for array textures X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d2bd63433a252c84488023e9877e70d69223da42;p=mesa.git radeonsi: simplify and fix MSAA texture sampling for array textures Reviewed-by: Michel Dänzer --- diff --git a/src/gallium/drivers/radeonsi/radeonsi_shader.c b/src/gallium/drivers/radeonsi/radeonsi_shader.c index 7e3ac5a7520..8d8cc4da8ec 100644 --- a/src/gallium/drivers/radeonsi/radeonsi_shader.c +++ b/src/gallium/drivers/radeonsi/radeonsi_shader.c @@ -1172,8 +1172,6 @@ static void tex_fetch_args( unsigned sampler_src, sampler_index; LLVMValueRef coords[4]; LLVMValueRef address[16]; - LLVMValueRef sample_index_rewrite = NULL; - LLVMValueRef sample_chan = NULL; int ref_pos; unsigned num_coords = tgsi_util_get_texture_coord_dim(target, &ref_pos); unsigned count = 0; @@ -1233,7 +1231,7 @@ static void tex_fetch_args( if (num_coords > 2) address[count++] = coords[2]; - /* Pack LOD */ + /* Pack LOD or sample index */ if (opcode == TGSI_OPCODE_TXL || opcode == TGSI_OPCODE_TXF) address[count++] = coords[3]; @@ -1270,10 +1268,15 @@ static void tex_fetch_args( target == TGSI_TEXTURE_2D_ARRAY_MSAA) { struct lp_build_context *uint_bld = &bld_base->uint_bld; struct lp_build_emit_data txf_emit_data = *emit_data; - LLVMValueRef txf_address[16]; + LLVMValueRef txf_address[4]; unsigned txf_count = count; - memcpy(txf_address, address, sizeof(address)); + memcpy(txf_address, address, sizeof(txf_address)); + + if (target == TGSI_TEXTURE_2D_MSAA) { + txf_address[2] = bld_base->uint_bld.zero; + } + txf_address[3] = bld_base->uint_bld.zero; /* Pad to a power-of-two size. */ while (txf_count < util_next_power_of_two(txf_count)) @@ -1285,18 +1288,13 @@ static void tex_fetch_args( LLVMInt32TypeInContext(bld_base->base.gallivm->context), 4); txf_emit_data.args[0] = lp_build_gather_values(gallivm, txf_address, txf_count); txf_emit_data.args[1] = si_shader_ctx->resources[FMASK_TEX_OFFSET + sampler_index]; - txf_emit_data.args[2] = lp_build_const_int32(bld_base->base.gallivm, target); + txf_emit_data.args[2] = lp_build_const_int32(bld_base->base.gallivm, + target == TGSI_TEXTURE_2D_MSAA ? TGSI_TEXTURE_2D : TGSI_TEXTURE_2D_ARRAY); txf_emit_data.arg_count = 3; build_tex_intrinsic(&txf_action, bld_base, &txf_emit_data); /* Initialize some constants. */ - if (target == TGSI_TEXTURE_2D_MSAA) { - sample_chan = LLVMConstInt(uint_bld->elem_type, 2, 0); - } else { - sample_chan = LLVMConstInt(uint_bld->elem_type, 3, 0); - } - LLVMValueRef four = LLVMConstInt(uint_bld->elem_type, 4, 0); LLVMValueRef F = LLVMConstInt(uint_bld->elem_type, 0xF, 0); @@ -1306,13 +1304,10 @@ static void tex_fetch_args( txf_emit_data.output[0], uint_bld->zero, ""); - LLVMValueRef sample_index = - LLVMBuildExtractElement(gallivm->builder, - txf_emit_data.args[0], - sample_chan, ""); + unsigned sample_chan = target == TGSI_TEXTURE_2D_MSAA ? 2 : 3; LLVMValueRef sample_index4 = - LLVMBuildMul(gallivm->builder, sample_index, four, ""); + LLVMBuildMul(gallivm->builder, address[sample_chan], four, ""); LLVMValueRef shifted_fmask = LLVMBuildLShr(gallivm->builder, fmask, sample_index4, ""); @@ -1336,9 +1331,10 @@ static void tex_fetch_args( LLVMBuildICmp(gallivm->builder, LLVMIntNE, fmask_word1, uint_bld->zero, ""); - sample_index_rewrite = + /* Replace the MSAA sample index. */ + address[sample_chan] = LLVMBuildSelect(gallivm->builder, word1_is_nonzero, - final_sample, sample_index, ""); + final_sample, address[sample_chan], ""); } /* Resource */ @@ -1405,13 +1401,6 @@ static void tex_fetch_args( address[count++] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context)); emit_data->args[0] = lp_build_gather_values(gallivm, address, count); - - /* Replace the MSAA sample index if needed. */ - if (sample_index_rewrite) { - emit_data->args[0] = - LLVMBuildInsertElement(gallivm->builder, emit_data->args[0], - sample_index_rewrite, sample_chan, ""); - } } static void build_tex_intrinsic(const struct lp_build_tgsi_action * action, diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index e1b4e32b6d5..8f7edafcf35 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -2758,7 +2758,8 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx S_008F1C_DST_SEL_W(V_008F1C_SQ_SEL_X) | S_008F1C_TILING_INDEX(tmp->fmask.tile_mode_index) | S_008F1C_TYPE(si_tex_dim(texture->target, 0)); - view->fmask_state[4] = S_008F20_PITCH(tmp->fmask.pitch - 1); + view->fmask_state[4] = S_008F20_DEPTH(depth - 1) | + S_008F20_PITCH(tmp->fmask.pitch - 1); view->fmask_state[5] = S_008F24_BASE_ARRAY(state->u.tex.first_layer) | S_008F24_LAST_ARRAY(state->u.tex.last_layer); view->fmask_state[6] = 0;