draw: add support for guard-band clipping
authorBrian Paul <brianp@vmware.com>
Wed, 21 Sep 2011 18:06:17 +0000 (12:06 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 22 Sep 2011 14:26:40 +0000 (08:26 -0600)
src/gallium/auxiliary/draw/draw_cliptest_tmp.h
src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_context.h
src/gallium/auxiliary/draw/draw_private.h
src/gallium/auxiliary/draw/draw_pt.h
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
src/gallium/auxiliary/draw/draw_pt_post_vs.c
src/gallium/drivers/svga/svga_swtnl_draw.c

index 958ed20dc84e9776d852856dcc7686e7cf9812f3..1ca152911ebe623365f9abaf94d0bf138e2406cf 100644 (file)
@@ -47,7 +47,8 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
   
       initialize_vertex_header(out);
 
-      if (flags & (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_HALF_Z | DO_CLIP_USER)) {
+      if (flags & (DO_CLIP_XY | DO_CLIP_XY_GUARD_BAND |
+                   DO_CLIP_FULL_Z | DO_CLIP_HALF_Z | DO_CLIP_USER)) {
          out->clip[0] = position[0];
          out->clip[1] = position[1];
          out->clip[2] = position[2];
@@ -55,7 +56,13 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
 
          /* Do the hardwired planes first:
           */
-         if (flags & DO_CLIP_XY) {
+         if (flags & DO_CLIP_XY_GUARD_BAND) {
+            if (-0.50 * position[0] + position[3] < 0) mask |= (1<<0);
+            if ( 0.50 * position[0] + position[3] < 0) mask |= (1<<1);
+            if (-0.50 * position[1] + position[3] < 0) mask |= (1<<2);
+            if ( 0.50 * position[1] + position[3] < 0) mask |= (1<<3);
+         }
+         else if (flags & DO_CLIP_XY) {
             if (-position[0] + position[3] < 0) mask |= (1<<0);
             if ( position[0] + position[3] < 0) mask |= (1<<1);
             if (-position[1] + position[3] < 0) mask |= (1<<2);
index f8196bb476ffae6e0efffc169848d4f512c23053..b8f8623ee5d818378f5ea5e8bf73acbc97d6c9b2 100644 (file)
@@ -220,6 +220,8 @@ void draw_set_mrd(struct draw_context *draw, double mrd)
 static void update_clip_flags( struct draw_context *draw )
 {
    draw->clip_xy = !draw->driver.bypass_clip_xy;
+   draw->guard_band_xy = (!draw->driver.bypass_clip_xy &&
+                          draw->driver.guard_band_xy);
    draw->clip_z = (!draw->driver.bypass_clip_z &&
                    !draw->depth_clamp);
    draw->clip_user = (draw->nr_planes > 6);
@@ -251,12 +253,14 @@ void draw_set_rasterizer_state( struct draw_context *draw,
  */
 void draw_set_driver_clipping( struct draw_context *draw,
                                boolean bypass_clip_xy,
-                               boolean bypass_clip_z )
+                               boolean bypass_clip_z,
+                               boolean guard_band_xy)
 {
    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
 
    draw->driver.bypass_clip_xy = bypass_clip_xy;
    draw->driver.bypass_clip_z = bypass_clip_z;
+   draw->driver.guard_band_xy = guard_band_xy;
    update_clip_flags(draw);
 }
 
index 5523e44563bfae3a5e6a57aa0867ed1b57b44af7..9a7bf361393c581ae680c44486709b67f5f76eb3 100644 (file)
@@ -230,7 +230,8 @@ void draw_set_render( struct draw_context *draw,
 
 void draw_set_driver_clipping( struct draw_context *draw,
                                boolean bypass_clip_xy,
-                               boolean bypass_clip_z );
+                               boolean bypass_clip_z,
+                               boolean guard_band_xy);
 
 void draw_set_force_passthrough( struct draw_context *draw, 
                                  boolean enable );
index 594ef440092ee82669c24bc92ca40339b2e7ed02..ef772660f7127454a3bc7ec693200ad7c098249e 100644 (file)
@@ -189,6 +189,7 @@ struct draw_context
    struct {
       boolean bypass_clip_xy;
       boolean bypass_clip_z;
+      boolean guard_band_xy;
    } driver;
 
    boolean flushing;         /**< debugging/sanity */
@@ -200,6 +201,7 @@ struct draw_context
    boolean clip_xy;
    boolean clip_z;
    boolean clip_user;
+   boolean guard_band_xy;
 
    boolean force_passthrough; /**< never clip or shade */
 
index 5fbb424291572c2c522f95323e7984132c2851c5..9a45845521af62e6ff4aee129466bbfbb3319249 100644 (file)
@@ -224,6 +224,7 @@ void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
                              boolean clip_xy,
                              boolean clip_z,
                              boolean clip_user,
+                              boolean guard_band,
                              boolean bypass_viewport,
                              boolean opengl,
                              boolean need_edgeflags );
index b72fd612451d3da9b9840b6b3a894e5bebd04c75..27420f06798a826123fbb7e41b46ef60eef72481 100644 (file)
@@ -103,6 +103,7 @@ static void fetch_pipeline_prepare( struct draw_pt_middle_end *middle,
                            draw->clip_xy,
                            draw->clip_z,
                            draw->clip_user,
+                            draw->guard_band_xy,
                            draw->identity_viewport,
                            (boolean)draw->rasterizer->gl_rasterization_rules,
                            (draw->vs.edgeflag_output ? TRUE : FALSE) );
index 2e3afb22c4867d0359d6cb11219ae894f946ba4c..ac839682331e7016a687bbfa07dc1d3a04818477 100644 (file)
@@ -110,6 +110,7 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
                            draw->clip_xy,
                            draw->clip_z,
                            draw->clip_user,
+                            draw->guard_band_xy,
                            draw->identity_viewport,
                            (boolean)draw->rasterizer->gl_rasterization_rules,
                            (draw->vs.edgeflag_output ? TRUE : FALSE) );
index 769409cfd67d180855f33c153fa624e26dba8a5b..a8d65fd5d7b60df2cf87f6ff080bfd14ba870604 100644 (file)
@@ -39,6 +39,7 @@
 #define DO_CLIP_USER         0x8
 #define DO_VIEWPORT          0x10
 #define DO_EDGEFLAG          0x20
+#define DO_CLIP_XY_GUARD_BAND 0x40
 
 
 struct pt_post_vs {
@@ -80,6 +81,10 @@ dot4(const float *a, const float *b)
 #define TAG(x) x##_xy_halfz_viewport
 #include "draw_cliptest_tmp.h"
 
+#define FLAGS (DO_CLIP_XY_GUARD_BAND | DO_CLIP_HALF_Z | DO_VIEWPORT)
+#define TAG(x) x##_xy_gb_halfz_viewport
+#include "draw_cliptest_tmp.h"
+
 #define FLAGS (DO_CLIP_FULL_Z | DO_VIEWPORT)
 #define TAG(x) x##_fullz_viewport
 #include "draw_cliptest_tmp.h"
@@ -120,15 +125,33 @@ void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
                              boolean clip_xy,
                              boolean clip_z,
                               boolean clip_user,
+                              boolean guard_band,
                              boolean bypass_viewport,
                              boolean opengl,
                              boolean need_edgeflags )
 {
    pvs->flags = 0;
 
-   if (clip_xy)
+   /* This combination not currently tested/in use:
+    */
+   if (opengl)
+      guard_band = FALSE;
+
+   if (clip_xy && !guard_band) {
       pvs->flags |= DO_CLIP_XY;
-   
+      ASSIGN_4V( pvs->draw->plane[0], -1,  0,  0, 1 );
+      ASSIGN_4V( pvs->draw->plane[1],  1,  0,  0, 1 );
+      ASSIGN_4V( pvs->draw->plane[2],  0, -1,  0, 1 );
+      ASSIGN_4V( pvs->draw->plane[3],  0,  1,  0, 1 );
+   }
+   else if (clip_xy && guard_band) {
+      pvs->flags |= DO_CLIP_XY_GUARD_BAND;
+      ASSIGN_4V( pvs->draw->plane[0], -0.5,  0,  0, 1 );
+      ASSIGN_4V( pvs->draw->plane[1],  0.5,  0,  0, 1 );
+      ASSIGN_4V( pvs->draw->plane[2],  0, -0.5,  0, 1 );
+      ASSIGN_4V( pvs->draw->plane[3],  0,  0.5,  0, 1 );
+   }
+
    if (clip_z && opengl) {
       pvs->flags |= DO_CLIP_FULL_Z;
       ASSIGN_4V( pvs->draw->plane[4],  0,  0,  1, 1 );
@@ -163,6 +186,10 @@ void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
       pvs->run = do_cliptest_xy_halfz_viewport;
       break;
 
+   case DO_CLIP_XY_GUARD_BAND | DO_CLIP_HALF_Z | DO_VIEWPORT:
+      pvs->run = do_cliptest_xy_gb_halfz_viewport;
+      break;
+
    case DO_CLIP_FULL_Z | DO_VIEWPORT:
       pvs->run = do_cliptest_fullz_viewport;
       break;
index ad29c1b6425232aa6910627b06f1848c9567b2ae..3bf1886194a306926d40164ff453ddfef4e3805f 100644 (file)
@@ -156,7 +156,7 @@ boolean svga_init_swtnl( struct svga_context *svga )
    draw_install_pstipple_stage(svga->swtnl.draw, &svga->pipe);
 
    if (debug_get_bool_option("SVGA_SWTNL_FSE", FALSE))
-      draw_set_driver_clipping(svga->swtnl.draw, TRUE, TRUE);
+      draw_set_driver_clipping(svga->swtnl.draw, TRUE, TRUE, TRUE);
 
    return TRUE;