nv30: Emit fragment program using state objects
[mesa.git] / src / gallium / drivers / nv30 / nv30_state_emit.c
index 7d77adbfdf0ad97bc04d18d681c1beee4375ce69..c4ccc9422be744337cabf05a7722285ef6d79460 100644 (file)
@@ -4,8 +4,15 @@
 static struct nv30_state_entry *render_states[] = {
        &nv30_state_framebuffer,
        &nv30_state_rasterizer,
+       &nv30_state_scissor,
+       &nv30_state_stipple,
+       &nv30_state_fragprog,
+       &nv30_state_fragtex,
+       &nv30_state_vertprog,
        &nv30_state_blend,
        &nv30_state_blend_colour,
+       &nv30_state_zsa,
+       &nv30_state_viewport,
        NULL
 };
 
@@ -42,9 +49,19 @@ void
 nv30_emit_hw_state(struct nv30_context *nv30)
 {
        struct nv30_state *state = &nv30->state;
-       unsigned i;
+       struct nv30_screen *screen = nv30->screen;
+       unsigned i, samplers;
        uint64 states;
 
+       if (nv30->pctx_id != screen->cur_pctx) {
+               for (i = 0; i < NV30_STATE_MAX; i++) {
+                       if (state->hw[i] && screen->state[i] != state->hw[i])
+                               state->dirty |= (1ULL << i);
+               }
+
+               screen->cur_pctx = nv30->pctx_id;
+       }
+
        for (i = 0, states = state->dirty; states; i++) {
                if (!(states & (1ULL << i)))
                        continue;
@@ -54,51 +71,15 @@ nv30_emit_hw_state(struct nv30_context *nv30)
                states &= ~(1ULL << i);
        }
 
-       if (nv30->dirty & NV30_NEW_FRAGPROG) {
-               nv30_fragprog_bind(nv30, nv30->fragprog.current);
-               /*XXX: clear NV30_NEW_FRAGPROG if no new program uploaded */
-       }
-
-       if (nv30->dirty_samplers || (nv30->dirty & NV30_NEW_FRAGPROG)) {
-               nv30_fragtex_bind(nv30);
-/*
-               BEGIN_RING(rankine, NV34TCL_TX_CACHE_CTL, 1);
-               OUT_RING  (2);
-               BEGIN_RING(rankine, NV34TCL_TX_CACHE_CTL, 1);
-               OUT_RING  (1);*/
-               nv30->dirty &= ~NV30_NEW_FRAGPROG;
-       }
-
-       if (nv30->dirty & NV30_NEW_VERTPROG) {
-               nv30_vertprog_bind(nv30, nv30->vertprog.current);
-               nv30->dirty &= ~NV30_NEW_VERTPROG;
-       }
-
-       nv30->dirty_samplers = 0;
-
        so_emit_reloc_markers(nv30->nvws, state->hw[NV30_STATE_FB]);
-
-       /* Texture images, emitted in nv30_fragtex_build */
-#if 0
-       for (i = 0; i < 16; i++) {
-               if (!(nv30->fp_samplers & (1 << i)))
+       for (i = 0, samplers = state->fp_samplers; i < 16 && samplers; i++) {
+               if (!(samplers & (1 << i)))
                        continue;
-               BEGIN_RING(rankine, NV34TCL_TX_OFFSET(i), 2);
-               OUT_RELOCl(nv30->tex[i].buffer, 0, NOUVEAU_BO_VRAM |
-                          NOUVEAU_BO_GART | NOUVEAU_BO_RD);
-               OUT_RELOCd(nv30->tex[i].buffer, nv30->tex[i].format,
-                          NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD |
-                          NOUVEAU_BO_OR, NV34TCL_TX_FORMAT_DMA0,
-                          NV34TCL_TX_FORMAT_DMA1);
+               so_emit_reloc_markers(nv30->nvws,
+                                     state->hw[NV30_STATE_FRAGTEX0+i]);
+               samplers &= ~(1ULL << i);
        }
-#endif
-
-       /* Fragment program */
-       BEGIN_RING(rankine, NV34TCL_FP_ACTIVE_PROGRAM, 1);
-       OUT_RELOC (nv30->fragprog.active->buffer, 0, NOUVEAU_BO_VRAM |
-                  NOUVEAU_BO_GART | NOUVEAU_BO_RD | NOUVEAU_BO_LOW |
-                  NOUVEAU_BO_OR, NV34TCL_FP_ACTIVE_PROGRAM_DMA0,
-                  NV34TCL_FP_ACTIVE_PROGRAM_DMA1);
+       so_emit_reloc_markers(nv30->nvws, state->hw[NV30_STATE_FRAGPROG]);
 }
 
 boolean