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: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
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 @@
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