gallium: add bits for clipping points as tris (d3d-style)
authorRoland Scheidegger <sroland@vmware.com>
Thu, 9 Jan 2014 15:55:22 +0000 (16:55 +0100)
committerRoland Scheidegger <sroland@vmware.com>
Fri, 17 Jan 2014 16:01:01 +0000 (17:01 +0100)
OpenGL does whole-point clipping, that is a large point is either fully
clipped or fully unclipped (the latter means it may extend beyond the
viewport as long as the center is inside the viewport). d3d9 (d3d10 has
no large points) however requires points to be clipped after they are
expanded to a rectangle. (Note some IHVs are known to ignore GL rules at
least with some hw/drivers.)
Hence add a rasterizer bit indicating which way points should be clipped
(some drivers probably will always ignore this), and add the draw interaction
this requires. Drivers wanting to support this and using draw must support
large points on their own as draw doesn't implement vp clipping on the
expanded points (it potentially could but the complexity doesn't seem
warranted), and the driver needs to do viewport scissoring on such points.

Conflicts:

src/gallium/drivers/llvmpipe/lp_context.c
src/gallium/drivers/llvmpipe/lp_state_derived.c

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_context.h
src/gallium/auxiliary/draw/draw_pipe_clip.c
src/gallium/auxiliary/draw/draw_private.h
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
src/gallium/docs/source/cso/rasterizer.rst
src/gallium/drivers/svga/svga_swtnl_draw.c
src/gallium/include/pipe/p_state.h

index 2b3bc0d0ece5884810f2171aca828853905935bb..9b5bcb5a3beba4735d760b2e651c8cd240a4c488 100644 (file)
@@ -262,6 +262,10 @@ static void update_clip_flags( struct draw_context *draw )
                    draw->rasterizer && draw->rasterizer->depth_clip);
    draw->clip_user = draw->rasterizer &&
                      draw->rasterizer->clip_plane_enable != 0;
+   draw->clip_points_xy = draw->clip_xy &&
+                          (!draw->driver.bypass_clip_points ||
+                          (draw->rasterizer &&
+                          !draw->rasterizer->point_tri_clip));
 }
 
 /**
@@ -287,17 +291,23 @@ void draw_set_rasterizer_state( struct draw_context *draw,
  * Some hardware can turn off clipping altogether - in particular any
  * hardware with a TNL unit can do its own clipping, even if it is
  * relying on the draw module for some other reason.
+ * Setting bypass_clip_points to achieve d3d-style point clipping (the driver
+ * will need to do the "vp scissoring") _requires_ the driver to implement
+ * wide points / point sprites itself (points will still be clipped if rasterizer
+ * point_tri_clip isn't set). Only relevant if bypass_clip_xy isn't set.
  */
 void draw_set_driver_clipping( struct draw_context *draw,
                                boolean bypass_clip_xy,
                                boolean bypass_clip_z,
-                               boolean guard_band_xy)
+                               boolean guard_band_xy,
+                               boolean bypass_clip_points)
 {
    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;
+   draw->driver.bypass_clip_points = bypass_clip_points;
    update_clip_flags(draw);
 }
 
index e2e0cb4dad64014886c1c98f26c9a25b60573679..65716c93cccf83cb4266b6fcaac86b8f052053a5 100644 (file)
@@ -263,7 +263,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 guard_band_xy);
+                               boolean guard_band_xy,
+                               boolean bypass_clip_points);
 
 void draw_set_force_passthrough( struct draw_context *draw, 
                                  boolean enable );
index dbb67575843a90513f087fa9a8ade07b2a656685..adfa4b6e8b99021fa54182de228aa1f5bcd0762a 100644 (file)
@@ -609,12 +609,37 @@ do_clip_line( struct draw_stage *stage,
 
 static void
 clip_point( struct draw_stage *stage, 
-           struct prim_header *header )
+            struct prim_header *header )
 {
-   if (header->v[0]->clipmask == 0) 
+   if (header->v[0]->clipmask == 0)
       stage->next->point( stage->next, header );
 }
 
+/*
+ * Clip points but ignore the first 4 (xy) clip planes.
+ * (This is necessary because we don't generate a different shader variant
+ * just for points hence xy clip bits are still generated. This is not really
+ * optimal because of the extra calculations both in generating clip masks
+ * and executing the clip stage but it gets the job done.)
+ */
+static void
+clip_point_no_xy( struct draw_stage *stage,
+                  struct prim_header *header )
+{
+   if ((header->v[0]->clipmask & 0xfffffff0) == 0)
+      stage->next->point( stage->next, header );
+}
+
+
+
+static void
+clip_first_point( struct draw_stage *stage,
+                  struct prim_header *header )
+{
+   stage->point = stage->draw->clip_points_xy ? clip_point : clip_point_no_xy;
+   stage->point(stage, header);
+}
+
 
 static void
 clip_line( struct draw_stage *stage,
@@ -822,7 +847,7 @@ struct draw_stage *draw_clip_stage( struct draw_context *draw )
 
    clipper->stage.draw = draw;
    clipper->stage.name = "clipper";
-   clipper->stage.point = clip_point;
+   clipper->stage.point = clip_first_point;
    clipper->stage.line = clip_first_line;
    clipper->stage.tri = clip_first_tri;
    clipper->stage.flush = clip_flush;
index fbe25a264c5a8f786eb65e604a3f2299fc5f2a90..5bcb8a8add518636e0727af47ed2352e0320c626 100644 (file)
@@ -217,6 +217,7 @@ struct draw_context
       boolean bypass_clip_xy;
       boolean bypass_clip_z;
       boolean guard_band_xy;
+      boolean bypass_clip_points;
    } driver;
 
    boolean quads_always_flatshade_last;
