nv50: import current "state of the art" nv50 code
[mesa.git] / src / gallium / drivers / nv40 / nv40_state.c
index 8ffbb131f7341ff04c41b8b52657b4cc5d211ab6..afcf336a65b9cd819dcc28da2b0220fb7f8859b6 100644 (file)
@@ -1,6 +1,9 @@
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_util.h"
+#include "pipe/p_inlines.h"
+
+#include "draw/draw_context.h"
 
 #include "nv40_context.h"
 #include "nv40_state.h"
@@ -10,7 +13,8 @@ nv40_blend_state_create(struct pipe_context *pipe,
                        const struct pipe_blend_state *cso)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
-       struct nouveau_grobj *curie = nv40->hw->curie;
+       struct nouveau_grobj *curie = nv40->screen->curie;
+       struct nv40_blend_state *bso = CALLOC(1, sizeof(*bso));
        struct nouveau_stateobj *so = so_new(16, 0);
 
        if (cso->blend_enable) {
@@ -46,7 +50,9 @@ nv40_blend_state_create(struct pipe_context *pipe,
        so_method(so, curie, NV40TCL_DITHER_ENABLE, 1);
        so_data  (so, cso->dither ? 1 : 0);
 
-       return (void *)so;
+       so_ref(so, &bso->so);
+       bso->pipe = *cso;
+       return (void *)bso;
 }
 
 static void
@@ -54,16 +60,17 @@ nv40_blend_state_bind(struct pipe_context *pipe, void *hwcso)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       so_ref(hwcso, &nv40->so_blend);
+       nv40->blend = hwcso;
        nv40->dirty |= NV40_NEW_BLEND;
 }
 
 static void
 nv40_blend_state_delete(struct pipe_context *pipe, void *hwcso)
 {
-       struct nouveau_stateobj *so = hwcso;
+       struct nv40_blend_state *bso = hwcso;
 
-       so_ref(NULL, &so);
+       so_ref(NULL, &bso->so);
+       FREE(bso);
 }
 
 
@@ -247,30 +254,52 @@ nv40_sampler_state_create(struct pipe_context *pipe,
 }
 
 static void
-nv40_sampler_state_bind(struct pipe_context *pipe, unsigned unit,
-                       void *hwcso)
+nv40_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **sampler)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
-       struct nv40_sampler_state *ps = hwcso;
+       unsigned unit;
+
+       for (unit = 0; unit < nr; unit++) {
+               nv40->tex_sampler[unit] = sampler[unit];
+               nv40->dirty_samplers |= (1 << unit);
+       }
 
-       nv40->tex_sampler[unit] = ps;
-       nv40->dirty_samplers |= (1 << unit);
+       for (unit = nr; unit < nv40->nr_samplers; unit++) {
+               nv40->tex_sampler[unit] = NULL;
+               nv40->dirty_samplers |= (1 << unit);
+       }
+
+       nv40->nr_samplers = nr;
+       nv40->dirty |= NV40_NEW_SAMPLER;
 }
 
 static void
 nv40_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
 {
-       free(hwcso);
+       FREE(hwcso);
 }
 
 static void
-nv40_set_sampler_texture(struct pipe_context *pipe, unsigned unit,
-                        struct pipe_texture *miptree)
+nv40_set_sampler_texture(struct pipe_context *pipe, unsigned nr,
+                        struct pipe_texture **miptree)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
+       unsigned unit;
+
+       for (unit = 0; unit < nr; unit++) {
+               pipe_texture_reference((struct pipe_texture **)
+                                      &nv40->tex_miptree[unit], miptree[unit]);
+               nv40->dirty_samplers |= (1 << unit);
+       }
 
-       nv40->tex_miptree[unit] = (struct nv40_miptree *)miptree;
-       nv40->dirty_samplers |= (1 << unit);
+       for (unit = nr; unit < nv40->nr_textures; unit++) {
+               pipe_texture_reference((struct pipe_texture **)
+                                      &nv40->tex_miptree[unit], NULL);
+               nv40->dirty_samplers |= (1 << unit);
+       }
+
+       nv40->nr_textures = nr;
+       nv40->dirty |= NV40_NEW_SAMPLER;
 }
 
 static void *
