From a1337c027cd4c8afd2454286eee7e9a04850b485 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Thu, 12 Mar 2020 09:36:24 +0100 Subject: [PATCH] v3dv: work around viewport Z scale hardware bug It looks like when the Z scale is small enough the hardware clipper won't work properly. Fixes: dEQP-VK.draw.inverted_depth_ranges.nodepthclamp_deltazero Part-of: --- src/broadcom/vulkan/v3dv_cmd_buffer.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c index 511dceb..b064665 100644 --- a/src/broadcom/vulkan/v3dv_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c @@ -1734,6 +1734,17 @@ v3dv_viewport_compute_xform(const VkViewport *viewport, scale[2] = (f - n); translate[2] = n; + + /* It seems that if the scale is small enough the hardware won't clip + * correctly so we work around this my choosing the smallest scale that + * seems to work. + * + * This case is exercised by CTS: + * dEQP-VK.draw.inverted_depth_ranges.nodepthclamp_deltazero + */ + const float min_abs_scale = 0.000009f; + if (fabs(scale[2]) < min_abs_scale) + scale[2] = min_abs_scale * (scale[2] < 0 ? -1.0f : 1.0f); } void -- 2.7.4