nv30: Emit rasterizer state using state objects
authorPatrice Mandin <pmandin@caramail.com>
Thu, 3 Jul 2008 19:48:18 +0000 (21:48 +0200)
committerPatrice Mandin <pmandin@caramail.com>
Thu, 3 Jul 2008 19:48:18 +0000 (21:48 +0200)
src/gallium/drivers/nv30/nv30_context.h
src/gallium/drivers/nv30/nv30_state.c
src/gallium/drivers/nv30/nv30_state.h
src/gallium/drivers/nv30/nv30_state_emit.c

index eedebc91b23ee6ba4403dbd1f97b60ceab89262f..692d8dd523089d8ada9a0e7dd3a719a4aac5b83f 100644 (file)
@@ -76,8 +76,7 @@ enum nv30_state_index {
 #define NV30_NEW_ARRAYS                (1 << 11)
 #define NV30_NEW_UCP           (1 << 12)
 
-/* TODO: rename when removing the old state emitter */
-struct nv30_rasterizer_state_new {
+struct nv30_rasterizer_state {
        struct pipe_rasterizer_state pipe;
        struct nouveau_stateobj *so;
 };
@@ -124,11 +123,11 @@ struct nv30_context {
        unsigned vp_samplers;
 
        /* Context state */
+       struct nv30_rasterizer_state *rasterizer;
        struct nv30_blend_state *blend;
        struct pipe_blend_color blend_colour;
        struct pipe_viewport_state viewport;
        struct pipe_framebuffer_state framebuffer;
-       struct nv30_rasterizer_state_new *rasterizer;
        struct nv30_zsa_state *zsa;
        unsigned stipple[32];
 
@@ -211,6 +210,7 @@ extern void nv30_fragtex_bind(struct nv30_context *);
 extern boolean nv30_state_validate(struct nv30_context *nv30);
 extern void nv30_emit_hw_state(struct nv30_context *nv30);
 extern void nv30_state_tex_update(struct nv30_context *nv30);
+extern struct nv30_state_entry nv30_state_rasterizer;
 extern struct nv30_state_entry nv30_state_blend;
 extern struct nv30_state_entry nv30_state_blend_colour;
 extern struct nv30_state_entry nv30_state_framebuffer;
index cf46dcef936419133851a95367006ce1d6cf51f1..8c7a902e28f7a7fa2ffaf32f931301921d8ffb9d 100644 (file)
@@ -275,123 +275,134 @@ static void *
 nv30_rasterizer_state_create(struct pipe_context *pipe,
                             const struct pipe_rasterizer_state *cso)
 {
-       struct nv30_rasterizer_state *rs;
-       int i;
+       struct nv30_context *nv30 = nv30_context(pipe);
+       struct nv30_rasterizer_state *rsso = CALLOC(1, sizeof(*rsso));
+       struct nouveau_stateobj *so = so_new(32, 0);
+       struct nouveau_grobj *rankine = nv30->screen->rankine;
 
        /*XXX: ignored:
         *      light_twoside
-        *      offset_cw/ccw -nohw
-        *      scissor
         *      point_smooth -nohw
         *      multisample
-        *      offset_units / offset_scale
         */
-       rs = malloc(sizeof(struct nv30_rasterizer_state));
-
-       rs->shade_model = cso->flatshade ? 0x1d00 : 0x1d01;
 
-       rs->line_width = (unsigned char)(cso->line_width * 8.0) & 0xff;
-       rs->line_smooth_en = cso->line_smooth ? 1 : 0;
-       rs->line_stipple_en = cso->line_stipple_enable ? 1 : 0;
-       rs->line_stipple = (cso->line_stipple_pattern << 16) |
-                           cso->line_stipple_factor;
+       so_method(so, rankine, NV34TCL_SHADE_MODEL, 1);
+       so_data  (so, cso->flatshade ? NV34TCL_SHADE_MODEL_FLAT :
+                                      NV34TCL_SHADE_MODEL_SMOOTH);
 
-       rs->point_size = *(uint32_t*)&cso->point_size;
+       so_method(so, rankine, NV34TCL_LINE_WIDTH, 2);
+       so_data  (so, (unsigned char)(cso->line_width * 8.0) & 0xff);
+       so_data  (so, cso->line_smooth ? 1 : 0);
+       so_method(so, rankine, NV34TCL_LINE_STIPPLE_ENABLE, 2);
+       so_data  (so, cso->line_stipple_enable ? 1 : 0);
+       so_data  (so, (cso->line_stipple_pattern << 16) |
+                      cso->line_stipple_factor);
 
-       rs->poly_smooth_en = cso->poly_smooth ? 1 : 0;
-       rs->poly_stipple_en = cso->poly_stipple_enable ? 1 : 0;
+       so_method(so, rankine, NV34TCL_POINT_SIZE, 1);
+       so_data  (so, fui(cso->point_size));
 
+       so_method(so, rankine, NV34TCL_POLYGON_MODE_FRONT, 6);
        if (cso->front_winding == PIPE_WINDING_CCW) {
-               rs->front_face = NV34TCL_FRONT_FACE_CCW;
-               rs->poly_mode_front = nvgl_polygon_mode(cso->fill_ccw);
-               rs->poly_mode_back  = nvgl_polygon_mode(cso->fill_cw);
+               so_data(so, nvgl_polygon_mode(cso->fill_ccw));
+               so_data(so, nvgl_polygon_mode(cso->fill_cw));
+               switch (cso->cull_mode) {
+               case PIPE_WINDING_CCW:
+                       so_data(so, NV34TCL_CULL_FACE_FRONT);
+                       break;
+               case PIPE_WINDING_CW:
+                       so_data(so, NV34TCL_CULL_FACE_BACK);
+                       break;
+               case PIPE_WINDING_BOTH:
+                       so_data(so, NV34TCL_CULL_FACE_FRONT_AND_BACK);
+                       break;
+               default:
+                       so_data(so, NV34TCL_CULL_FACE_BACK);
+                       break;
+               }
+               so_data(so, NV34TCL_FRONT_FACE_CCW);
        } else {
-               rs->front_face = NV34TCL_FRONT_FACE_CW;
-               rs->poly_mode_front = nvgl_polygon_mode(cso->fill_cw);
-               rs->poly_mode_back  = nvgl_polygon_mode(cso->fill_ccw);
+               so_data(so, nvgl_polygon_mode(cso->fill_cw));
+               so_data(so, nvgl_polygon_mode(cso->fill_ccw));
+               switch (cso->cull_mode) {
+               case PIPE_WINDING_CCW:
+                       so_data(so, NV34TCL_CULL_FACE_BACK);
+                       break;
+               case PIPE_WINDING_CW:
+                       so_data(so, NV34TCL_CULL_FACE_FRONT);
+                       break;
+               case PIPE_WINDING_BOTH:
+                       so_data(so, NV34TCL_CULL_FACE_FRONT_AND_BACK);
+                       break;
+               default:
+                       so_data(so, NV34TCL_CULL_FACE_BACK);
+                       break;
+               }
+               so_data(so, NV34TCL_FRONT_FACE_CW);
        }
-
-       switch (cso->cull_mode) {
-       case PIPE_WINDING_CCW:
-               rs->cull_face_en = 1;
-               if (cso->front_winding == PIPE_WINDING_CCW)
-                       rs->cull_face    = NV34TCL_CULL_FACE_FRONT;
-               else
-                       rs->cull_face    = NV34TCL_CULL_FACE_BACK;
-               break;
-       case PIPE_WINDING_CW:
-               rs->cull_face_en = 1;
-               if (cso->front_winding == PIPE_WINDING_CW)
-                       rs->cull_face    = NV34TCL_CULL_FACE_FRONT;
-               else
-                       rs->cull_face    = NV34TCL_CULL_FACE_BACK;
-               break;
-       case PIPE_WINDING_BOTH:
-               rs->cull_face_en = 1;
-               rs->cull_face    = NV34TCL_CULL_FACE_FRONT_AND_BACK;
-               break;
-       case PIPE_WINDING_NONE:
-       default:
-               rs->cull_face_en = 0;
-               rs->cull_face    = 0;
-               break;
+       so_data(so, cso->poly_smooth ? 1 : 0);
+       so_data(so, (cso->cull_mode != PIPE_WINDING_NONE) ? 1 : 0);
+
+       so_method(so, rankine, NV34TCL_POLYGON_STIPPLE_ENABLE, 1);
+       so_data  (so, cso->poly_stipple_enable ? 1 : 0);
+
+       so_method(so, rankine, NV34TCL_POLYGON_OFFSET_POINT_ENABLE, 3);
+       if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_POINT) ||
+           (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_POINT))
+               so_data(so, 1);
+       else
+               so_data(so, 0);
+       if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_LINE) ||
+           (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_LINE))
+               so_data(so, 1);
+       else
+               so_data(so, 0);
+       if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_FILL) ||
+           (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_FILL))
+               so_data(so, 1);
+       else
+               so_data(so, 0);
+       if (cso->offset_cw || cso->offset_ccw) {
+               so_method(so, rankine, NV34TCL_POLYGON_OFFSET_FACTOR, 2);
+               so_data  (so, fui(cso->offset_scale));
+               so_data  (so, fui(cso->offset_units * 2));
        }
 