@@ -231,6 +232,7 @@ struct draw_context
    boolean clip_z;
    boolean clip_user;
    boolean guard_band_xy;
+   boolean clip_points_xy;
 
    boolean force_passthrough; /**< never clip or shade */
 
index 8fcc17048d239d3c27c2db99d9e9fb3be5d81535..ab8a0c6ab39330fde1760d27b25f3b2a62b4e958 100644 (file)
@@ -104,7 +104,8 @@ static void fetch_pipeline_prepare( struct draw_pt_middle_end *middle,
                           fpme->vertex_size,
                           instance_id_index );
    draw_pt_post_vs_prepare( fpme->post_vs,
-                            draw->clip_xy,
+                            gs_out_prim == PIPE_PRIM_POINTS ?
+                                           draw->clip_points_xy : draw->clip_xy,
                             draw->clip_z,
                             draw->clip_user,
                             draw->guard_band_xy,
index 846e1d58052e2d9529533e8dc39cc2352e8e662b..bca658f2c05793c0bfa311a0ed60f2899ba41bd5 100644 (file)
@@ -155,7 +155,8 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
 
 
    draw_pt_post_vs_prepare( fpme->post_vs,
-                            draw->clip_xy,
+                            out_prim == PIPE_PRIM_POINTS ?
+                                        draw->clip_points_xy : draw->clip_xy,
                             draw->clip_z,
                             draw->clip_user,
                             draw->guard_band_xy,
index 44e5544cdaabf65827eb1685dae1cab240b6b81e..8d473b8446e000b0ab00c028a7461ef5cbe63ffb 100644 (file)
@@ -200,10 +200,11 @@ point_quad_rasterization
 Determines if points should be rasterized according to quad or point
 rasterization rules.
 
-OpenGL actually has quite different rasterization rules for points and
-point sprites - hence this indicates if points should be rasterized as
-points or according to point sprite (which decomposes them into quads,
-basically) rules.
+(Legacy-only) OpenGL actually has quite different rasterization rules
+for points and point sprites - hence this indicates if points should be
+rasterized as points or according to point sprite (which decomposes them
+into quads, basically) rules. Newer GL versions no longer support the old
+point rules at all.
 
 Additionally Direct3D will always use quad rasterization rules for
 points, regardless of whether point sprites are enabled or not.
@@ -217,6 +218,12 @@ generated.
    Some renderers always internally translate points into quads; this state
    still affects those renderers by overriding other rasterization state.
 
+point_tri_clip
+    Determines if clipping of points should happen after they are converted
+    to "rectangles" (required by d3d) or before (required by OpenGL, though
+    this rule is ignored by some IHVs).
+    It is not valid to set this to enabled but have point_quad_rasterization
+    disabled.
 point_smooth
     Whether points should be smoothed. Point smoothing turns rectangular
     points into circles or ovals.
index 66e4adfdcbe46cb3c3c4fb27a8d5df9eb084bedc..de38d6f59f3663fcdbd2c92dd367df55095ecd3e 100644 (file)
@@ -183,7 +183,7 @@ boolean svga_init_swtnl( struct svga_context *svga )
                                  screen->maxLineWidthAA));
 
    if (debug_get_bool_option("SVGA_SWTNL_FSE", FALSE))
-      draw_set_driver_clipping(svga->swtnl.draw, TRUE, TRUE, TRUE);
+      draw_set_driver_clipping(svga->swtnl.draw, TRUE, TRUE, TRUE, FALSE);
 
    return TRUE;
 
index 1b5f88e3e1d013a1cfa9f9a8839004ba46b6b8e5..1ccf3b07d6c9e2cb52db93248d9ff9f028043849 100644 (file)
@@ -99,6 +99,7 @@ struct pipe_rasterizer_state
    unsigned point_smooth:1;
    unsigned sprite_coord_mode:1;     /**< PIPE_SPRITE_COORD_ */
    unsigned point_quad_rasterization:1; /** points rasterized as quads or points */
+   unsigned point_tri_clip:1; /** large points clipped as tris or points */
    unsigned point_size_per_vertex:1; /**< size computed in vertex shader */
    unsigned multisample:1;         /* XXX maybe more ms state in future */
    unsigned line_smooth:1;