[Mesa-dev] [PATCH 84/92] ac/nir: clamp shadow texture comparison value on VI

Nicolai Hähnle nhaehnle at gmail.com
Mon Jun 26 14:19:13 UTC 2017


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

Needed for TC-compatible HTILE in radeonsi for test cases like
piglit spec/arb_texture_rg/execution/fs-shadow2d-red-01.shader_test
---
 src/amd/common/ac_nir_to_llvm.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index e24ad65..f520e0f 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -4405,21 +4405,33 @@ static void visit_tex(struct ac_nir_context *ctx, nir_tex_instr *instr)
 		address[count++] = pack;
 
 	}
 	/* pack LOD bias value */
 	if (instr->op == nir_texop_txb && bias) {
 		address[count++] = bias;
 	}
 
 	/* Pack depth comparison value */
 	if (instr->is_shadow && comparator) {
-		address[count++] = llvm_extract_elem(&ctx->ac, comparator, 0);
+		LLVMValueRef z = llvm_extract_elem(&ctx->ac, comparator, 0);
+
+		/* TC-compatible HTILE promotes Z16 and Z24 to Z32_FLOAT,
+		 * so the depth comparison value isn't clamped for Z16 and
+		 * Z24 anymore. Do it manually here.
+		 *
+		 * It's unnecessary if the original texture format was
+		 * Z32_FLOAT, but we don't know that here.
+		 */
+		if (ctx->abi->chip_class == VI)
+			z = ac_build_clamp(&ctx->ac, z);
+
+		address[count++] = z;
 	}
 
 	/* pack derivatives */
 	if (ddx || ddy) {
 		switch (instr->sampler_dim) {
 		case GLSL_SAMPLER_DIM_3D:
 		case GLSL_SAMPLER_DIM_CUBE:
 			num_deriv_comp = 3;
 			break;
 		case GLSL_SAMPLER_DIM_2D:
-- 
2.9.3



More information about the mesa-dev mailing list