+       so_method(so, rankine, NV34TCL_POINT_SPRITE, 1);
        if (cso->point_sprite) {
-               rs->point_sprite = (1 << 0);
+               unsigned psctl = (1 << 0), i;
+
                for (i = 0; i < 8; i++) {
                        if (cso->sprite_coord_mode[i] != PIPE_SPRITE_COORD_NONE)
-                               rs->point_sprite |= (1 << (8 + i));
+                               psctl |= (1 << (8 + i));
                }
+
+               so_data(so, psctl);
        } else {
-               rs->point_sprite = 0;
+               so_data(so, 0);
        }
 
-       return (void *)rs;
+       so_ref(so, &rsso->so);
+       rsso->pipe = *cso;
+       return (void *)rsso;
 }
 
 static void
 nv30_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
 {
        struct nv30_context *nv30 = nv30_context(pipe);
-       struct nv30_rasterizer_state *rs = hwcso;
 
-       if (!hwcso) {
-               return;
-       }
-
-       BEGIN_RING(rankine, NV34TCL_SHADE_MODEL, 1);
-       OUT_RING  (rs->shade_model);
-
-       BEGIN_RING(rankine, NV34TCL_LINE_WIDTH, 2);
-       OUT_RING  (rs->line_width);
-       OUT_RING  (rs->line_smooth_en);
-       BEGIN_RING(rankine, NV34TCL_LINE_STIPPLE_ENABLE, 2);
-       OUT_RING  (rs->line_stipple_en);
-       OUT_RING  (rs->line_stipple);
-
-       BEGIN_RING(rankine, NV34TCL_POINT_SIZE, 1);
-       OUT_RING  (rs->point_size);
-
-       BEGIN_RING(rankine, NV34TCL_POLYGON_MODE_FRONT, 6);
-       OUT_RING  (rs->poly_mode_front);
-       OUT_RING  (rs->poly_mode_back);
-       OUT_RING  (rs->cull_face);
-       OUT_RING  (rs->front_face);
-       OUT_RING  (rs->poly_smooth_en);
-       OUT_RING  (rs->cull_face_en);
-
-       BEGIN_RING(rankine, NV34TCL_POLYGON_STIPPLE_ENABLE, 1);
-       OUT_RING  (rs->poly_stipple_en);
-
-       BEGIN_RING(rankine, NV34TCL_POINT_SPRITE, 1);
-       OUT_RING  (rs->point_sprite);
+       nv30->rasterizer = hwcso;
+       nv30->dirty |= NV30_NEW_RAST;
+       /*nv30->draw_dirty |= NV30_NEW_RAST;*/
 }
 
 static void
 nv30_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
 {
-       free(hwcso);
+       struct nv30_rasterizer_state *rsso = hwcso;
+
+       so_ref(NULL, &rsso->so);
+       FREE(rsso);
 }
 
 static void
