llvmpipe: abstract the code to set number of subpixel bits
authorZack Rusin <zackr@vmware.com>
Wed, 25 Sep 2013 23:38:33 +0000 (19:38 -0400)
committerZack Rusin <zackr@vmware.com>
Wed, 9 Oct 2013 22:30:31 +0000 (18:30 -0400)
As we're moving towards expanding the number of subpixel
bits and the width of the variables used in the computations
we need to make this code a bit more centralized.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: José Fonseca <jfonseca@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/drivers/llvmpipe/lp_rast.h
src/gallium/drivers/llvmpipe/lp_setup.c
src/gallium/drivers/llvmpipe/lp_setup_tri.c

index c57f2ea11de44574136a5dcf66287b4cad60a5fe..43c598d51177c590f30e83f757e0121c3c34a6c0 100644 (file)
@@ -46,9 +46,18 @@ struct lp_scene;
 struct lp_fence;
 struct cmd_bin;
 
+#define FIXED_TYPE_WIDTH 32
 /** For sub-pixel positioning */
 #define FIXED_ORDER 4
 #define FIXED_ONE (1<<FIXED_ORDER)
+/** Maximum length of an edge in a primitive in pixels.
+ *  If the framebuffer is large we have to think about fixed-point
+ *  integer overflow. Coordinates need ((FIXED_TYPE_WIDTH/2) - 1) bits
+ *  to be able to fit product of two such coordinates inside
+ *  FIXED_TYPE_WIDTH, any larger and we could overflow a
+ *  FIXED_TYPE_WIDTH_-bit int.
+ */
+#define MAX_FIXED_LENGTH (1 << (((FIXED_TYPE_WIDTH/2) - 1) - FIXED_ORDER))
 
 /* Rasterizer output size going to jit fs, width/height */
 #define LP_RASTER_BLOCK_SIZE 4
index c8199b496f915ac89881dff6a6598b08f02386ea..9b277d32ddc82832e85d0b08ce90021dcb87b877 100644 (file)
@@ -1007,16 +1007,12 @@ try_update_scene_state( struct lp_setup_context *setup )
                                          &setup->draw_regions[i]);
          }
       }
-      /* If the framebuffer is large we have to think about fixed-point
-       * integer overflow.  For 2K by 2K images, coordinates need 15 bits
-       * (2^11 + 4 subpixel bits).  The product of two such numbers would
-       * use 30 bits.  Any larger and we could overflow a 32-bit int.
-       *
-       * To cope with this problem we check if triangles are large and
-       * subdivide them if needed.
+      /*
+       * Subdivide triangles if the framebuffer is larger than the
+       * MAX_FIXED_LENGTH.
        */
-      setup->subdivide_large_triangles = (setup->fb.width > 2048 ||
-                                          setup->fb.height > 2048);
+      setup->subdivide_large_triangles = (setup->fb.width > MAX_FIXED_LENGTH ||
+                                          setup->fb.height > MAX_FIXED_LENGTH);
    }
                                       
    setup->dirty = 0;
index 051ffa098609f0135d54a1e21c77f9473de6c8e8..2164f3a1e3cd0e5fd4214ca36328cbba776c46cc 100644 (file)
@@ -988,7 +988,7 @@ check_subdivide_triangle(struct lp_setup_context *setup,
                          const float (*v2)[4],
                          triangle_func_t tri)
 {
-   const float maxLen = 2048.0f;  /* longest permissible edge, in pixels */
+   const float maxLen = (float) MAX_FIXED_LENGTH;  /* longest permissible edge, in pixels */
    float dx10, dy10, len10;
    float dx21, dy21, len21;
    float dx02, dy02, len02;