nv40: fix non-debug builds + start on obeying portability guidelines.
authorBen Skeggs <skeggsb@gmail.com>
Fri, 15 Feb 2008 15:30:56 +0000 (02:30 +1100)
committerBen Skeggs <skeggsb@gmail.com>
Fri, 15 Feb 2008 15:31:52 +0000 (02:31 +1100)
src/mesa/pipe/nouveau/nouveau_stateobj.h
src/mesa/pipe/nv40/nv40_context.c
src/mesa/pipe/nv40/nv40_context.h
src/mesa/pipe/nv40/nv40_fragprog.c
src/mesa/pipe/nv40/nv40_miptree.c
src/mesa/pipe/nv40/nv40_query.c
src/mesa/pipe/nv40/nv40_state.c
src/mesa/pipe/nv40/nv40_vbo.c
src/mesa/pipe/nv40/nv40_vertprog.c

index 58167a2..07c31b0 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __NOUVEAU_STATEOBJ_H__
 #define __NOUVEAU_STATEOBJ_H__
 
+#include "pipe/p_util.h"
+
 struct nouveau_stateobj_reloc {
        struct pipe_buffer *bo;
 
@@ -24,15 +26,15 @@ struct nouveau_stateobj {
        unsigned cur_reloc;
 };
 
-static inline struct nouveau_stateobj *
+static INLINE struct nouveau_stateobj *
 so_new(unsigned push, unsigned reloc)
 {
        struct nouveau_stateobj *so;
 
-       so = malloc(sizeof(struct nouveau_stateobj));
+       so = MALLOC(sizeof(struct nouveau_stateobj));
        so->refcount = 1;
-       so->push = malloc(sizeof(unsigned) * push);
-       so->reloc = malloc(sizeof(struct nouveau_stateobj_reloc) * reloc);
+       so->push = MALLOC(sizeof(unsigned) * push);
+       so->reloc = MALLOC(sizeof(struct nouveau_stateobj_reloc) * reloc);
 
        so->cur = so->push;
        so->cur_reloc = so->cur_packet = 0;
@@ -40,7 +42,7 @@ so_new(unsigned push, unsigned reloc)
        return so;
 }
 
-static inline void
+static INLINE void
 so_ref(struct nouveau_stateobj *ref, struct nouveau_stateobj **pso)
 {
        struct nouveau_stateobj *so;
@@ -61,14 +63,14 @@ so_ref(struct nouveau_stateobj *ref, struct nouveau_stateobj **pso)
        }
 }
 
-static inline void
+static INLINE void
 so_data(struct nouveau_stateobj *so, unsigned data)
 {
        (*so->cur++) = (data);
        so->cur_packet += 4;
 }
 