index 8489b7b796965b75912224bd11e42e046d3c08b5..b33075aceb640c53f8a3ca4afe97e2aab8240d65 100644 (file)
@@ -11,29 +11,6 @@ struct nv30_sampler_state {
        uint32_t bcol;
 };
 
-struct nv30_rasterizer_state {
-       uint32_t shade_model;
-
-       uint32_t line_width;
-       uint32_t line_smooth_en;
-       uint32_t line_stipple_en;
-       uint32_t line_stipple;
-
-       uint32_t point_size;
-
-       uint32_t poly_smooth_en;
-       uint32_t poly_stipple_en;
-       
-       uint32_t poly_mode_front;
-       uint32_t poly_mode_back;
-
-       uint32_t front_face;
-       uint32_t cull_face;
-       uint32_t cull_face_en;
-
-       uint32_t point_sprite;
-};
-
 struct nv30_vertex_program_exec {
        uint32_t data[4];
        boolean has_branch_offset;
index 492f4110117b91658f665a25fc07a1643ea63351..7d77adbfdf0ad97bc04d18d681c1beee4375ce69 100644 (file)
@@ -3,6 +3,7 @@
 
 static struct nv30_state_entry *render_states[] = {
        &nv30_state_framebuffer,
+       &nv30_state_rasterizer,
        &nv30_state_blend,
        &nv30_state_blend_colour,
        NULL