From 7792ee1c15379d95ccb20ce34352473f2bb2bfbd Mon Sep 17 00:00:00 2001 From: Friedrich Vock Date: Thu, 7 Mar 2024 09:30:00 +0100 Subject: [PATCH] radv/rt: Fix frontface culling with emulated RT We need to preserve the divisor's sign for front/backface detection to work correctly. Cc: mesa-stable Part-of: --- src/amd/vulkan/nir/radv_nir_rt_common.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/amd/vulkan/nir/radv_nir_rt_common.c b/src/amd/vulkan/nir/radv_nir_rt_common.c index e1916111bb4..ce2c60a7a2a 100644 --- a/src/amd/vulkan/nir/radv_nir_rt_common.c +++ b/src/amd/vulkan/nir/radv_nir_rt_common.c @@ -269,11 +269,13 @@ intersect_ray_amd_software_tri(struct radv_device *device, nir_builder *b, nir_d nir_push_if(b, det_cond_front); { - t = nir_f2f32(b, nir_fdiv(b, t, det)); - v = nir_f2f32(b, nir_fdiv(b, v, det)); - w = nir_f2f32(b, nir_fdiv(b, w, det)); + nir_def *det_abs = nir_fabs(b, det); - nir_def *indices[4] = {t, nir_imm_float(b, 1.0), v, w}; + t = nir_f2f32(b, nir_fdiv(b, t, det_abs)); + v = nir_f2f32(b, nir_fdiv(b, v, det_abs)); + w = nir_f2f32(b, nir_fdiv(b, w, det_abs)); + + nir_def *indices[4] = {t, nir_f2f32(b, nir_fsign(b, det)), v, w}; nir_store_var(b, result, nir_vec(b, indices, 4), 0xf); } nir_pop_if(b, NULL);