gallium: clean up point sprite rasterizer state
authorRoland Scheidegger <sroland@vmware.com>
Wed, 3 Feb 2010 16:25:14 +0000 (17:25 +0100)
committerRoland Scheidegger <sroland@vmware.com>
Wed, 3 Feb 2010 16:25:14 +0000 (17:25 +0100)
Don't need sprite coord origin per coord.
Also, don't need separate sprite enable bit - if all coords have it diabled,
then there are no point sprites (technically, there's a distinction in pre-GL3,
but it only differs in having more leniency in clamping to max size, something
the state tracker would need to handle and the hardware won't bother anyway).
Also, use packed field for the per-coord enables.
All in all, should save 3 dwords in rasterizer state (from 10 down to 7).

18 files changed:
src/gallium/auxiliary/draw/draw_pipe_validate.c
src/gallium/auxiliary/draw/draw_pipe_wide_point.c
src/gallium/docs/source/cso/rasterizer.rst
src/gallium/drivers/i965/brw_sf.c
src/gallium/drivers/i965/brw_sf_state.c
src/gallium/drivers/nv10/nv10_state.c
src/gallium/drivers/nv20/nv20_state.c
src/gallium/drivers/nv30/nv30_state.c
src/gallium/drivers/nv40/nv40_state.c
src/gallium/drivers/nv50/nv50_program.c
src/gallium/drivers/nv50/nv50_state.c
src/gallium/drivers/softpipe/sp_video_context.c
src/gallium/drivers/svga/svga_pipe_rasterizer.c
src/gallium/drivers/trace/tr_dump_state.c
src/gallium/include/pipe/p_defines.h
src/gallium/include/pipe/p_state.h
src/gallium/state_trackers/python/retrace/interpreter.py
src/mesa/state_tracker/st_atom_rasterizer.c

index bea90e50d30cd91eee9e00ff292e9806a908f182..ac29634d67713ff238bc724b1e9d287bb423d55e 100644 (file)
@@ -105,7 +105,7 @@ draw_need_pipeline(const struct draw_context *draw,
          return TRUE;
 
       /* point sprites */
-      if (rasterizer->point_sprite && draw->pipeline.point_sprite)
+      if (rasterizer->sprite_coord_enable && draw->pipeline.point_sprite)
          return TRUE;
    }
 
@@ -165,7 +165,7 @@ static struct draw_stage *validate_pipeline( struct draw_stage *stage )
                  && !draw->rasterizer->line_smooth);
 
    /* drawing large points? */
-   if (draw->rasterizer->point_sprite && draw->pipeline.point_sprite)
+   if (draw->rasterizer->sprite_coord_enable && draw->pipeline.point_sprite)
       wide_points = TRUE;
    else if (draw->rasterizer->point_smooth && draw->pipeline.aapoint)
       wide_points = FALSE;
@@ -197,7 +197,7 @@ static struct draw_stage *validate_pipeline( struct draw_stage *stage )
       precalc_flat = 1;
    }
 
