Mesa (main): llvmpipe/triangle: don't store area in fixed_position.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Feb 4 06:47:13 UTC 2022


Module: Mesa
Branch: main
Commit: c4b400285ac011f337023b13270e02fbb337fc85
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c4b400285ac011f337023b13270e02fbb337fc85

Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Feb  3 14:18:40 2022 +1000

llvmpipe/triangle: don't store area in fixed_position.

It doesn't get used again, just extract the sign and move on.

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14846>

---

 src/gallium/drivers/llvmpipe/lp_setup_tri.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_setup_tri.c b/src/gallium/drivers/llvmpipe/lp_setup_tri.c
index 76c803ae785..89ff598f179 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup_tri.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup_tri.c
@@ -69,7 +69,6 @@ struct fixed_position {
    int32_t dy01;
    int32_t dx20;
    int32_t dy20;
-   int64_t area;
 };
 
 
@@ -285,9 +284,6 @@ do_triangle_ccw(struct lp_setup_context *setup,
    unsigned layer = 0;
    const float (*pv)[4];
 
-   /* Area should always be positive here */
-   assert(position->area > 0);
-
    if (0)
       lp_setup_print_triangle(setup, v0, v1, v2);
 
@@ -1035,7 +1031,7 @@ static inline void retry_triangle_ccw( struct lp_setup_context *setup,
  * calculated in fixed point), as there's quite some code duplication
  * to what is done in the jit setup prog.
  */
-static inline void
+static inline int8_t
 calc_fixed_position(struct lp_setup_context *setup,
                     struct fixed_position* position,
                     const float (*v0)[4],
@@ -1097,8 +1093,9 @@ calc_fixed_position(struct lp_setup_context *setup,
    position->dy20 = position->y[2] - position->y[0];
 #endif
 
-   position->area = IMUL64(position->dx01, position->dy20) -
-         IMUL64(position->dx20, position->dy01);
+   uint64_t area = IMUL64(position->dx01, position->dy20) -
+      IMUL64(position->dx20, position->dy01);
+   return area == 0 ? 0 : (area & (1ULL << 63)) ? -1 : 1;
 }
 
 
@@ -1122,8 +1119,6 @@ rotate_fixed_position_01( struct fixed_position* position )
    position->dy01 = -position->dy01;
    position->dx20 = position->x[2] - position->x[0];
    position->dy20 = position->y[2] - position->y[0];
-
-   position->area = -position->area;
 }
 
 
@@ -1149,8 +1144,6 @@ rotate_fixed_position_12( struct fixed_position* position )
    position->dy01 = -position->dy20;
    position->dx20 = -x;
    position->dy20 = -y;
-
-   position->area = -position->area;
 }
 
 
@@ -1169,9 +1162,9 @@ static void triangle_cw(struct lp_setup_context *setup,
       lp_context->pipeline_statistics.c_primitives++;
    }
 
-   calc_fixed_position(setup, &position, v0, v1, v2);
+   int8_t area_sign = calc_fixed_position(setup, &position, v0, v1, v2);
 
-   if (position.area < 0) {
+   if (area_sign < 0) {
       if (setup->flatshade_first) {
          rotate_fixed_position_12(&position);
          retry_triangle_ccw(setup, &position, v0, v2, v1, !setup->ccw_is_frontface);
@@ -1195,9 +1188,9 @@ static void triangle_ccw(struct lp_setup_context *setup,
       lp_context->pipeline_statistics.c_primitives++;
    }
 
-   calc_fixed_position(setup, &position, v0, v1, v2);
+   int8_t area_sign = calc_fixed_position(setup, &position, v0, v1, v2);
 
-   if (position.area > 0)
+   if (area_sign > 0)
       retry_triangle_ccw(setup, &position, v0, v1, v2, setup->ccw_is_frontface);
 }
 
@@ -1216,7 +1209,7 @@ static void triangle_both(struct lp_setup_context *setup,
       lp_context->pipeline_statistics.c_primitives++;
    }
 
-   calc_fixed_position(setup, &position, v0, v1, v2);
+   int8_t area_sign = calc_fixed_position(setup, &position, v0, v1, v2);
 
    if (0) {
       assert(!util_is_inf_or_nan(v0[0][0]));
@@ -1227,9 +1220,9 @@ static void triangle_both(struct lp_setup_context *setup,
       assert(!util_is_inf_or_nan(v2[0][1]));
    }
 
-   if (position.area > 0)
+   if (area_sign > 0)
       retry_triangle_ccw( setup, &position, v0, v1, v2, setup->ccw_is_frontface );
-   else if (position.area < 0) {
+   else if (area_sign < 0) {
       if (setup->flatshade_first) {
          rotate_fixed_position_12( &position );
          retry_triangle_ccw( setup, &position, v0, v2, v1, !setup->ccw_is_frontface );



More information about the mesa-commit mailing list