-static inline void
+static INLINE void
 so_method(struct nouveau_stateobj *so, struct nouveau_grobj *gr,
          unsigned mthd, unsigned size)
 {
@@ -76,7 +78,7 @@ so_method(struct nouveau_stateobj *so, struct nouveau_grobj *gr,
        so_data(so, (gr->subc << 13) | (size << 18) | mthd);
 }
 
-static inline void
+static INLINE void
 so_reloc(struct nouveau_stateobj *so, struct pipe_buffer *bo,
         unsigned data, unsigned flags, unsigned vor, unsigned tor)
 {
@@ -92,7 +94,7 @@ so_reloc(struct nouveau_stateobj *so, struct pipe_buffer *bo,
        so_data(so, data);
 }
 
-static inline void
+static INLINE void
 so_emit(struct nouveau_winsys *nvws, struct nouveau_stateobj *so)
 {
        struct nouveau_pushbuf *pb = nvws->channel->pushbuf;
@@ -113,7 +115,7 @@ so_emit(struct nouveau_winsys *nvws, struct nouveau_stateobj *so)
        pb->cur += nr;
 }
 
-static inline void
+static INLINE void
 so_emit_reloc_markers(struct nouveau_winsys *nvws, struct nouveau_stateobj *so)
 {
        struct nouveau_pushbuf *pb = nvws->channel->pushbuf;
index a8a2eaf..6e86ca0 100644 (file)
@@ -154,7 +154,7 @@ nv40_channel_init(struct pipe_winsys *ws, struct nouveau_winsys *nvws,
                return NULL;
        }
 
-       cnv40 = calloc(1, sizeof(struct nv40_channel_context));
+       cnv40 = CALLOC(1, sizeof(struct nv40_channel_context));
        if (!cnv40)
                return NULL;
        cnv40->chipset = chipset;
@@ -274,7 +274,7 @@ nv40_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws,
 {
        struct nv40_context *nv40;
 
-       nv40 = calloc(1, sizeof(struct nv40_context));
+       nv40 = CALLOC(1, sizeof(struct nv40_context));
        if (!nv40)
                return NULL;
 
index d7c9ee7..cf2a144 100644 (file)
@@ -100,7 +100,7 @@ struct nv40_context {
        struct pipe_vertex_element vtxelt[PIPE_ATTRIB_MAX];
 };
 
-static inline struct nv40_context *
+static INLINE struct nv40_context *
 nv40_context(struct pipe_context *pipe)
 {
        return (struct nv40_context *)pipe;
index cc637f5..7487fb8 100644 (file)
@@ -675,7 +675,7 @@ nv40_fragprog_translate(struct nv40_context *nv40,
        struct tgsi_parse_context parse;
        struct nv40_fpc *fpc = NULL;
 
-       fpc = calloc(1, sizeof(struct nv40_fpc));
+       fpc = CALLOC(1, sizeof(struct nv40_fpc));
        if (!fpc)
                return;
        fpc->fp = fp;
index 1b3c27d..92e6b3a 100644 (file)
@@ -35,7 +35,7 @@ nv40_miptree_layout(struct nv40_miptree *nv40mt)
                nv40mt->level[l].pitch = (nv40mt->level[l].pitch + 63) & ~63;
 
                nv40mt->level[l].image_offset =
-                       calloc(nr_faces, sizeof(unsigned));
+                       CALLOC(nr_faces, sizeof(unsigned));
 
                width  = MAX2(1, width  >> 1);
                height = MAX2(1, height >> 1);
@@ -59,7 +59,7 @@ nv40_miptree_create(struct pipe_context *pipe, const struct pipe_texture *pt)
        struct pipe_winsys *ws = pipe->winsys;
        struct nv40_miptree *mt;
 
-       mt = malloc(sizeof(struct nv40_miptree));
+       mt = MALLOC(sizeof(struct nv40_miptree));
        if (!mt)
                return NULL;
        mt->base = *pt;
index eb305e6..8bca278 100644 (file)
@@ -9,7 +9,7 @@ struct nv40_query {
        uint64_t result;
 };
 
-static inline struct nv40_query *
+static INLINE struct nv40_query *
 nv40_query(struct pipe_query *pipe)
 {
        return (struct nv40_query *)pipe;
@@ -20,7 +20,7 @@ nv40_query_create(struct pipe_context *pipe, unsigned query_type)
 {
        struct nv40_query *q;
 
-       q = calloc(1, sizeof(struct nv40_query));
+       q = CALLOC(1, sizeof(struct nv40_query));
        q->type = query_type;
 
        return (struct pipe_query *)q;
index bcd2445..713f31d 100644 (file)
@@ -112,7 +112,7 @@ nv40_sampler_state_create(struct pipe_context *pipe,
        struct nv40_sampler_state *ps;
        uint32_t filter = 0;
 
-       ps = malloc(sizeof(struct nv40_sampler_state));
+       ps = MALLOC(sizeof(struct nv40_sampler_state));
 
        ps->fmt = 0;
        if (!cso->normalized_coords)
@@ -455,7 +455,7 @@ nv40_vp_state_create(struct pipe_context *pipe,
 {
        struct nv40_vertex_program *vp;
 
-       vp = calloc(1, sizeof(struct nv40_vertex_program));
+       vp = CALLOC(1, sizeof(struct nv40_vertex_program));
        vp->pipe = cso;
 
        return (void *)vp;
@@ -487,7 +487,7 @@ nv40_fp_state_create(struct pipe_context *pipe,
 {
        struct nv40_fragment_program *fp;
 
-       fp = calloc(1, sizeof(struct nv40_fragment_program));
+       fp = CALLOC(1, sizeof(struct nv40_fragment_program));
        fp->pipe = cso;
 
        return (void *)fp;
index 4e9cdb4..a18d0f9 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;
        }
 }
 
@@ -188,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));
@@ -290,19 +296,26 @@ nv40_draw_elements_u32(struct nv40_context *nv40, void *ib,
 }
 
 static boolean
-nv40_draw_elements_inline(struct pipe_context *pipe,
+nv40_draw_elements_INLINE(struct pipe_context *pipe,
                          struct pipe_buffer *ib, unsigned ib_size,
                          unsigned mode, unsigned start, unsigned count)
 {
        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));
@@ -318,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;
        }
 
@@ -337,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:
@@ -346,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));
@@ -391,7 +410,7 @@ nv40_draw_elements(struct pipe_context *pipe,
         * to be support on any chipset for 8-bit indices.
         */
        if (nv40->hw->curie->grclass == NV44TCL || indexSize == 1) {
-               nv40_draw_elements_inline(pipe, indexBuffer, indexSize,
+               nv40_draw_elements_INLINE(pipe, indexBuffer, indexSize,
                                          mode, start, count);
        } else {
                nv40_draw_elements_vbo(pipe, indexBuffer, indexSize,
index 415b3c7..d57e3ca 100644 (file)
@@ -551,7 +551,7 @@ nv40_vertprog_prepare(struct nv40_vpc *vpc)
        tgsi_parse_free(&p);
 
        if (nr_imm) {
-               vpc->imm = calloc(nr_imm, sizeof(struct nv40_sreg));
+               vpc->imm = CALLOC(nr_imm, sizeof(struct nv40_sreg));
                assert(vpc->imm);
        }
 
@@ -565,7 +565,7 @@ nv40_vertprog_translate(struct nv40_context *nv40,
        struct tgsi_parse_context parse;
        struct nv40_vpc *vpc = NULL;
 
-       vpc = calloc(1, sizeof(struct nv40_vpc));
+       vpc = CALLOC(1, sizeof(struct nv40_vpc));
        if (!vpc)
                return;
        vpc->vp = vp;