draw: improve numerical stability in clipper
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 13 Aug 2021 12:08:58 +0000 (14:08 +0200)
committerMarge Bot <eric+marge@anholt.net>
Fri, 20 Aug 2021 09:26:41 +0000 (09:26 +0000)
Floats have much better precision close to zero than close to one, so
let's make sure we compute an interpolation factor that goes in the
direction that discards the fewest bits.

This makes a big difference when interpolating from very small to very
large values for screen-space positions.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12355>

src/gallium/auxiliary/draw/draw_pipe_clip.c
src/gallium/drivers/i915/ci/deqp-i915-g33-fails.txt
src/gallium/drivers/i915/ci/traces-i915.yml
src/gallium/drivers/llvmpipe/ci/deqp-llvmpipe-fails.txt
src/gallium/drivers/llvmpipe/ci/traces-llvmpipe.yml
src/gallium/drivers/softpipe/ci/deqp-softpipe-fails.txt
src/gallium/drivers/virgl/ci/deqp-virgl-gl-fails.txt
src/gallium/drivers/virgl/ci/deqp-virgl-gles-fails.txt
src/gallium/drivers/virgl/ci/traces-virgl.yml
src/gallium/drivers/zink/ci/deqp-zink-lvp-fails.txt

index 2a9c944..d341fee 100644 (file)
@@ -469,12 +469,18 @@ do_clip_tri(struct draw_stage *stage,
             new_edge = &outEdges[outcount];
             outlist[outcount++] = new_vert;
 
+            float denom = dp - dp_prev;
             if (dp < 0.0f) {
                /* Going out of bounds.  Avoid division by zero as we
                 * know dp != dp_prev from different_sign, above.
                 */
-               float t = dp / (dp - dp_prev);
-               interp( clipper, new_vert, t, vert, vert_prev, viewport_index );
+               if (-dp < dp_prev) {
+                  float t = dp / denom;
+                  interp( clipper, new_vert, t, vert, vert_prev, viewport_index );
+               } else {
+                  float t = -dp_prev / denom;
+                  interp( clipper, new_vert, t, vert_prev, vert, viewport_index );
+               }
 
                /* Whether or not to set edge flag for the new vert depends
                 * on whether it's a user-defined clipping plane.  We're
@@ -494,8 +500,13 @@ do_clip_tri(struct draw_stage *stage,
             else {
                /* Coming back in.
                 */
-               float t = dp_prev / (dp_prev - dp);
-               interp( clipper, new_vert, t, vert_prev, vert, viewport_index );
+               if (-dp_prev < dp) {
+                  float t = -dp_prev / denom;
+                  interp( clipper, new_vert, t, vert_prev, vert, viewport_index );
+               } else {
+                  float t = dp / denom;
+                  interp( clipper, new_vert, t, vert, vert_prev, viewport_index );
+               }
 
                /* Copy starting vert's edgeflag:
                 */
index a4622a5..5db672f 100644 (file)
@@ -22,10 +22,6 @@ dEQP-GLES2.functional.clipping.point.wide_point_clip,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip_viewport_center,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip_viewport_corner,Fail
 
-# Minor deviations in the position of a clipped triangle.
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_pos_y_pos_z_and_neg_x_neg_y_neg_z,Fail
-
 # " // GL_INVALID_OPERATION returned
 #   // ERROR: expected GL_INVALID_VALUE"
 # Mesa: User error: GL_INVALID_OPERATION in glUniformMatrix(non-matrix uniform)
index 819a659..da9fded 100644 (file)
@@ -41,7 +41,7 @@ traces:
   - path: humus/Portals.trace
     expectations:
       - device: i915-g33
-        checksum: 9306a8d9f37d83a327759319c46f7cae
+        checksum: 4cb0eb98c89c4d7ff962a25cc7931d8c
   # The shadow raytracing shader fails to compile
   #- path: humus/RaytracedShadows.trace
   #  expectations:
@@ -55,9 +55,9 @@ traces:
   - path: neverball/neverball.trace
     expectations:
       - device: i915-g33
-        checksum: 344479e929ad4bc7f7316b5e574b0131
+        checksum: bb7f4ddd30c36418a94ad8f02fc6bd09
   - path: valve/counterstrike-v2.trace
     # Tree foliage rendering is extra aliased.
     expectations:
       - device: i915-g33
-        checksum: 66a18e91b95674a3a1d227ed5681257d
+        checksum: 837c0aabe5d6bf75a071a3fa45cf448f
index 4bbd9a6..68c4c47 100644 (file)
@@ -10,7 +10,6 @@ dEQP-EGL.functional.robustness.reset_context.shaders.infinite_loop.sync_status.v
 dEQP-EGL.functional.robustness.reset_context.shaders.infinite_loop.sync_status.vertex_and_fragment,Fail
 dEQP-GLES2.functional.clipping.line.wide_line_clip_viewport_center,Fail
 dEQP-GLES2.functional.clipping.line.wide_line_clip_viewport_corner,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
 dEQP-GLES2.functional.polygon_offset.default_displacement_with_units,Fail
 dEQP-GLES2.functional.rasterization.interpolation.basic.line_loop_wide,Fail
 dEQP-GLES2.functional.rasterization.interpolation.basic.line_strip_wide,Fail
@@ -20,7 +19,6 @@ dEQP-GLES2.functional.rasterization.interpolation.projected.line_strip_wide,Fail
 dEQP-GLES2.functional.rasterization.interpolation.projected.lines_wide,Fail
 dEQP-GLES3.functional.clipping.line.wide_line_clip_viewport_center,Fail
 dEQP-GLES3.functional.clipping.line.wide_line_clip_viewport_corner,Fail
-dEQP-GLES3.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag_reverse_dst_x,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag_reverse_src_dst_x,Fail
index c2ccf84..ff9e0a7 100644 (file)
@@ -17,7 +17,7 @@ traces:
   - path: 0ad/0ad.trace
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: 7f45f21eefb76b4a35506cd6a47040ad
+        checksum: de926f73d0f11c7da4bfec20d332bfc4
   - path: pathfinder/demo.trace
     expectations:
       - device: gl-vmware-llvmpipe
@@ -45,7 +45,7 @@ traces:
   - path: humus/Portals.trace
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: c4a0f928e0cedf91726728e7fd5d9759
+        checksum: a55dd3d87a86b3b47121ff67861028c3
   - path: bgfx/01-cubes.rdc
     expectations:
       - device: gl-vmware-llvmpipe
@@ -69,7 +69,7 @@ traces:
   - path: bgfx/06-bump.rdc
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: 75a8ac1b7bbcba03a93159243ade2c83
+        checksum: ff0626714d1eccff7f3a730933794af1
   - path: bgfx/07-callback.rdc
     expectations:
       - device: gl-vmware-llvmpipe
@@ -97,7 +97,7 @@ traces:
   - path: bgfx/14-shadowvolumes.rdc
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: 66f789a7c813945e43e59c187fba1d19
+        checksum: 0f4d6a65e591afbe5652517d9b80430f
   - path: bgfx/15-shadowmaps-simple.rdc
     expectations:
       - device: gl-vmware-llvmpipe
@@ -105,11 +105,11 @@ traces:
   - path: bgfx/16-shadowmaps.rdc
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: 4b1942b6c218c83de66687782f2cfd3b
+        checksum: 8418c344d4a92400f522efb7473e4afc
   - path: bgfx/18-ibl.rdc
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: 8b7be0c59b4be560dba4ca7583ed1130
+        checksum: 1f4d62805d9ecc086289e0701dc5139b
   - path: bgfx/19-oit.rdc
     expectations:
       - device: gl-vmware-llvmpipe
@@ -129,7 +129,7 @@ traces:
   - path: bgfx/28-wireframe.rdc
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: 3aebd4eb89f6e68b84852f7556d5c1d9
+        checksum: 56294c5582e142728cf36a65561697a6
   - path: bgfx/29-debugdraw.rdc
     expectations:
       - device: gl-vmware-llvmpipe
@@ -137,7 +137,7 @@ traces:
   - path: bgfx/31-rsm.rdc
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: 559e9fabc82a7979599ab1153700f018
+        checksum: c54bb845285639c212546027a462e5c9
   - path: bgfx/32-particles.rdc
     expectations:
       - device: gl-vmware-llvmpipe
@@ -157,11 +157,11 @@ traces:
   - path: bgfx/36-sky.rdc
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: 9971a794fe1b12fc21b8655ccb3b6bac
+        checksum: 74cbe4687e773208306636a8fb6be999
   - path: bgfx/37-gpudrivenrendering.rdc
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: a778dbf1d7c8bff9d68ae53a74cec467
+        checksum: 05ba4526c8eaf3cfb06755a5d9a5cb7c
   - path: bgfx/38-bloom.rdc
     expectations:
       - device: gl-vmware-llvmpipe
@@ -169,7 +169,7 @@ traces:
   - path: bgfx/39-assao.rdc
     expectations:
       - device: gl-vmware-llvmpipe
-        checksum: 74b3570d73241fa0798afb0869e5b121
+        checksum: 5b59de4721efe2979b4ab1d48fdee64c
   - path: bgfx/40-svt.rdc
     expectations:
       - device: gl-vmware-llvmpipe
index 87778af..81848c7 100644 (file)
@@ -3,8 +3,6 @@ dEQP-GLES2.functional.clipping.line.wide_line_clip_viewport_corner,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip_viewport_center,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip_viewport_corner,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_pos_y_pos_z_and_neg_x_neg_y_neg_z,Fail
 dEQP-GLES2.functional.polygon_offset.default_displacement_with_units,Fail
 dEQP-GLES2.functional.polygon_offset.fixed16_displacement_with_units,Fail
 dEQP-GLES2.functional.rasterization.interpolation.basic.line_loop_wide,Fail
@@ -19,8 +17,6 @@ dEQP-GLES3.functional.clipping.line.wide_line_clip_viewport_corner,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip_viewport_center,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip_viewport_corner,Fail
-dEQP-GLES3.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
-dEQP-GLES3.functional.clipping.triangle_vertex.clip_two.clip_pos_y_pos_z_and_neg_x_neg_y_neg_z,Fail
 dEQP-GLES3.functional.draw.random.124,Fail
 dEQP-GLES3.functional.fbo.depth.depth_test_clamp.depth24_stencil8,Fail
 dEQP-GLES3.functional.fbo.depth.depth_test_clamp.depth32f_stencil8,Fail
index e315117..14918d8 100644 (file)
@@ -3,8 +3,6 @@ dEQP-GLES2.functional.clipping.line.wide_line_clip_viewport_corner,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip_viewport_center,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip_viewport_corner,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_pos_y_pos_z_and_neg_x_neg_y_neg_z,Fail
 dEQP-GLES2.functional.polygon_offset.default_displacement_with_units,Fail
 dEQP-GLES2.functional.rasterization.interpolation.basic.line_loop_wide,Fail
 dEQP-GLES2.functional.rasterization.interpolation.basic.line_strip_wide,Fail
@@ -17,8 +15,6 @@ dEQP-GLES3.functional.clipping.line.wide_line_clip_viewport_corner,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip_viewport_center,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip_viewport_corner,Fail
-dEQP-GLES3.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
-dEQP-GLES3.functional.clipping.triangle_vertex.clip_two.clip_pos_y_pos_z_and_neg_x_neg_y_neg_z,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag_reverse_dst_x,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag_reverse_src_dst_x,Fail
index 002a1cd..cf0ddaa 100644 (file)
@@ -3,8 +3,6 @@ dEQP-GLES2.functional.clipping.line.wide_line_clip_viewport_corner,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip_viewport_center,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip_viewport_corner,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_pos_y_pos_z_and_neg_x_neg_y_neg_z,Fail
 dEQP-GLES2.functional.polygon_offset.default_displacement_with_units,Fail
 dEQP-GLES2.functional.rasterization.interpolation.basic.line_loop_wide,Fail
 dEQP-GLES2.functional.rasterization.interpolation.basic.line_strip_wide,Fail
@@ -17,8 +15,6 @@ dEQP-GLES3.functional.clipping.line.wide_line_clip_viewport_corner,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip_viewport_center,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip_viewport_corner,Fail
-dEQP-GLES3.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
-dEQP-GLES3.functional.clipping.triangle_vertex.clip_two.clip_pos_y_pos_z_and_neg_x_neg_y_neg_z,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag_reverse_dst_x,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag_reverse_src_dst_x,Fail
index 1857ec0..baef5ec 100644 (file)
@@ -29,11 +29,11 @@ traces:
   - path: humus/Portals.trace
     expectations:
       - device: gl-virgl
-        checksum: 6d78eed6749f01cc5625dec0ad129c66
+        checksum: 846df7d54649319dec1b68b371633cd1
   - path: 0ad/0ad.trace
     expectations:
       - device: gl-virgl
-        checksum: 03145ecd597dca6aaf5e113b99687278
+        checksum: 3975d6d29509ec21a11a0cf88e3467b2
   - path: glmark2/buffer:update-fraction=0.5:update-dispersion=0.9:columns=200:update-method=map:interleave=false.trace
     expectations:
       - device: gl-virgl
@@ -188,7 +188,7 @@ traces:
   - path: humus/AmbientAperture.trace
     expectations:
       - device: gl-virgl
-        checksum: d5635a3660405651a572b5efc6107827
+        checksum: 66db5d53d261b8cc7b0e9b7463f3911d
   - path: humus/CelShading.trace
     expectations:
       - device: gl-virgl
@@ -197,19 +197,19 @@ traces:
     expectations:
       # speckling present on the ground that isn't there on other drivers.
       - device: gl-virgl
-        checksum: 45f7f54972d196c173763f77082393bb
+        checksum: 4b7fea4ad77981b0e214299bbfe1214e
   - path: humus/HDR.trace
     expectations:
       - device: gl-virgl
-        checksum: c04b8feeb0d41763db0c636373d3ba4e
+        checksum: 110d70e58b9b4ec392071312e690429d
   - path: humus/RaytracedShadows.trace
     expectations:
       - device: gl-virgl
-        checksum: a0d3b811a34033465441776d7115462c
+        checksum: c1fa10c98b2120dae6356ad76d237c99
   - path: humus/VolumetricFogging2.trace
     expectations:
       - device: gl-virgl
-        checksum: 6260e5d1e7e6fc050d48e6a1790c6117
+        checksum: a6e3bc45fa4090a307d431d63036ca33
 # Crash
 #  - path: itoral-gl-terrain-demo/demo.trace
 #    expectations:
@@ -218,7 +218,7 @@ traces:
   - path: neverball/neverball.trace
     expectations:
       - device: gl-virgl
-        checksum: 4ad035fd572792648c82903e0c3b87ed
+        checksum: 92ca4c422ca4aca917ffcc8a874a2c69
 # Crash
 #  - path: pathfinder/canvas_moire.trace
 #    expectations:
@@ -237,7 +237,7 @@ traces:
   - path: supertuxkart/supertuxkart-mansion-egl-gles.trace
     expectations:
       - device: gl-virgl
-        checksum: 0e93531dfb9d18941904ff1f49581ea0
+        checksum: 54847eaf8a2f1b6b45cc323be67417d3
 # Sometimes crashes
 #  - path: xonotic/xonotic-keybench-high.trace
 #    expectations:
@@ -246,7 +246,7 @@ traces:
   - path: valve/counterstrike.trace
     expectations:
       - device: gl-virgl
-        checksum: 7f3ae17190d74da032d9a463c738404a
+        checksum: 405faea80fdc58c511b939891ba478c6
 # Piglit times-out when trying to run these two
 #  - path: valve/counterstrike-source.trace
 #    expectations:
@@ -259,7 +259,7 @@ traces:
   - path: valve/portal-2.trace
     expectations:
       - device: gl-virgl
-        checksum: adf249c3d2ee204ef6583641f70816db
+        checksum: ba556c810d4eb2a9efa9e44e150e7e19
 # Piglit crashes when trying to run this one
 #  - path: supertuxkart/supertuxkart-antediluvian-abyss.rdc
 #    expectations:
index 3a8736c..a8fd68f 100644 (file)
@@ -1,9 +1,6 @@
 dEQP-GLES2.functional.clipping.point.wide_point_clip,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip_viewport_center,Fail
 dEQP-GLES2.functional.clipping.point.wide_point_clip_viewport_corner,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_three.clip_pos_x_and_neg_y_neg_z_and_pos_y_pos_z,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
-dEQP-GLES2.functional.clipping.triangle_vertex.clip_two.clip_pos_y_pos_z_and_neg_x_neg_y_neg_z,Fail
 dEQP-GLES2.functional.polygon_offset.default_displacement_with_units,Fail
 dEQP-GLES3.functional.polygon_offset.default_displacement_with_units,Fail
 dEQP-GLES3.functional.polygon_offset.float32_displacement_with_units,Fail
@@ -12,8 +9,6 @@ dEQP-GLES3.functional.clipping.line.wide_line_clip_viewport_corner,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip_viewport_center,Fail
 dEQP-GLES3.functional.clipping.point.wide_point_clip_viewport_corner,Fail
-dEQP-GLES3.functional.clipping.triangle_vertex.clip_two.clip_neg_y_neg_z_and_neg_x_neg_y_pos_z,Fail
-dEQP-GLES3.functional.clipping.triangle_vertex.clip_two.clip_pos_y_pos_z_and_neg_x_neg_y_neg_z,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag_reverse_dst_x,Fail
 dEQP-GLES3.functional.fbo.blit.rect.nearest_consistency_mag_reverse_src_dst_x,Fail