@@ -278,9 +307,9 @@ nv40_rasterizer_state_create(struct pipe_context *pipe,
                             const struct pipe_rasterizer_state *cso)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
-       struct nv40_rasterizer_state *rsso = MALLOC(sizeof(*rsso));
+       struct nv40_rasterizer_state *rsso = CALLOC(1, sizeof(*rsso));
        struct nouveau_stateobj *so = so_new(32, 0);
-       struct nouveau_grobj *curie = nv40->hw->curie;
+       struct nouveau_grobj *curie = nv40->screen->curie;
 
        /*XXX: ignored:
         *      light_twoside
@@ -318,7 +347,7 @@ nv40_rasterizer_state_create(struct pipe_context *pipe,
                        so_data(so, NV40TCL_CULL_FACE_FRONT_AND_BACK);
                        break;
                default:
-                       so_data(so, 0);
+                       so_data(so, NV40TCL_CULL_FACE_BACK);
                        break;
                }
                so_data(so, NV40TCL_FRONT_FACE_CCW);
@@ -336,13 +365,13 @@ nv40_rasterizer_state_create(struct pipe_context *pipe,
                        so_data(so, NV40TCL_CULL_FACE_FRONT_AND_BACK);
                        break;
                default:
-                       so_data(so, 0);
+                       so_data(so, NV40TCL_CULL_FACE_BACK);
                        break;
                }
                so_data(so, NV40TCL_FRONT_FACE_CW);
        }
        so_data(so, cso->poly_smooth ? 1 : 0);
-       so_data(so, cso->cull_mode != PIPE_WINDING_NONE ? 1 : 0);
+       so_data(so, (cso->cull_mode != PIPE_WINDING_NONE) ? 1 : 0);
 
        so_method(so, curie, NV40TCL_POLYGON_STIPPLE_ENABLE, 1);
        so_data  (so, cso->poly_stipple_enable ? 1 : 0);
@@ -383,7 +412,7 @@ nv40_rasterizer_state_create(struct pipe_context *pipe,
                so_data(so, 0);
        }
 
-       rsso->so = so;
+       so_ref(so, &rsso->so);
        rsso->pipe = *cso;
        return (void *)rsso;
 }
@@ -392,11 +421,10 @@ static void
 nv40_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
-       struct nv40_rasterizer_state *rsso = hwcso;
 
-       so_ref(rsso->so, &nv40->so_rast);
-       nv40->rasterizer = rsso;
+       nv40->rasterizer = hwcso;
        nv40->dirty |= NV40_NEW_RAST;
+       nv40->draw_dirty |= NV40_NEW_RAST;
 }
 
 static void
@@ -405,7 +433,7 @@ nv40_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
        struct nv40_rasterizer_state *rsso = hwcso;
 
        so_ref(NULL, &rsso->so);
-       free(rsso);
+       FREE(rsso);
 }
 
 static void *
@@ -413,20 +441,22 @@ nv40_depth_stencil_alpha_state_create(struct pipe_context *pipe,
                        const struct pipe_depth_stencil_alpha_state *cso)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
+       struct nv40_zsa_state *zsaso = CALLOC(1, sizeof(*zsaso));
        struct nouveau_stateobj *so = so_new(32, 0);
+       struct nouveau_grobj *curie = nv40->screen->curie;
 
-       so_method(so, nv40->hw->curie, NV40TCL_DEPTH_FUNC, 3);
+       so_method(so, curie, NV40TCL_DEPTH_FUNC, 3);
        so_data  (so, nvgl_comparison_op(cso->depth.func));
        so_data  (so, cso->depth.writemask ? 1 : 0);
        so_data  (so, cso->depth.enabled ? 1 : 0);
 
-       so_method(so, nv40->hw->curie, NV40TCL_ALPHA_TEST_ENABLE, 3);
+       so_method(so, curie, NV40TCL_ALPHA_TEST_ENABLE, 3);
        so_data  (so, cso->alpha.enabled ? 1 : 0);
        so_data  (so, nvgl_comparison_op(cso->alpha.func));
        so_data  (so, float_to_ubyte(cso->alpha.ref));
 
        if (cso->stencil[0].enabled) {
-               so_method(so, nv40->hw->curie, NV40TCL_STENCIL_FRONT_ENABLE, 8);
+               so_method(so, curie, NV40TCL_STENCIL_FRONT_ENABLE, 8);
                so_data  (so, cso->stencil[0].enabled ? 1 : 0);
                so_data  (so, cso->stencil[0].write_mask);
                so_data  (so, nvgl_comparison_op(cso->stencil[0].func));
@@ -436,12 +466,12 @@ nv40_depth_stencil_alpha_state_create(struct pipe_context *pipe,
                so_data  (so, nvgl_stencil_op(cso->stencil[0].zfail_op));
                so_data  (so, nvgl_stencil_op(cso->stencil[0].zpass_op));
        } else {
-               so_method(so, nv40->hw->curie, NV40TCL_STENCIL_FRONT_ENABLE, 1);
+               so_method(so, curie, NV40TCL_STENCIL_FRONT_ENABLE, 1);
                so_data  (so, 0);
        }
 
        if (cso->stencil[1].enabled) {
-               so_method(so, nv40->hw->curie, NV40TCL_STENCIL_BACK_ENABLE, 8);
+               so_method(so, curie, NV40TCL_STENCIL_BACK_ENABLE, 8);
                so_data  (so, cso->stencil[1].enabled ? 1 : 0);
                so_data  (so, cso->stencil[1].write_mask);
                so_data  (so, nvgl_comparison_op(cso->stencil[1].func));
@@ -451,11 +481,13 @@ nv40_depth_stencil_alpha_state_create(struct pipe_context *pipe,
                so_data  (so, nvgl_stencil_op(cso->stencil[1].zfail_op));
                so_data  (so, nvgl_stencil_op(cso->stencil[1].zpass_op));
        } else {
-               so_method(so, nv40->hw->curie, NV40TCL_STENCIL_BACK_ENABLE, 1);
+               so_method(so, curie, NV40TCL_STENCIL_BACK_ENABLE, 1);
                so_data  (so, 0);
        }
 
-       return (void *)so;
+       so_ref(so, &zsaso->so);
+       zsaso->pipe = *cso;
+       return (void *)zsaso;
 }
 
 static void
@@ -463,26 +495,29 @@ nv40_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *hwcso)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       so_ref(hwcso, &nv40->so_zsa);
+       nv40->zsa = hwcso;
        nv40->dirty |= NV40_NEW_ZSA;
 }
 
 static void
 nv40_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso)
 {
-       struct nouveau_stateobj *so = hwcso;
+       struct nv40_zsa_state *zsaso = hwcso;
 
-       so_ref(NULL, &so);
+       so_ref(NULL, &zsaso->so);
+       FREE(zsaso);
 }
 
 static void *
 nv40_vp_state_create(struct pipe_context *pipe,
                     const struct pipe_shader_state *cso)
 {
+       struct nv40_context *nv40 = nv40_context(pipe);
        struct nv40_vertex_program *vp;
 
        vp = CALLOC(1, sizeof(struct nv40_vertex_program));
-       vp->pipe = cso;
+       vp->pipe = *cso;
+       vp->draw = draw_create_vertex_shader(nv40->draw, &vp->pipe);
 
        return (void *)vp;
 }
@@ -492,8 +527,9 @@ nv40_vp_state_bind(struct pipe_context *pipe, void *hwcso)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       nv40->pipe_state.vertprog = hwcso;
+       nv40->vertprog = hwcso;
        nv40->dirty |= NV40_NEW_VERTPROG;
+       nv40->draw_dirty |= NV40_NEW_VERTPROG;
 }
 
 static void
@@ -502,8 +538,9 @@ nv40_vp_state_delete(struct pipe_context *pipe, void *hwcso)
        struct nv40_context *nv40 = nv40_context(pipe);
        struct nv40_vertex_program *vp = hwcso;
 
+       draw_delete_vertex_shader(nv40->draw, vp->draw);
        nv40_vertprog_destroy(nv40, vp);
-       free(vp);
+       FREE(vp);
 }
 
 static void *
@@ -513,7 +550,9 @@ nv40_fp_state_create(struct pipe_context *pipe,
        struct nv40_fragment_program *fp;
 
        fp = CALLOC(1, sizeof(struct nv40_fragment_program));
-       fp->pipe = cso;
+       fp->pipe = *cso;
+
+       tgsi_scan_shader(fp->pipe.tokens, &fp->info);
 
        return (void *)fp;
 }
@@ -523,7 +562,7 @@ nv40_fp_state_bind(struct pipe_context *pipe, void *hwcso)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       nv40->pipe_state.fragprog = hwcso;
+       nv40->fragprog = hwcso;
        nv40->dirty |= NV40_NEW_FRAGPROG;
 }
 
@@ -534,7 +573,7 @@ nv40_fp_state_delete(struct pipe_context *pipe, void *hwcso)
        struct nv40_fragment_program *fp = hwcso;
 
        nv40_fragprog_destroy(nv40, fp);
-       free(fp);
+       FREE(fp);
 }
 
 static void
@@ -542,16 +581,8 @@ nv40_set_blend_color(struct pipe_context *pipe,
                     const struct pipe_blend_color *bcol)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
-       struct nouveau_stateobj *so = so_new(2, 0);
 
-       so_method(so, nv40->hw->curie, NV40TCL_BLEND_COLOR, 1);
-       so_data  (so, ((float_to_ubyte(bcol->color[3]) << 24) |
-                      (float_to_ubyte(bcol->color[0]) << 16) |
-                      (float_to_ubyte(bcol->color[1]) <<  8) |
-                      (float_to_ubyte(bcol->color[2]) <<  0)));
-
-       so_ref(so, &nv40->so_bcol);
-       so_ref(NULL, &so);
+       nv40->blend_colour = *bcol;
        nv40->dirty |= NV40_NEW_BCOL;
 }
 
@@ -561,8 +592,9 @@ nv40_set_clip_state(struct pipe_context *pipe,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       nv40->pipe_state.clip = *clip;
+       nv40->clip = *clip;
        nv40->dirty |= NV40_NEW_UCP;
+       nv40->draw_dirty |= NV40_NEW_UCP;
 }
 
 static void
@@ -571,12 +603,13 @@ nv40_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
+       nv40->constbuf[shader] = buf->buffer;
+       nv40->constbuf_nr[shader] = buf->size / (4 * sizeof(float));
+
        if (shader == PIPE_SHADER_VERTEX) {
-               nv40->pipe_state.constbuf[PIPE_SHADER_VERTEX] = buf->buffer;
                nv40->dirty |= NV40_NEW_VERTPROG;
        } else
        if (shader == PIPE_SHADER_FRAGMENT) {
-               nv40->pipe_state.constbuf[PIPE_SHADER_FRAGMENT] = buf->buffer;
                nv40->dirty |= NV40_NEW_FRAGPROG;
        }
 }
@@ -586,146 +619,8 @@ nv40_set_framebuffer_state(struct pipe_context *pipe,
                           const struct pipe_framebuffer_state *fb)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
-       struct pipe_surface *rt[4], *zeta;
-       uint32_t rt_enable, rt_format, w, h;
-       int i, colour_format = 0, zeta_format = 0;
-       struct nouveau_stateobj *so = so_new(64, 10);
-       unsigned rt_flags = NOUVEAU_BO_RDWR | NOUVEAU_BO_VRAM;
-
-       rt_enable = 0;
-       for (i = 0; i < 4; i++) {
-               if (!fb->cbufs[i])
-                       continue;
-
-               if (colour_format) {
-                       assert(w == fb->cbufs[i]->width);
-                       assert(h == fb->cbufs[i]->height);
-                       assert(colour_format == fb->cbufs[i]->format);
-               } else {
-                       w = fb->cbufs[i]->width;
-                       h = fb->cbufs[i]->height;
-                       colour_format = fb->cbufs[i]->format;
-                       rt_enable |= (NV40TCL_RT_ENABLE_COLOR0 << i);
-                       rt[i] = fb->cbufs[i];
-               }
-       }
-
-       if (rt_enable & (NV40TCL_RT_ENABLE_COLOR1 | NV40TCL_RT_ENABLE_COLOR2 |
-                        NV40TCL_RT_ENABLE_COLOR3))
-               rt_enable |= NV40TCL_RT_ENABLE_MRT;
-
-       if (fb->zsbuf) {
-               if (colour_format) {
-                       assert(w == fb->zsbuf->width);
-                       assert(h == fb->zsbuf->height);
-               } else {
-                       w = fb->zsbuf->width;
-                       h = fb->zsbuf->height;
-               }
-
-               zeta_format = fb->zsbuf->format;
-               zeta = fb->zsbuf;
-       }
-
-       rt_format = NV40TCL_RT_FORMAT_TYPE_LINEAR;
-
-       switch (colour_format) {
-       case PIPE_FORMAT_A8R8G8B8_UNORM:
-       case 0:
-               rt_format |= NV40TCL_RT_FORMAT_COLOR_A8R8G8B8;
-               break;
-       case PIPE_FORMAT_R5G6B5_UNORM:
-               rt_format |= NV40TCL_RT_FORMAT_COLOR_R5G6B5;
-               break;
-       default:
-               assert(0);
-       }
-
-       switch (zeta_format) {
-       case PIPE_FORMAT_Z16_UNORM:
-               rt_format |= NV40TCL_RT_FORMAT_ZETA_Z16;
-               break;
-       case PIPE_FORMAT_Z24S8_UNORM:
-       case 0:
-               rt_format |= NV40TCL_RT_FORMAT_ZETA_Z24S8;
-               break;
-       default:
-               assert(0);
-       }
-
-       if (rt_enable & NV40TCL_RT_ENABLE_COLOR0) {
-               so_method(so, nv40->hw->curie, NV40TCL_DMA_COLOR0, 1);
-               so_reloc (so, rt[0]->buffer, 0, rt_flags | NOUVEAU_BO_OR,
-                         nv40->nvws->channel->vram->handle,
-                         nv40->nvws->channel->gart->handle);
-               so_method(so, nv40->hw->curie, NV40TCL_COLOR0_PITCH, 2);
-               so_data  (so, rt[0]->pitch * rt[0]->cpp);
-               so_reloc (so, rt[0]->buffer, rt[0]->offset, rt_flags |
-                         NOUVEAU_BO_LOW, 0, 0);
-       }
 
-       if (rt_enable & NV40TCL_RT_ENABLE_COLOR1) {
-               so_method(so, nv40->hw->curie, NV40TCL_DMA_COLOR1, 1);
-               so_reloc (so, rt[1]->buffer, 0, rt_flags | NOUVEAU_BO_OR,
-                         nv40->nvws->channel->vram->handle,
-                         nv40->nvws->channel->gart->handle);
-               so_method(so, nv40->hw->curie, NV40TCL_COLOR1_OFFSET, 2);
-               so_reloc (so, rt[1]->buffer, rt[1]->offset, rt_flags |
-                         NOUVEAU_BO_LOW, 0, 0);
-               so_data  (so, rt[1]->pitch * rt[1]->cpp);
-       }
-
-       if (rt_enable & NV40TCL_RT_ENABLE_COLOR2) {
-               so_method(so, nv40->hw->curie, NV40TCL_DMA_COLOR2, 1);
-               so_reloc (so, rt[2]->buffer, 0, rt_flags | NOUVEAU_BO_OR,
-                         nv40->nvws->channel->vram->handle,
-                         nv40->nvws->channel->gart->handle);
-               so_method(so, nv40->hw->curie, NV40TCL_COLOR2_OFFSET, 1);
-               so_reloc (so, rt[2]->buffer, rt[2]->offset, rt_flags |
-                         NOUVEAU_BO_LOW, 0, 0);
-               so_method(so, nv40->hw->curie, NV40TCL_COLOR2_PITCH, 1);
-               so_data  (so, rt[2]->pitch * rt[2]->cpp);
-       }
-
-       if (rt_enable & NV40TCL_RT_ENABLE_COLOR3) {
-               so_method(so, nv40->hw->curie, NV40TCL_DMA_COLOR3, 1);
-               so_reloc (so, rt[3]->buffer, 0, rt_flags | NOUVEAU_BO_OR,
-                         nv40->nvws->channel->vram->handle,
-                         nv40->nvws->channel->gart->handle);
-               so_method(so, nv40->hw->curie, NV40TCL_COLOR3_OFFSET, 1);
-               so_reloc (so, rt[3]->buffer, rt[3]->offset, rt_flags |
-                         NOUVEAU_BO_LOW, 0, 0);
-               so_method(so, nv40->hw->curie, NV40TCL_COLOR3_PITCH, 1);
-               so_data  (so, rt[3]->pitch * rt[3]->cpp);
-       }
-
-       if (zeta_format) {
-               so_method(so, nv40->hw->curie, NV40TCL_DMA_ZETA, 1);
-               so_reloc (so, zeta->buffer, 0, rt_flags | NOUVEAU_BO_OR,
-                         nv40->nvws->channel->vram->handle,
-                         nv40->nvws->channel->gart->handle);
-               so_method(so, nv40->hw->curie, NV40TCL_ZETA_OFFSET, 1);
-               so_reloc (so, zeta->buffer, zeta->offset, rt_flags |
-                         NOUVEAU_BO_LOW, 0, 0);
-               so_method(so, nv40->hw->curie, NV40TCL_ZETA_PITCH, 1);
-               so_data  (so, zeta->pitch * zeta->cpp);
-       }
-
-       so_method(so, nv40->hw->curie, NV40TCL_RT_ENABLE, 1);
-       so_data  (so, rt_enable);
-       so_method(so, nv40->hw->curie, NV40TCL_RT_HORIZ, 3);
-       so_data  (so, (w << 16) | 0);
-       so_data  (so, (h << 16) | 0);
-       so_data  (so, rt_format);
-       so_method(so, nv40->hw->curie, NV40TCL_VIEWPORT_HORIZ, 2);
-       so_data  (so, (w << 16) | 0);
-       so_data  (so, (h << 16) | 0);
-       so_method(so, nv40->hw->curie, NV40TCL_VIEWPORT_CLIP_HORIZ(0), 2);
-       so_data  (so, ((w - 1) << 16) | 0);
-       so_data  (so, ((h - 1) << 16) | 0);
-
-       so_ref(so, &nv40->so_framebuffer);
-       so_ref(NULL, &so);
+       nv40->framebuffer = *fb;
        nv40->dirty |= NV40_NEW_FB;
 }
 
@@ -735,7 +630,7 @@ nv40_set_polygon_stipple(struct pipe_context *pipe,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       memcpy(nv40->pipe_state.stipple, stipple->stipple, 4 * 32);
+       memcpy(nv40->stipple, stipple->stipple, 4 * 32);
        nv40->dirty |= NV40_NEW_STIPPLE;
 }
 
@@ -745,7 +640,7 @@ nv40_set_scissor_state(struct pipe_context *pipe,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       nv40->pipe_state.scissor = *s;
+       nv40->scissor = *s;
        nv40->dirty |= NV40_NEW_SCISSOR;
 }
 
@@ -754,43 +649,46 @@ nv40_set_viewport_state(struct pipe_context *pipe,
                        const struct pipe_viewport_state *vpt)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
-       struct nouveau_stateobj *so = so_new(9, 0);
-
-       so_method(so, nv40->hw->curie, NV40TCL_VIEWPORT_TRANSLATE_X, 8);
-       so_data  (so, fui(vpt->translate[0]));
-       so_data  (so, fui(vpt->translate[1]));
-       so_data  (so, fui(vpt->translate[2]));
-       so_data  (so, fui(vpt->translate[3]));
-       so_data  (so, fui(vpt->scale[0]));
-       so_data  (so, fui(vpt->scale[1]));
-       so_data  (so, fui(vpt->scale[2]));
-       so_data  (so, fui(vpt->scale[3]));
-
-       so_ref(so, &nv40->so_viewport);
-       so_ref(NULL, &so);
+
+       nv40->viewport = *vpt;
        nv40->dirty |= NV40_NEW_VIEWPORT;
+       nv40->draw_dirty |= NV40_NEW_VIEWPORT;
 }
 
 static void
-nv40_set_vertex_buffer(struct pipe_context *pipe, unsigned index,
-                      const struct pipe_vertex_buffer *vb)
+nv40_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
+                       const struct pipe_vertex_buffer *vb)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       nv40->vtxbuf[index] = *vb;
+       memcpy(nv40->vtxbuf, vb, sizeof(*vb) * count);
+       nv40->vtxbuf_nr = count;
 
        nv40->dirty |= NV40_NEW_ARRAYS;
+       nv40->draw_dirty |= NV40_NEW_ARRAYS;
 }
 
 static void
-nv40_set_vertex_element(struct pipe_context *pipe, unsigned index,
-                       const struct pipe_vertex_element *ve)
+nv40_set_vertex_elements(struct pipe_context *pipe, unsigned count,
+                        const struct pipe_vertex_element *ve)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       nv40->vtxelt[index] = *ve;
+       memcpy(nv40->vtxelt, ve, sizeof(*ve) * count);
+       nv40->vtxelt_nr = count;
+
+       nv40->dirty |= NV40_NEW_ARRAYS;
+       nv40->draw_dirty |= NV40_NEW_ARRAYS;
+}
+
+static void
+nv40_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield)
+{
+       struct nv40_context *nv40 = nv40_context(pipe);
 
+       nv40->edgeflags = bitfield;
        nv40->dirty |= NV40_NEW_ARRAYS;
+       nv40->draw_dirty |= NV40_NEW_ARRAYS;
 }
 
 void
@@ -801,9 +699,9 @@ nv40_init_state_functions(struct nv40_context *nv40)
        nv40->pipe.delete_blend_state = nv40_blend_state_delete;
 
        nv40->pipe.create_sampler_state = nv40_sampler_state_create;
-       nv40->pipe.bind_sampler_state = nv40_sampler_state_bind;
+       nv40->pipe.bind_sampler_states = nv40_sampler_state_bind;
        nv40->pipe.delete_sampler_state = nv40_sampler_state_delete;
-       nv40->pipe.set_sampler_texture = nv40_set_sampler_texture;
+       nv40->pipe.set_sampler_textures = nv40_set_sampler_texture;
 
        nv40->pipe.create_rasterizer_state = nv40_rasterizer_state_create;
        nv40->pipe.bind_rasterizer_state = nv40_rasterizer_state_bind;
@@ -832,7 +730,8 @@ nv40_init_state_functions(struct nv40_context *nv40)
        nv40->pipe.set_scissor_state = nv40_set_scissor_state;
        nv40->pipe.set_viewport_state = nv40_set_viewport_state;
 
-       nv40->pipe.set_vertex_buffer = nv40_set_vertex_buffer;
-       nv40->pipe.set_vertex_element = nv40_set_vertex_element;
+       nv40->pipe.set_edgeflags = nv40_set_edgeflags;
+       nv40->pipe.set_vertex_buffers = nv40_set_vertex_buffers;
+       nv40->pipe.set_vertex_elements = nv40_set_vertex_elements;
 }