[Mesa-stable] [PATCH 2/5] amd/common: round cube array slice in ac_prepare_cube_coords

Nicolai Hähnle nhaehnle at gmail.com
Wed Sep 13 17:04:31 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

The NIR-to-LLVM pass already does this; now the same fix covers
radeonsi as well.

Fixes various tests of
dEQP-GLES31.functional.texture.filtering.cube_array.combinations.*

Cc: mesa-stable at lists.freedesktop.org
---
 src/amd/common/ac_llvm_build.c                    | 7 ++++++-
 src/amd/common/ac_llvm_build.h                    | 2 +-
 src/amd/common/ac_nir_to_llvm.c                   | 4 +---
 src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c | 1 +
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index a831baed3f5..7193b80be59 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -477,30 +477,35 @@ static void build_cube_select(LLVMBuilderRef builder,
 	/* Select ma */
 	tmp = LLVMBuildSelect(builder, is_ma_z, coords[2],
 		LLVMBuildSelect(builder, is_ma_y, coords[1], coords[0], ""), "");
 	sgn = LLVMBuildSelect(builder, is_ma_positive,
 		LLVMConstReal(f32, 2.0), LLVMConstReal(f32, -2.0), "");
 	*out_ma = LLVMBuildFMul(builder, tmp, sgn, "");
 }
 
 void
 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
-		       bool is_deriv, bool is_array,
+		       bool is_deriv, bool is_array, bool is_lod,
 		       LLVMValueRef *coords_arg,
 		       LLVMValueRef *derivs_arg)
 {
 
 	LLVMBuilderRef builder = ctx->builder;
 	struct cube_selection_coords selcoords;
 	LLVMValueRef coords[3];
 	LLVMValueRef invma;
 
+	if (is_array && !is_lod) {
+		coords_arg[3] = ac_build_intrinsic(ctx, "llvm.rint.f32", ctx->f32,
+						   &coords_arg[3], 1, 0);
+	}
+
 	build_cube_intrinsic(ctx, coords_arg, &selcoords);
 
 	invma = ac_build_intrinsic(ctx, "llvm.fabs.f32",
 			ctx->f32, &selcoords.ma, 1, AC_FUNC_ATTR_READNONE);
 	invma = ac_build_fdiv(ctx, LLVMConstReal(ctx->f32, 1.0), invma);
 
 	for (int i = 0; i < 2; ++i)
 		coords[i] = LLVMBuildFMul(builder, selcoords.stc[i], invma, "");
 
 	coords[2] = selcoords.id;
diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h
index dae32e45752..14ec03f5c84 100644
--- a/src/amd/common/ac_llvm_build.h
+++ b/src/amd/common/ac_llvm_build.h
@@ -103,21 +103,21 @@ ac_build_gather_values(struct ac_llvm_context *ctx,
 		       LLVMValueRef *values,
 		       unsigned value_count);
 
 LLVMValueRef
 ac_build_fdiv(struct ac_llvm_context *ctx,
 	      LLVMValueRef num,
 	      LLVMValueRef den);
 
 void
 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
-		       bool is_deriv, bool is_array,
+		       bool is_deriv, bool is_array, bool is_lod,
 		       LLVMValueRef *coords_arg,
 		       LLVMValueRef *derivs_arg);
 
 
 LLVMValueRef
 ac_build_fs_interp(struct ac_llvm_context *ctx,
 		   LLVMValueRef llvm_chan,
 		   LLVMValueRef attr_number,
 		   LLVMValueRef params,
 		   LLVMValueRef i,
diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index 1388ebd998b..8b0d0ec23e8 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -4542,29 +4542,27 @@ static void visit_tex(struct ac_nir_context *ctx, nir_tex_instr *instr)
 			derivs[i] = ac_to_float(&ctx->ac, llvm_extract_elem(&ctx->ac, ddx, i));
 			derivs[num_dest_deriv_channels + i] = ac_to_float(&ctx->ac, llvm_extract_elem(&ctx->ac, ddy, i));
 		}
 		for (unsigned i = num_src_deriv_channels; i < num_dest_deriv_channels; i++) {
 			derivs[i] = ctx->ac.f32_0;
 			derivs[num_dest_deriv_channels + i] = ctx->ac.f32_0;
 		}
 	}
 
 	if (instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE && coord) {
-		if (instr->is_array && instr->op != nir_texop_lod)
-			coords[3] = apply_round_slice(&ctx->ac, coords[3]);
 		for (chan = 0; chan < instr->coord_components; chan++)
 			coords[chan] = ac_to_float(&ctx->ac, coords[chan]);
 		if (instr->coord_components == 3)
 			coords[3] = LLVMGetUndef(ctx->ac.f32);
 		ac_prepare_cube_coords(&ctx->ac,
 			instr->op == nir_texop_txd, instr->is_array,
-			coords, derivs);
+			instr->op == nir_texop_lod, coords, derivs);
 		if (num_deriv_comp)
 			num_deriv_comp--;
 	}
 
 	if (ddx || ddy) {
 		for (unsigned i = 0; i < num_deriv_comp * 2; i++)
 			address[count++] = derivs[i];
 	}
 
 	/* Pack texture coordinates */
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
index a09ebed23d2..e6467f9654a 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
@@ -1465,20 +1465,21 @@ static void tex_fetch_args(
 	}
 
 	if (target == TGSI_TEXTURE_CUBE ||
 	    target == TGSI_TEXTURE_CUBE_ARRAY ||
 	    target == TGSI_TEXTURE_SHADOWCUBE ||
 	    target == TGSI_TEXTURE_SHADOWCUBE_ARRAY)
 		ac_prepare_cube_coords(&ctx->ac,
 				       opcode == TGSI_OPCODE_TXD,
 				       target == TGSI_TEXTURE_CUBE_ARRAY ||
 				       target == TGSI_TEXTURE_SHADOWCUBE_ARRAY,
+				       opcode == TGSI_OPCODE_LODQ,
 				       coords, derivs);
 
 	if (opcode == TGSI_OPCODE_TXD)
 		for (int i = 0; i < num_deriv_channels * 2; i++)
 			address[count++] = derivs[i];
 
 	/* Pack texture coordinates */
 	address[count++] = coords[0];
 	if (num_coords > 1)
 		address[count++] = coords[1];
-- 
2.11.0



More information about the mesa-stable mailing list