[Mesa-dev] [PATCH 18/20] radeonsi: force the DCC enable bit off in image descriptors for writing
Nicolai Hähnle
nhaehnle at gmail.com
Tue Mar 15 18:29:05 UTC 2016
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
This avoids a lockup at least on Tonga.
---
src/gallium/drivers/radeonsi/si_shader.c | 53 +++++++++++++++++++++++++++-----
1 file changed, 45 insertions(+), 8 deletions(-)
diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index 03dc496..37a27a2 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -2764,12 +2764,37 @@ static bool tgsi_is_array_image(unsigned target)
}
/**
+ * Given a 256-bit resource descriptor, force the DCC enable bit to off.
+ *
+ * At least on Tonga, executing image stores on images with DCC enabled and
+ * non-trivial can eventually lead to lockups. This can occur when an
+ * application binds an image as read-only but then uses a shader that writes
+ * to it. The OpenGL spec allows almost arbitrarily bad behavior (including
+ * program termination) in this case, but it doesn't cost much to be a bit
+ * nicer: disabling DCC in the shader still leads to undefined results but
+ * avoids the lockup.
+ */
+static LLVMValueRef force_dcc_off(struct si_shader_context *ctx,
+ LLVMValueRef rsrc)
+{
+ LLVMBuilderRef builder = ctx->radeon_bld.gallivm.builder;
+ LLVMValueRef i32_6 = LLVMConstInt(ctx->i32, 6, 0);
+ LLVMValueRef i32_C = LLVMConstInt(ctx->i32, C_008F28_COMPRESSION_EN, 0);
+ LLVMValueRef tmp;
+
+ tmp = LLVMBuildExtractElement(builder, rsrc, i32_6, "");
+ tmp = LLVMBuildAnd(builder, tmp, i32_C, "");
+ return LLVMBuildInsertElement(builder, rsrc, tmp, i32_6, "");
+}
+
+/**
* Load the resource descriptor for \p image.
*/
static void
image_fetch_rsrc(
struct lp_build_tgsi_context *bld_base,
const struct tgsi_full_src_register *image,
+ bool dcc_off,
LLVMValueRef *rsrc)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
@@ -2783,11 +2808,15 @@ image_fetch_rsrc(
/* Indexing and manual load */
LLVMValueRef ind_index;
LLVMValueRef rsrc_ptr;
+ LLVMValueRef tmp;
ind_index = get_indirect_index(ctx, &image->Indirect, image->Register.Index);
rsrc_ptr = LLVMGetParam(ctx->radeon_bld.main_fn, SI_PARAM_IMAGES);
- *rsrc = build_indexed_load_const(ctx, rsrc_ptr, ind_index);
+ tmp = build_indexed_load_const(ctx, rsrc_ptr, ind_index);
+ if (dcc_off)
+ tmp = force_dcc_off(ctx, tmp);
+ *rsrc = tmp;
}
}
@@ -2897,7 +2926,7 @@ static void load_fetch_args(
emit_data->dst_type = LLVMVectorType(bld_base->base.elem_type, 4);
- image_fetch_rsrc(bld_base, &inst->Src[0], &rsrc);
+ image_fetch_rsrc(bld_base, &inst->Src[0], false, &rsrc);
coords = image_fetch_coords(bld_base, inst, 1);
if (target == TGSI_TEXTURE_BUFFER) {
@@ -2966,7 +2995,6 @@ static void store_fetch_args(
emit_data->dst_type = LLVMVoidTypeInContext(gallivm->context);
image = tgsi_full_src_register_from_dst(&inst->Dst[0]);
- image_fetch_rsrc(bld_base, &image, &rsrc);
coords = image_fetch_coords(bld_base, inst, 0);
for (chan = 0; chan < 4; ++chan) {
@@ -2975,6 +3003,7 @@ static void store_fetch_args(
data = lp_build_gather_values(gallivm, chans, 4);
if (target == TGSI_TEXTURE_BUFFER) {
+ image_fetch_rsrc(bld_base, &image, false, &rsrc);
emit_data->args[0] = data;
emit_data->arg_count = 1;
@@ -2982,7 +3011,7 @@ static void store_fetch_args(
} else {
emit_data->args[0] = data;
emit_data->args[1] = coords;
- emit_data->args[2] = rsrc;
+ image_fetch_rsrc(bld_base, &image, true, &emit_data->args[2]);
emit_data->args[3] = lp_build_const_int32(gallivm, 15); /* dmask */
emit_data->arg_count = 4;
@@ -3037,7 +3066,8 @@ static void atomic_fetch_args(
emit_data->dst_type = bld_base->base.elem_type;
- image_fetch_rsrc(bld_base, &inst->Src[0], &rsrc);
+ image_fetch_rsrc(bld_base, &inst->Src[0], target != TGSI_TEXTURE_BUFFER,
+ &rsrc);
coords = image_fetch_coords(bld_base, inst, 1);
tmp = lp_build_emit_fetch(bld_base, inst, 2, 0);
@@ -3110,11 +3140,11 @@ static void resq_fetch_args(
emit_data->dst_type = LLVMVectorType(bld_base->base.elem_type, 4);
if (tex_target == TGSI_TEXTURE_BUFFER) {
- image_fetch_rsrc(bld_base, reg, &emit_data->args[0]);
+ image_fetch_rsrc(bld_base, reg, false, &emit_data->args[0]);
emit_data->arg_count = 1;
} else {
emit_data->args[0] = bld_base->uint_bld.zero; /* mip level */
- image_fetch_rsrc(bld_base, reg, &emit_data->args[1]);
+ image_fetch_rsrc(bld_base, reg, false, &emit_data->args[1]);
emit_data->args[2] = lp_build_const_int32(gallivm, 15); /* dmask */
emit_data->args[3] = bld_base->uint_bld.zero; /* unorm */
emit_data->args[4] = bld_base->uint_bld.zero; /* r128 */
@@ -4624,6 +4654,7 @@ static void preload_samplers(struct si_shader_context *ctx)
static void preload_images(struct si_shader_context *ctx)
{
struct lp_build_tgsi_context *bld_base = &ctx->radeon_bld.soa.bld_base;
+ struct tgsi_shader_info *info = &ctx->shader->selector->info;
struct gallivm_state *gallivm = bld_base->base.gallivm;
unsigned num_images = bld_base->info->file_max[TGSI_FILE_IMAGE] + 1;
LLVMValueRef res_ptr;
@@ -4636,9 +4667,15 @@ static void preload_images(struct si_shader_context *ctx)
for (i = 0; i < num_images; ++i) {
/* Rely on LLVM to shrink the load for buffer resources. */
- ctx->images[i] =
+ LLVMValueRef rsrc =
build_indexed_load_const(ctx, res_ptr,
lp_build_const_int32(gallivm, i));
+
+ if (info->images_writemask & (1 << i) &&
+ !(info->images_buffers & (1 << i)))
+ rsrc = force_dcc_off(ctx, rsrc);
+
+ ctx->images[i] = rsrc;
}
}
--
2.5.0
More information about the mesa-dev
mailing list