-   if (wide_points || draw->rasterizer->point_sprite) {
+   if (wide_points || draw->rasterizer->sprite_coord_enable) {
       draw->pipeline.wide_point->next = next;
       next = draw->pipeline.wide_point;
    }
index f723e658e1a3172f589772b4245b5cdeedc7b015..d9d4d2a8b67d8fbb88896116f58fdde283bb1c55 100644 (file)
@@ -69,8 +69,9 @@ struct widepoint_stage {
    float ybias;
 
    uint texcoord_slot[PIPE_MAX_SHADER_OUTPUTS];
-   uint texcoord_mode[PIPE_MAX_SHADER_OUTPUTS];
+   uint texcoord_enable[PIPE_MAX_SHADER_OUTPUTS];
    uint num_texcoords;
+   uint texcoord_mode;
 
    int psize_slot;
 
@@ -96,10 +97,10 @@ static void set_texcoords(const struct widepoint_stage *wide,
 {
    uint i;
    for (i = 0; i < wide->num_texcoords; i++) {
-      if (wide->texcoord_mode[i] != PIPE_SPRITE_COORD_NONE) {
+      if (wide->texcoord_enable[i]) {
          uint j = wide->texcoord_slot[i];
          v->data[j][0] = tc[0];
-         if (wide->texcoord_mode[i] == PIPE_SPRITE_COORD_LOWER_LEFT)
+         if (wide->texcoord_mode == PIPE_SPRITE_COORD_LOWER_LEFT)
             v->data[j][1] = 1.0f - tc[1];
          else
             v->data[j][1] = tc[1];
@@ -129,7 +130,7 @@ static void widepoint_point( struct draw_stage *stage,
 {
    const struct widepoint_stage *wide = widepoint_stage(stage);
    const unsigned pos = draw_current_shader_position_output(stage->draw);
-   const boolean sprite = (boolean) stage->draw->rasterizer->point_sprite;
+   const boolean sprite = (boolean) stage->draw->rasterizer->sprite_coord_enable;
    float half_size;
    float left_adj, right_adj, bot_adj, top_adj;
 
@@ -222,21 +223,22 @@ static void widepoint_first_point( struct draw_stage *stage,
 
    /* XXX we won't know the real size if it's computed by the vertex shader! */
    if ((draw->rasterizer->point_size > draw->pipeline.wide_point_threshold) ||
-       (draw->rasterizer->point_sprite && draw->pipeline.point_sprite)) {
+       (draw->rasterizer->sprite_coord_enable && draw->pipeline.point_sprite)) {
       stage->point = widepoint_point;
    }
    else {
       stage->point = draw_pipe_passthrough_point;
    }
 
-   if (draw->rasterizer->point_sprite) {
+   if (draw->rasterizer->sprite_coord_enable) {
       /* find vertex shader texcoord outputs */
       const struct draw_vertex_shader *vs = draw->vs.vertex_shader;
       uint i, j = 0;
+      wide->texcoord_mode = draw->rasterizer->sprite_coord_mode;
       for (i = 0; i < vs->info.num_outputs; i++) {
          if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_GENERIC) {
             wide->texcoord_slot[j] = i;
-            wide->texcoord_mode[j] = draw->rasterizer->sprite_coord_mode[j];
+            wide->texcoord_enable[j] = (draw->rasterizer->sprite_coord_enable >> j) & 1;
             j++;
          }
       }
index 5ffd6007be735f06179568869568cdb1a961413c..89c3c061f0d87ab4013879eb9445fd59d8a60d9f 100644 (file)
@@ -83,7 +83,10 @@ point_size_per_vertex
 point_size
     The size of points, if not specified per-vertex.
 point_sprite
-    Whether points are drawn as sprites (textured quads)
+    Whether points are drawn as sprites (textured quads). This is mutually
+    exclusive with point_smooth. Note that sprite_coord_mode set to
+    PIPE_SPRITE_COORD_NONE for all coords and point_sprite enabled is basically
+    equivalent to point_sprite disabled.
 sprite_coord_mode
     Specifies how the value for each shader output should be computed when
     drawing sprites.  If PIPE_SPRITE_COORD_NONE, don't change the vertex
@@ -98,7 +101,7 @@ sprite_coord_mode
     sprite rendering.
     Note that when geometry shaders are available, this state could be
     removed.  A special geometry shader defined by the state tracker could
-    converts the incoming points into quads with the proper texture coords.
+    convert the incoming points into quads with the proper texture coords.
 
 scissor
     Whether the scissor test is enabled.
index e1986a9dbbd4c47890e8e7adf74484eb3aec634c..fc3102b5318514893bad4cd83d687b0e6ff004b1 100644 (file)
@@ -128,6 +128,7 @@ static enum pipe_error compile_sf_prog( struct brw_context *brw,
 static enum pipe_error upload_sf_prog(struct brw_context *brw)
 {
    const struct brw_fs_signature *sig = &brw->curr.fragment_shader->signature;
+   const struct pipe_rasterizer_state *rast = &brw->curr.rast->templ;
    struct brw_sf_prog_key key;
    enum pipe_error ret;
    unsigned i;
@@ -166,8 +167,8 @@ static enum pipe_error upload_sf_prog(struct brw_context *brw)
    case PIPE_PRIM_TRIANGLES: 
       /* PIPE_NEW_RAST
        */
-      if (brw->curr.rast->templ.fill_cw != PIPE_POLYGON_MODE_FILL ||
-         brw->curr.rast->templ.fill_ccw != PIPE_POLYGON_MODE_FILL)
+      if (rast->fill_cw != PIPE_POLYGON_MODE_FILL ||
+         rast->fill_ccw != PIPE_POLYGON_MODE_FILL)
         key.primitive = SF_UNFILLED_TRIS;
       else
         key.primitive = SF_TRIANGLES;
@@ -180,14 +181,14 @@ static enum pipe_error upload_sf_prog(struct brw_context *brw)
       break;
    }
 
-   key.do_point_sprite = brw->curr.rast->templ.point_sprite;
-   key.sprite_origin_lower_left = 0; /* XXX: ctx->Point.SpriteOrigin - fix rast state */
-   key.do_flat_shading = brw->curr.rast->templ.flatshade;
-   key.do_twoside_color = brw->curr.rast->templ.light_twoside;
+   key.do_point_sprite = rast->sprite_coord_enable ? 1 : 0;
+   key.sprite_origin_lower_left = (rast->sprite_coord_mode == PIPE_SPRITE_COORD_LOWER_LEFT);
+   key.point_coord_replace_attrs = rast->sprite_coord_enable;
+   key.do_flat_shading = rast->flatshade;
+   key.do_twoside_color = rast->light_twoside;
 
    if (key.do_twoside_color) {
-      key.frontface_ccw = (brw->curr.rast->templ.front_winding == 
-                          PIPE_WINDING_CCW);
+      key.frontface_ccw = (rast->front_winding == PIPE_WINDING_CCW);
    }
 
    if (brw_search_cache(&brw->cache, BRW_SF_PROG,
index 663a688772c8100684ce650463a9a4fec87d4988..0ad91e03072afb345f5ef63e9a098f7b43ad45e1 100644 (file)
@@ -123,7 +123,7 @@ sf_unit_populate_key(struct brw_context *brw, struct brw_sf_unit_key *key)
    key->line_last_pixel_enable = rast->line_last_pixel;
    key->gl_rasterization_rules = rast->gl_rasterization_rules;
 
-   key->point_sprite = rast->point_sprite;
+   key->point_sprite = rast->sprite_coord_enable ? 1 : 0;
    key->point_attenuated = rast->point_size_per_vertex;
 
    key->point_size = rast->point_size;
index ffc6be3c401d68740f162bb86d15ab001d4d2299..6f674d6e13fd12fba87958c4ab13386965531ec0 100644 (file)
@@ -299,10 +299,10 @@ nv10_rasterizer_state_create(struct pipe_context *pipe,
                break;
        }
 
-       if (cso->point_sprite) {
+       if (cso->sprite_coord_enable) {
                rs->point_sprite = (1 << 0);
                for (i = 0; i < 8; i++) {
-                       if (cso->sprite_coord_mode[i] != PIPE_SPRITE_COORD_NONE)
+                       if ((cso->sprite_coord_enable >> i) & 1)
                                rs->point_sprite |= (1 << (8 + i));
                }
        } else {
index 3a82e63423dcea9b595a573c25479f9af90c452b..3d9a276fa12bf2f73f9ac82b0eab9bd287079a68 100644 (file)
@@ -292,10 +292,10 @@ nv20_rasterizer_state_create(struct pipe_context *pipe,
                break;
        }
 
-       if (cso->point_sprite) {
+       if (cso->sprite_coord_enable) {
                rs->point_sprite = (1 << 0);
                for (i = 0; i < 8; i++) {
-                       if (cso->sprite_coord_mode[i] != PIPE_SPRITE_COORD_NONE)
+                       if ((cso->sprite_coord_enable >> i) & 1)
                                rs->point_sprite |= (1 << (8 + i));
                }
        } else {
index a80dfb04880db04a30967706ca72d083e3546eb7..ab9fc5293c868a6b901426131fd315cbd067c03b 100644 (file)
@@ -391,11 +391,11 @@ nv30_rasterizer_state_create(struct pipe_context *pipe,
        }
 
        so_method(so, rankine, NV34TCL_POINT_SPRITE, 1);
-       if (cso->point_sprite) {
+       if (cso->sprite_coord_enable) {
                unsigned psctl = (1 << 0), i;
 
                for (i = 0; i < 8; i++) {
-                       if (cso->sprite_coord_mode[i] != PIPE_SPRITE_COORD_NONE)
+                       if ((cso->sprite_coord_enable >> i) & 1)
                                psctl |= (1 << (8 + i));
                }
 
index ed0ca9e02c31d8c0b183ebd59e9e126993d164a3..a5c5e291f3e49f547d66b7a5e7e5d0d36408bb8b 100644 (file)
@@ -401,11 +401,11 @@ nv40_rasterizer_state_create(struct pipe_context *pipe,
        }
 
        so_method(so, curie, NV40TCL_POINT_SPRITE, 1);
-       if (cso->point_sprite) {
+       if (cso->sprite_coord_enable) {
                unsigned psctl = (1 << 0), i;
 
                for (i = 0; i < 8; i++) {
-                       if (cso->sprite_coord_mode[i] != PIPE_SPRITE_COORD_NONE)
+                       if ((cso->sprite_coord_enable >> i) & 1)
                                psctl |= (1 << (8 + i));
                }
 
index e16fa479e5f1533b13dfbb1244cb0ecabce67c1d..593d7436037fd85f99351036fee29e24692e9eaa 100644 (file)
@@ -4067,15 +4067,13 @@ nv50_pntc_replace(struct nv50_context *nv50, uint32_t pntc[8], unsigned base)
                }
 
                if (j < vp->info.num_outputs) {
-                       ubyte mode =
-                               nv50->rasterizer->pipe.sprite_coord_mode[si];
+                       ubyte enable =
+                                (nv50->rasterizer->pipe.sprite_coord_enable >> si) & 1;
 
-                       if (mode == PIPE_SPRITE_COORD_NONE) {
+                       if (enable == 0) {
                                m += n;
                                continue;
-                       } else
-                       if (mode == PIPE_SPRITE_COORD_LOWER_LEFT)
-                               origin = 0;
+                       }
                }
 
                /* this is either PointCoord or replaced by sprite coords */
@@ -4086,7 +4084,7 @@ nv50_pntc_replace(struct nv50_context *nv50, uint32_t pntc[8], unsigned base)
                        ++m;
                }
        }
-       return origin;
+       return (nv50->rasterizer->pipe.sprite_coord_mode == PIPE_SPRITE_COORD_LOWER_LEFT ? 0 : origin);
 }
 
 static int
@@ -4202,7 +4200,7 @@ nv50_linkage_validate(struct nv50_context *nv50)
        so_method(so, tesla, NV50TCL_NOPERSPECTIVE_BITMAP(0), 4);
        so_datap (so, lin, 4);
 
-       if (nv50->rasterizer->pipe.point_sprite) {
+       if (nv50->rasterizer->pipe.sprite_coord_enable) {
                so_method(so, tesla, NV50TCL_POINT_SPRITE_CTRL, 1);
                so_data  (so,
                          nv50_pntc_replace(nv50, pcrd, (reg[4] >> 8) & 0xff));
index 1f67df814b1742a4d9e8ad748a209ff9269870f7..cbe2f349c2bd062a7d2a79af58aeb627694ea038 100644 (file)
@@ -318,7 +318,7 @@ nv50_rasterizer_state_create(struct pipe_context *pipe,
        so_data  (so, fui(cso->point_size));
 
        so_method(so, tesla, NV50TCL_POINT_SPRITE_ENABLE, 1);
-       so_data  (so, cso->point_sprite);
+       so_data  (so, cso->sprite_coord_enable ? 1 : 0);
 
        so_method(so, tesla, NV50TCL_POLYGON_MODE_FRONT, 3);
        if (cso->front_winding == PIPE_WINDING_CCW) {
index cae2d3efc589317c42e5bde7c69e6279a8803b21..7dde3c1330107cf6564ef892afc3d1b96385361c 100644 (file)
@@ -167,7 +167,7 @@ init_pipe_state(struct sp_mpeg12_context *ctx)
    rast.scissor = 0;
    rast.poly_smooth = 0;
    rast.poly_stipple_enable = 0;
-   rast.point_sprite = 0;
+   rast.sprite_coord_enable = 0;
    rast.point_size_per_vertex = 0;
    rast.multisample = 0;
    rast.line_smooth = 0;
@@ -181,7 +181,6 @@ init_pipe_state(struct sp_mpeg12_context *ctx)
    rast.point_size = 1;
    rast.offset_units = 1;
    rast.offset_scale = 1;
-   /*rast.sprite_coord_mode[i] = ;*/
    ctx->rast = ctx->pipe->create_rasterizer_state(ctx->pipe, &rast);
    ctx->pipe->bind_rasterizer_state(ctx->pipe, ctx->rast);
 
index b5ecc4c56cae10f2e0145ab945190ae58b120b93..0a613cb553dc9316c8c521890ddcc45fe629b722 100644 (file)
@@ -71,7 +71,7 @@ svga_create_rasterizer_state(struct pipe_context *pipe,
    /* light_twoside          - XXX: need fragment shader varient */
    /* poly_smooth            - XXX: no fallback available */
    /* poly_stipple_enable    - draw module */
-   /* point_sprite           - ? */
+   /* sprite_coord_enable    - ? */
    /* point_size_per_vertex  - ? */
    /* sprite_coord_mode      - ??? */
    /* bypass_vs_viewport_and_clip        - handled by viewport setup */
index 0e7b7ec123fe9898783657c3bbc71847602c1e1f..ed327f60f08e39ec00c055caf3217e98c827e05f 100644 (file)
@@ -112,7 +112,8 @@ void trace_dump_rasterizer_state(const struct pipe_rasterizer_state *state)
    trace_dump_member(bool, state, poly_smooth);
    trace_dump_member(bool, state, poly_stipple_enable);
    trace_dump_member(bool, state, point_smooth);
-   trace_dump_member(bool, state, point_sprite);
+   trace_dump_member(uint, state, sprite_coord_enable);
+   trace_dump_member(bool, state, sprite_coord_mode);
    trace_dump_member(bool, state, point_size_per_vertex);
    trace_dump_member(bool, state, multisample);
    trace_dump_member(bool, state, line_smooth);
@@ -129,8 +130,6 @@ void trace_dump_rasterizer_state(const struct pipe_rasterizer_state *state)
    trace_dump_member(float, state, offset_units);
    trace_dump_member(float, state, offset_scale);
 
-   trace_dump_member_array(uint, state, sprite_coord_mode);
-
    trace_dump_struct_end();
 }
 
index 35f3830ebcf076ba9d7305b6ba62b64bf89466ae..a85a1701536ad77970025301505522233fa01932 100644 (file)
@@ -364,9 +364,8 @@ enum pipe_transfer_usage {
 /**
  * Point sprite coord modes
  */
-#define PIPE_SPRITE_COORD_NONE       0
-#define PIPE_SPRITE_COORD_UPPER_LEFT 1
-#define PIPE_SPRITE_COORD_LOWER_LEFT 2
+#define PIPE_SPRITE_COORD_UPPER_LEFT 0
+#define PIPE_SPRITE_COORD_LOWER_LEFT 1
 
 
 /**
index ea3ec201eaa224b74cba726f99d9d60c5421a81a..50a4cd6e138dfcfe32763a6dfd9c0b86f94e8a8e 100644 (file)
@@ -101,7 +101,8 @@ struct pipe_rasterizer_state
    unsigned poly_smooth:1;
    unsigned poly_stipple_enable:1;
    unsigned point_smooth:1;
-   unsigned point_sprite:1;
+   unsigned sprite_coord_enable:PIPE_MAX_SHADER_OUTPUTS;
+   unsigned sprite_coord_mode:1;     /**< PIPE_SPRITE_COORD_ */
    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;
@@ -143,7 +144,6 @@ struct pipe_rasterizer_state
    float point_size;           /**< used when no per-vertex size */
    float offset_units;
    float offset_scale;
-   ubyte sprite_coord_mode[PIPE_MAX_SHADER_OUTPUTS]; /**< PIPE_SPRITE_COORD_ */
 };
 
 
index a68709f5cf34b5b59d9df1b75c68171b69d0f5d8..bb61979d07c30dc8b6241433ae88e9ba8f40f838 100755 (executable)
@@ -113,7 +113,7 @@ struct_factories = {
 
 
 member_array_factories = {
-    "pipe_rasterizer_state": {"sprite_coord_mode": gallium.ByteArray},                          
+    #"pipe_rasterizer_state": {"sprite_coord_mode": gallium.ByteArray},                          
     "pipe_poly_stipple": {"stipple": gallium.UnsignedArray},                          
     "pipe_viewport_state": {"scale": gallium.FloatArray, "translate": gallium.FloatArray},                          
     #"pipe_clip_state": {"ucp": gallium.FloatArray},
index 710574f3618983f6245bd549f0d9a0fd312d36e9..16c842d2f695904d3ba586b0ce51266c364fa7c3 100644 (file)
@@ -188,18 +188,19 @@ static void update_raster_state( struct st_context *st )
     */
    raster->point_size = ctx->Point.Size;
 
-   raster->point_smooth = ctx->Point.SmoothFlag;
-   raster->point_sprite = ctx->Point.PointSprite;
-   for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
-      if (ctx->Point.CoordReplace[i]) {
-         if ((ctx->Point.SpriteOrigin == GL_UPPER_LEFT) ^
-             (st_fb_orientation(ctx->DrawBuffer) == Y_0_BOTTOM))
-            raster->sprite_coord_mode[i] = PIPE_SPRITE_COORD_UPPER_LEFT;
-         else 
-            raster->sprite_coord_mode[i] = PIPE_SPRITE_COORD_LOWER_LEFT;
-      }
-      else {
-         raster->sprite_coord_mode[i] = PIPE_SPRITE_COORD_NONE;
+   if (!ctx->Point.PointSprite && ctx->Point.SmoothFlag)
+      raster->point_smooth = 1;
+
+   if (ctx->Point.PointSprite) {
+      if ((ctx->Point.SpriteOrigin == GL_UPPER_LEFT) ^
+          (st_fb_orientation(ctx->DrawBuffer) == Y_0_BOTTOM))
+         raster->sprite_coord_mode = PIPE_SPRITE_COORD_UPPER_LEFT;
+      else 
+         raster->sprite_coord_mode = PIPE_SPRITE_COORD_LOWER_LEFT;
+      for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
+         if (ctx->Point.CoordReplace[i]) {
+            raster->sprite_coord_enable |= 1 << i;
+         }
       }
    }