panfrost: Preserve w sign in perspective division
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Fri, 15 Feb 2019 06:38:23 +0000 (06:38 +0000)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 18 Feb 2019 05:13:34 +0000 (05:13 +0000)
This fixes issues where polygons that should be culled (due to negative
w, for instance) may not be.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
src/gallium/drivers/panfrost/midgard/midgard_compile.c

index 6b6a405d963312d83731f4a8166a9bcb0c76c222..cd8412c2dff4f540d2412cea744132ab1dd6e1ea 100644 (file)
@@ -2919,13 +2919,15 @@ write_transformed_position(nir_builder *b, nir_src input_point_src, int uniform_
 
         /* gl_Position will be written out in screenspace xyz, with w set to
          * the reciprocal we computed earlier. The transformed w component is
-         * then used for perspective-correct varying interpolation */
+         * then used for perspective-correct varying interpolation. The
+         * transformed w component must preserve its original sign; this is
+         * used in depth clipping computations */
 
         nir_ssa_def *screen_space = nir_vec4(b,
                                              nir_channel(b, viewport_xy, 0),
                                              nir_channel(b, viewport_xy, 1),
                                              screen_depth,
-                                             nir_fabs(b, w_recip));
+                                             w_recip);
 
         /* Finally, write out the transformed values to the varying */