nv30: Move constant buffers out of vert/frag prog structures
authorPatrice Mandin <pmandin@caramail.com>
Fri, 11 Jul 2008 21:17:47 +0000 (23:17 +0200)
committerPatrice Mandin <pmandin@caramail.com>
Fri, 11 Jul 2008 21:17:47 +0000 (23:17 +0200)
src/gallium/drivers/nv30/nv30_context.h
src/gallium/drivers/nv30/nv30_fragprog.c
src/gallium/drivers/nv30/nv30_state.c
src/gallium/drivers/nv30/nv30_vertprog.c

index 72f803c80ad12c5b95b6ed8f3ed8ca788a4024bf..c3c8b733090c62324ca8055e5152ca5b7a943e75 100644 (file)
@@ -124,6 +124,8 @@ struct nv30_context {
        unsigned dirty;
        struct pipe_scissor_state scissor;
        unsigned stipple[32];
+       struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
+       unsigned constbuf_nr[PIPE_SHADER_TYPES];
        struct nv30_rasterizer_state *rasterizer;
        struct nv30_zsa_state *zsa;
        struct nv30_blend_state *blend;
@@ -150,16 +152,12 @@ struct nv30_context {
 
        struct {
                struct nv30_vertex_program *active;
-
                struct nv30_vertex_program *current;
-               struct pipe_buffer *constant_buf;
        } vertprog;
 
        struct {
                struct nv30_fragment_program *active;
-
                struct nv30_fragment_program *current;
-               struct pipe_buffer *constant_buf;
        } fragprog;
 
        struct pipe_vertex_buffer  vtxbuf[PIPE_MAX_ATTRIBS];
index 6af86e4f4f9b3dd3125a8a4b1c421e9d4bbb40f2..b560455a02f99691e689555e4d3a25a887de696d 100644 (file)
@@ -820,6 +820,8 @@ nv30_fragprog_upload(struct nv30_context *nv30,
 void
 nv30_fragprog_bind(struct nv30_context *nv30, struct nv30_fragment_program *fp)
 {
+       struct pipe_buffer *constbuf =
+               nv30->constbuf[PIPE_SHADER_FRAGMENT];
        struct pipe_winsys *ws = nv30->pipe.winsys;
        int i;
 
@@ -830,8 +832,9 @@ nv30_fragprog_bind(struct nv30_context *nv30, struct nv30_fragment_program *fp)
        }
 
        if (fp->nr_consts) {
-               float *map = ws->buffer_map(ws, nv30->fragprog.constant_buf,
-                                           PIPE_BUFFER_USAGE_CPU_READ);
+               float *map;
+
+               map = ws->buffer_map(ws, constbuf, PIPE_BUFFER_USAGE_CPU_READ);
                for (i = 0; i < fp->nr_consts; i++) {
                        struct nv30_fragment_program_data *fpd = &fp->consts[i];
                        uint32_t *p = &fp->insn[fpd->offset];
@@ -842,13 +845,10 @@ nv30_fragprog_bind(struct nv30_context *nv30, struct nv30_fragment_program *fp)
                        memcpy(p, cb, 4 * sizeof(float));
                        fp->on_hw = 0;
                }
-               ws->buffer_unmap(ws, nv30->fragprog.constant_buf);
+               ws->buffer_unmap(ws, constbuf);
        }
 
        if (!fp->on_hw) {
-               const uint32_t le = 1;
-               uint32_t *map;
-
                if (!fp->buffer)
                        fp->buffer = ws->buffer_create(ws, 0x100, 0,
                                                       fp->insn_len * 4);
index 72b9515eb1afcfb01cf104016273b1cfabfe78c2..aec6fa2b1556532f3960f7213aaf3956592bec5f 100644 (file)
@@ -589,12 +589,13 @@ nv30_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
 {
        struct nv30_context *nv30 = nv30_context(pipe);
 
+       nv30->constbuf[shader] = buf->buffer;
+       nv30->constbuf_nr[shader] = buf->size / (4 * sizeof(float));
+
        if (shader == PIPE_SHADER_VERTEX) {
-               nv30->vertprog.constant_buf = buf->buffer;
                nv30->dirty |= NV30_NEW_VERTPROG;
        } else
        if (shader == PIPE_SHADER_FRAGMENT) {
-               nv30->fragprog.constant_buf = buf->buffer;
                nv30->dirty |= NV30_NEW_FRAGPROG;
        }
 }
index 1b34d2e4b29e21cde5973fcfc3a947d979c1639a..90756febd28e0ddd484b0c8526a668ac33bd1e95 100644 (file)
@@ -135,7 +135,7 @@ emit_src(struct nv30_vpc *vpc, uint32_t *hw, int pos, struct nv30_sreg src)
 
 /*
  * |VVV|
- * d°.°b
+ * d�.�b
  *  \u/
  *
  */
@@ -641,9 +641,12 @@ nv30_vertprog_bind(struct nv30_context *nv30, struct nv30_vertex_program *vp)
 { 
        struct nouveau_winsys *nvws = nv30->nvws;
        struct pipe_winsys *ws = nv30->pipe.winsys;
+       struct pipe_buffer *constbuf;
        boolean upload_code = FALSE, upload_data = FALSE;
        int i;
 
+       constbuf = nv30->constbuf[PIPE_SHADER_VERTEX];
+
        /* Translate TGSI shader into hw bytecode */
        if (!vp->translated) {
                nv30_vertprog_translate(nv30, vp);
@@ -730,8 +733,8 @@ nv30_vertprog_bind(struct nv30_context *nv30, struct nv30_vertex_program *vp)
        if (vp->nr_consts) {
                float *map = NULL;
 
-               if (nv30->vertprog.constant_buf) {
-                       map = ws->buffer_map(ws, nv30->vertprog.constant_buf,
+               if (constbuf) {
+                       map = ws->buffer_map(ws, constbuf,
                                             PIPE_BUFFER_USAGE_CPU_READ);
                }
 
@@ -750,15 +753,10 @@ nv30_vertprog_bind(struct nv30_context *nv30, struct nv30_vertex_program *vp)
                        BEGIN_RING(rankine, NV34TCL_VP_UPLOAD_CONST_ID, 5);
                        OUT_RING  (i + vp->data->start);
                        OUT_RINGp ((uint32_t *)vpd->value, 4);
-#if 0
-                       NOUVEAU_MSG("VP const %d: %f %f %f %f\n",
-                               i, vpd->value[0], vpd->value[1],
-                               vpd->value[2], vpd->value[3]);
-#endif
                }
 
-               if (map) {
-                       ws->buffer_unmap(ws, nv30->vertprog.constant_buf);
+               if (constbuf) {
+                       ws->buffer_unmap(ws, constbuf);
                }
        }