nv40: only update draw module state when using swtnl
authorBen Skeggs <skeggsb@gmail.com>
Wed, 2 Apr 2008 03:04:06 +0000 (13:04 +1000)
committerBen Skeggs <skeggsb@gmail.com>
Wed, 2 Apr 2008 03:04:06 +0000 (13:04 +1000)
src/gallium/drivers/nv40/nv40_context.h
src/gallium/drivers/nv40/nv40_state.c
src/gallium/drivers/nv40/nv40_state_emit.c

index b50f6f8fefcd8025d60d750e9814a198757414b5..525eef8d63dac44d77759ded24a24df5028ade3a 100644 (file)
@@ -133,7 +133,7 @@ struct nv40_context {
        unsigned fallback_swrast;
 
        /* Context state */
-       unsigned dirty;
+       unsigned dirty, draw_dirty;
        struct pipe_scissor_state scissor;
        unsigned stipple[32];
        struct pipe_clip_state clip;
@@ -153,8 +153,10 @@ struct nv40_context {
        unsigned nr_samplers;
        unsigned nr_textures;
        unsigned dirty_samplers;
-       struct pipe_vertex_buffer  vtxbuf[PIPE_ATTRIB_MAX];
+       struct pipe_vertex_buffer vtxbuf[PIPE_ATTRIB_MAX];
+       unsigned vtxbuf_nr;
        struct pipe_vertex_element vtxelt[PIPE_ATTRIB_MAX];
+       unsigned vtxelt_nr;
 };
 
 static INLINE struct nv40_context *
index 89f4078b720fa45b09faec3f5b3dc7bbb36d3f98..5dc2991212d39d256ea097022bfa983887a1d052 100644 (file)
@@ -423,10 +423,9 @@ nv40_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
        struct nv40_context *nv40 = nv40_context(pipe);
        struct nv40_rasterizer_state *rsso = hwcso;
 
-       draw_set_rasterizer_state(nv40->draw, &rsso->pipe);
-
        nv40->rasterizer = hwcso;
        nv40->dirty |= NV40_NEW_RAST;
+       nv40->draw_dirty |= NV40_NEW_RAST;
 }
 
 static void
@@ -530,10 +529,9 @@ nv40_vp_state_bind(struct pipe_context *pipe, void *hwcso)
        struct nv40_context *nv40 = nv40_context(pipe);
        struct nv40_vertex_program *vp = hwcso;
 
-       draw_bind_vertex_shader(nv40->draw, vp ? vp->draw : NULL);
-
        nv40->vertprog = hwcso;
        nv40->dirty |= NV40_NEW_VERTPROG;
+       nv40->draw_dirty |= NV40_NEW_VERTPROG;
 }
 
 static void
@@ -596,10 +594,9 @@ nv40_set_clip_state(struct pipe_context *pipe,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       draw_set_clip_state(nv40->draw, clip);
-
        nv40->clip = *clip;
        nv40->dirty |= NV40_NEW_UCP;
+       nv40->draw_dirty |= NV40_NEW_UCP;
 }
 
 static void
@@ -654,10 +651,9 @@ nv40_set_viewport_state(struct pipe_context *pipe,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       draw_set_viewport_state(nv40->draw, vpt);
-
        nv40->viewport = *vpt;
        nv40->dirty |= NV40_NEW_VIEWPORT;
+       nv40->draw_dirty |= NV40_NEW_VIEWPORT;
 }
 
 static void
@@ -666,10 +662,11 @@ nv40_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       draw_set_vertex_buffers(nv40->draw, count, 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
@@ -678,10 +675,11 @@ nv40_set_vertex_elements(struct pipe_context *pipe, unsigned count,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
 
-       draw_set_vertex_elements(nv40->draw, count, ve);
-
        memcpy(nv40->vtxelt, ve, sizeof(*ve) * count);
+       nv40->vtxelt_nr = count;
+
        nv40->dirty |= NV40_NEW_ARRAYS;
+       nv40->draw_dirty |= NV40_NEW_ARRAYS;
 }
 
 void
index 74feb6d4bfc5c7b42ae071105aaf2a0972491a1f..722b9f31e6df2af27b933f372227a794de289e14 100644 (file)
@@ -144,6 +144,8 @@ nv40_state_validate(struct nv40_context *nv40)
 boolean
 nv40_state_validate_swtnl(struct nv40_context *nv40)
 {
+       struct draw_context *draw = nv40->draw;
+
        /* Setup for swtnl */
        if (nv40->render_mode == HW) {
                NOUVEAU_ERR("hw->swtnl 0x%08x\n", nv40->fallback_swtnl);
@@ -155,12 +157,30 @@ nv40_state_validate_swtnl(struct nv40_context *nv40)
                nv40->render_mode = SWTNL;
        }
 
+       if (nv40->draw_dirty & NV40_NEW_VERTPROG)
+               draw_bind_vertex_shader(draw, nv40->vertprog->draw);
+
+       if (nv40->draw_dirty & NV40_NEW_RAST)
+               draw_set_rasterizer_state(draw, &nv40->rasterizer->pipe);
+
+       if (nv40->draw_dirty & NV40_NEW_UCP)
+               draw_set_clip_state(draw, &nv40->clip);
+
+       if (nv40->draw_dirty & NV40_NEW_VIEWPORT)
+               draw_set_viewport_state(draw, &nv40->viewport);
+
+       if (nv40->draw_dirty & NV40_NEW_ARRAYS) {
+               draw_set_vertex_buffers(draw, nv40->vtxbuf_nr, nv40->vtxbuf);
+               draw_set_vertex_elements(draw, nv40->vtxelt_nr, nv40->vtxelt);  
+       }
+
        nv40_state_do_validate(nv40, swtnl_states);
        if (nv40->fallback_swrast) {
                NOUVEAU_ERR("swtnl->swrast 0x%08x\n", nv40->fallback_swrast);
                return FALSE;
        }
 
+       nv40->draw_dirty = 0;
        return TRUE;
 }