Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / gallium / drivers / llvmpipe / lp_setup_tri.c
index ce3a0a7671629bd67c62a4ed7d257b8ae0b9d6dc..b1671dd0ae275e57a6f38f8f78366e39043448a2 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <emmintrin.h>
 #endif
 
-static INLINE int
+static inline int
 subpixel_snap(float a)
 {
    return util_iround(FIXED_ONE * a);
 }
 
-static INLINE float
+static inline float
 fixed_to_float(int a)
 {
    return a * (1.0f / FIXED_ONE);
@@ -96,7 +96,7 @@ lp_setup_alloc_triangle(struct lp_scene *scene,
                 plane_sz);
 
    tri = lp_scene_alloc_aligned( scene, *tri_size, 16 );
-   if (tri == NULL)
+   if (!tri)
       return NULL;
 
    tri->inputs.stride = input_array_sz;
@@ -276,6 +276,7 @@ do_triangle_ccw(struct lp_setup_context *setup,
    int nr_planes = 3;
    unsigned viewport_index = 0;
    unsigned layer = 0;
+   const float (*pv)[4];
 
    /* Area should always be positive here */
    assert(position->area > 0);
@@ -283,21 +284,28 @@ do_triangle_ccw(struct lp_setup_context *setup,
    if (0)
       lp_setup_print_triangle(setup, v0, v1, v2);
 
-   if (setup->scissor_test) {
-      nr_planes = 7;
-      if (setup->viewport_index_slot > 0) {
-         unsigned *udata = (unsigned*)v0[setup->viewport_index_slot];
-         viewport_index = lp_clamp_viewport_idx(*udata);
-      }
+   if (setup->flatshade_first) {
+      pv = v0;
    }
    else {
-      nr_planes = 3;
+      pv = v2;
+   }
+   if (setup->viewport_index_slot > 0) {
+      unsigned *udata = (unsigned*)pv[setup->viewport_index_slot];
+      viewport_index = lp_clamp_viewport_idx(*udata);
    }
    if (setup->layer_slot > 0) {
-      layer = *(unsigned*)v1[setup->layer_slot];
+      layer = *(unsigned*)pv[setup->layer_slot];
       layer = MIN2(layer, scene->fb_max_layer);
    }
 
+   if (setup->scissor_test) {
+      nr_planes = 7;
+   }
+   else {
+      nr_planes = 3;
+   }
+
    /* Bounding rectangle (in pixels) */
    {
       /* Yes this is necessary to accurately calculate bounding boxes
@@ -305,7 +313,7 @@ do_triangle_ccw(struct lp_setup_context *setup,
        * up needing a bottom-left fill convention, which requires
        * slightly different rounding.
        */
-      int adj = (setup->pixel_offset != 0) ? 1 : 0;
+      int adj = (setup->bottom_edge_rule != 0) ? 1 : 0;
 
       /* Inclusive x0, exclusive x1 */
       bbox.x0 =  MIN3(position->x[0], position->x[1], position->x[2]) >> FIXED_ORDER;
@@ -579,7 +587,7 @@ do_triangle_ccw(struct lp_setup_context *setup,
  *
  * Undefined if no bit set exists, so code should check against 0 first.
  */
-static INLINE uint32_t 
+static inline uint32_t 
 floor_pot(uint32_t n)
 {
 #if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
@@ -760,8 +768,8 @@ lp_setup_bin_triangle( struct lp_setup_context *setup,
             for (i = 0; i < nr_planes; i++) {
                int64_t planeout = cx[i] + eo[i];
                int64_t planepartial = cx[i] + ei[i] - 1;
-               out |= (planeout >> 63);
-               partial |= (planepartial >> 63) & (1<<i);
+               out |= (int) (planeout >> 63);
+               partial |= ((int) (planepartial >> 63)) & (1<<i);
             }
 
             if (out) {
@@ -841,7 +849,7 @@ static void retry_triangle_ccw( struct lp_setup_context *setup,
 /**
  * Calculate fixed position data for a triangle
  */
-static INLINE void
+static inline void
 calc_fixed_position( struct lp_setup_context *setup,
                      struct fixed_position* position,
                      const float (*v0)[4],
@@ -873,7 +881,7 @@ calc_fixed_position( struct lp_setup_context *setup,
  * Rotate a triangle, flipping its clockwise direction,
  * Swaps values for xy[0] and xy[1]
  */
-static INLINE void
+static inline void
 rotate_fixed_position_01( struct fixed_position* position )
 {
    int x, y;
@@ -898,7 +906,7 @@ rotate_fixed_position_01( struct fixed_position* position )
  * Rotate a triangle, flipping its clockwise direction,
  * Swaps values for xy[1] and xy[2]
  */
-static INLINE void
+static inline void
 rotate_fixed_position_12( struct fixed_position* position )
 {
    int x, y;