nv40: Do all fp setup in nv40_fragprog.c
authorBen Skeggs <skeggsb@gmail.com>
Thu, 13 Dec 2007 14:51:43 +0000 (01:51 +1100)
committerBen Skeggs <skeggsb@gmail.com>
Thu, 13 Dec 2007 14:51:43 +0000 (01:51 +1100)
src/mesa/pipe/nv40/nv40_fragprog.c
src/mesa/pipe/nv40/nv40_state_emit.c

index bad5f0020ebace8ff0f53751590d7463c4b0397b..a0d98ae4dcc7034bc441726a34cc75fa724c175c 100644 (file)
@@ -701,10 +701,34 @@ nv40_fragprog_bind(struct nv40_context *nv40, struct nv40_fragment_program *fp)
 {
        struct pipe_winsys *ws = nv40->pipe.winsys;
        uint32_t fp_control;
+       int i;
 
        if (!fp->translated) {
-               NOUVEAU_ERR("fragprog invalid, using passthrough shader\n");
-               fp = &passthrough_fp;
+               nv40_fragprog_translate(nv40, fp);
+               if (!fp->translated) {
+                       NOUVEAU_ERR("invalid, using passthrough shader\n");
+                       fp = &passthrough_fp;
+               }
+       }
+
+       if (fp->num_consts) {
+               float *map = ws->buffer_map(ws, nv40->fragprog.constant_buf,
+                                           PIPE_BUFFER_FLAG_READ);
+               for (i = 0; i < fp->num_consts; i++) {
+                       uint pid = fp->consts[i].pipe_id;
+
+                       if (pid == -1)
+                               continue;
+
+                       if (!memcmp(&fp->insn[fp->consts[i].hw_id], &map[pid*4],
+                                   4 * sizeof(float)))
+                               continue;
+
+                       memcpy(&fp->insn[fp->consts[i].hw_id], &map[pid*4],
+                              4 * sizeof(float));
+                       fp->on_hw = 0;
+               }
+               ws->buffer_unmap(ws, nv40->fragprog.constant_buf);
        }
 
        if (!fp->on_hw) {
@@ -712,7 +736,6 @@ nv40_fragprog_bind(struct nv40_context *nv40, struct nv40_fragment_program *fp)
                        fp->buffer = ws->buffer_create(ws, 0x100, 0, 0);
 
 #if 0
-               int i;
                for (i = 0; i < fp->insn_len; i++)
                        NOUVEAU_ERR("%d 0x%08x\n", i, fp->insn[i]);
 #endif
index 55c7d36b12902276035394435824c8061d9041f5..fb2a3cb98e9b8a2cd252476d93f1f844052e60b2 100644 (file)
@@ -2,53 +2,12 @@
 #include "nv40_dma.h"
 #include "nv40_state.h"
 
-static INLINE void
-nv40_state_update_fragprog(struct nv40_context *nv40)
-{
-       struct pipe_context *pipe = (struct pipe_context *)nv40;
-       struct nv40_fragment_program *fp = nv40->fragprog.current;
-       float *map;
-       int i;
-
-       if (!fp->translated)
-               nv40_fragprog_translate(nv40, fp);
-
-       if (fp->num_consts) {
-               map = pipe->winsys->buffer_map(pipe->winsys,
-                                              nv40->fragprog.constant_buf,
-                                              PIPE_BUFFER_FLAG_READ);
-               for (i = 0; i < fp->num_consts; i++) {
-                       uint pid = fp->consts[i].pipe_id;
-
-                       if (pid == -1)
-                               continue;
-
-                       if (!memcmp(&fp->insn[fp->consts[i].hw_id], &map[pid*4],
-                                   4 * sizeof(float)))
-                               continue;
-
-                       memcpy(&fp->insn[fp->consts[i].hw_id], &map[pid*4],
-                              4 * sizeof(float));
-                       fp->on_hw = 0;
-               }
-               pipe->winsys->buffer_unmap(pipe->winsys,
-                                          nv40->fragprog.constant_buf);
-       }
-}
-
 void
 nv40_emit_hw_state(struct nv40_context *nv40)
 {
        if (nv40->dirty & NV40_NEW_FRAGPROG) {
-               struct nv40_fragment_program *cur = nv40->fragprog.current;
-
-               nv40_state_update_fragprog(nv40);
-       
-               if (cur->on_hw)
-                       nv40->dirty &= ~NV40_NEW_FRAGPROG;
-
-               if (!cur->on_hw || cur != nv40->fragprog.active)
-                       nv40_fragprog_bind(nv40, cur);
+               nv40_fragprog_bind(nv40, nv40->fragprog.current);
+               /*XXX: clear NV40_NEW_FRAGPROG if no now program uploaded */
        }
 
        if (nv40->dirty & NV40_NEW_TEXTURE)
@@ -62,8 +21,10 @@ nv40_emit_hw_state(struct nv40_context *nv40)
                nv40->dirty &= ~(NV40_NEW_TEXTURE | NV40_NEW_FRAGPROG);
        }
 
-       if (nv40->dirty & NV40_NEW_VERTPROG)
+       if (nv40->dirty & NV40_NEW_VERTPROG) {
                nv40_vertprog_bind(nv40, nv40->vertprog.current);
+               nv40->dirty &= ~NV40_NEW_VERTPROG;
+       }
 
        if (nv40->dirty & NV40_NEW_ARRAYS) {
                nv40_vbo_arrays_update(nv40);