Merge branch 'upstream-gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / mesa / pipe / nv40 / nv40_vbo.c
index e2cb3fda8f21397c872a81590143d251668c52a5..6b1ac65b49e7040dd7c8d640a9323c9426c38d82 100644 (file)
@@ -30,7 +30,8 @@ nv40_vbo_type(uint format)
        case PIPE_FORMAT_TYPE_UNORM:
                return NV40TCL_VTXFMT_TYPE_UBYTE;
        default:
-               assert(0);
+               NOUVEAU_ERR("Unknown format 0x%08x\n", format);
+               return NV40TCL_VTXFMT_TYPE_FLOAT;
        }
 }
 
@@ -115,9 +116,9 @@ nv40_vbo_arrays_update(struct nv40_context *nv40, struct pipe_buffer *ib,
        num_hw++;
 
        vtxbuf = so_new(20, 18);
-       so_method(vtxbuf, nv40->curie, NV40TCL_VTXBUF_ADDRESS(0), num_hw);
+       so_method(vtxbuf, nv40->hw->curie, NV40TCL_VTXBUF_ADDRESS(0), num_hw);
        vtxfmt = so_new(17, 0);
-       so_method(vtxfmt, nv40->curie, NV40TCL_VTXFMT(0), num_hw);
+       so_method(vtxfmt, nv40->hw->curie, NV40TCL_VTXFMT(0), num_hw);
 
        inputs = vp->ir;
        for (hw = 0; hw < num_hw; hw++) {
@@ -149,7 +150,7 @@ nv40_vbo_arrays_update(struct nv40_context *nv40, struct pipe_buffer *ib,
        }
 
        if (ib) {
-               so_method(vtxbuf, nv40->curie, NV40TCL_IDXBUF_ADDRESS, 2);
+               so_method(vtxbuf, nv40->hw->curie, NV40TCL_IDXBUF_ADDRESS, 2);
                so_reloc (vtxbuf, ib, 0, vb_flags | NOUVEAU_BO_LOW, 0, 0);
                so_reloc (vtxbuf, ib, ib_format, vb_flags | NOUVEAU_BO_OR,
                          0, NV40TCL_IDXBUF_FORMAT_DMA1);
@@ -158,6 +159,7 @@ nv40_vbo_arrays_update(struct nv40_context *nv40, struct pipe_buffer *ib,
        so_emit(nv40->nvws, vtxfmt);
        so_emit(nv40->nvws, vtxbuf);
        so_ref (vtxbuf, &nv40->so_vtxbuf);
+       so_ref (NULL, &vtxbuf);
        so_ref (NULL, &vtxfmt);
 }
 
@@ -165,8 +167,10 @@ static boolean
 nv40_vbo_validate_state(struct nv40_context *nv40,
                        struct pipe_buffer *ib, unsigned ib_format)
 {
+       unsigned vdn = nv40->dirty & NV40_NEW_ARRAYS;
+
        nv40_emit_hw_state(nv40);
-       if (nv40->dirty & NV40_NEW_ARRAYS || ib) {
+       if (vdn || ib) {
                nv40_vbo_arrays_update(nv40, ib, ib_format);
                nv40->dirty &= ~NV40_NEW_ARRAYS;
        }
@@ -185,8 +189,13 @@ nv40_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
        unsigned nr;
+       boolean ret;
 
-       assert(nv40_vbo_validate_state(nv40, NULL, 0));
+       ret = nv40_vbo_validate_state(nv40, NULL, 0);
+       if (!ret) {
+               NOUVEAU_ERR("state validate failed\n");
+               return FALSE;
+       }
 
        BEGIN_RING(curie, NV40TCL_BEGIN_END, 1);
        OUT_RING  (nvgl_primitive(mode));
@@ -232,9 +241,9 @@ nv40_draw_elements_u08(struct nv40_context *nv40, void *ib,
        }
 
        while (count) {
-               push = MIN2(count, 2046);
+               push = MIN2(count, 2047 * 2);
 
-               BEGIN_RING_NI(curie, NV40TCL_VB_ELEMENT_U16, push);
+               BEGIN_RING_NI(curie, NV40TCL_VB_ELEMENT_U16, push >> 1);
                for (i = 0; i < push; i+=2)
                        OUT_RING((elts[i+1] << 16) | elts[i]);
 
@@ -257,9 +266,9 @@ nv40_draw_elements_u16(struct nv40_context *nv40, void *ib,
        }
 
        while (count) {
-               push = MIN2(count, 2046);
+               push = MIN2(count, 2047 * 2);
 
-               BEGIN_RING_NI(curie, NV40TCL_VB_ELEMENT_U16, push);
+               BEGIN_RING_NI(curie, NV40TCL_VB_ELEMENT_U16, push >> 1);
                for (i = 0; i < push; i+=2)
                        OUT_RING((elts[i+1] << 16) | elts[i]);
 
@@ -293,13 +302,20 @@ nv40_draw_elements_inline(struct pipe_context *pipe,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
        struct pipe_winsys *ws = pipe->winsys;
+       boolean ret;
        void *map;
 
-       assert(nv40_vbo_validate_state(nv40, NULL, 0));
+       ret = nv40_vbo_validate_state(nv40, NULL, 0);
+       if (!ret) {
+               NOUVEAU_ERR("state validate failed\n");
+               return FALSE;
+       }
 
        map = ws->buffer_map(ws, ib, PIPE_BUFFER_USAGE_CPU_READ);
-       if (!ib)
-               assert(0);
+       if (!ib) {
+               NOUVEAU_ERR("failed mapping ib\n");
+               return FALSE;
+       }
 
        BEGIN_RING(curie, NV40TCL_BEGIN_END, 1);
        OUT_RING  (nvgl_primitive(mode));
@@ -315,7 +331,7 @@ nv40_draw_elements_inline(struct pipe_context *pipe,
                nv40_draw_elements_u32(nv40, map, start, count);
                break;
        default:
-               assert(0);
+               NOUVEAU_ERR("invalid idxbuf fmt %d\n", ib_size);
                break;
        }
 
@@ -334,6 +350,7 @@ nv40_draw_elements_vbo(struct pipe_context *pipe,
 {
        struct nv40_context *nv40 = nv40_context(pipe);
        unsigned nr, type;
+       boolean ret;
 
        switch (ib_size) {
        case 2:
@@ -343,10 +360,15 @@ nv40_draw_elements_vbo(struct pipe_context *pipe,
                type = NV40TCL_IDXBUF_FORMAT_TYPE_U32;
                break;
        default:
-               assert(0);
+               NOUVEAU_ERR("invalid idxbuf fmt %d\n", ib_size);
+               return FALSE;
        }
 
-       assert(nv40_vbo_validate_state(nv40, ib, type));
+       ret = nv40_vbo_validate_state(nv40, ib, type);
+       if (!ret) {
+               NOUVEAU_ERR("failed state validation\n");
+               return FALSE;
+       }
 
        BEGIN_RING(curie, NV40TCL_BEGIN_END, 1);
        OUT_RING  (nvgl_primitive(mode));
@@ -387,7 +409,7 @@ nv40_draw_elements(struct pipe_context *pipe,
        /* 0x4497 doesn't support real index buffers, and there doesn't appear
         * to be support on any chipset for 8-bit indices.
         */
-       if (nv40->curie->grclass == NV44TCL || indexSize == 1) {
+       if (nv40->hw->curie->grclass == NV44TCL || indexSize == 1) {
                nv40_draw_elements_inline(pipe, indexBuffer, indexSize,
                                          mode, start, count);
        } else {