i965: Rename do_<stage>_prog to brw_compile_<stage>_prog (and export)
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_render_t.c
index c0505781cfebd05722165ca3b409e972ec1aff66..1625a87223ff2bcd60c22b8e2d6eb8bd39ab3c31 100644 (file)
  */
 #define EMIT_VBO(out, ctx, start, delta, n) do {                       \
                struct nouveau_render_state *render = to_render_state(ctx); \
-               int npush = n;                                          \
+               int _npush = n;                                         \
                                                                        \
-               while (npush) {                                         \
-                       int npack = MIN2(npush, MAX_PACKET * MAX_OUT_##out); \
-                       npush -= npack;                                 \
+               while (_npush) {                                                \
+                       int _npack = MIN2(_npush, MAX_PACKET * MAX_OUT_##out); \
+                       _npush -= _npack;                                       \
                                                                        \
-                       BATCH_PACKET_##out((npack + MAX_OUT_##out - 1)  \
+                       BATCH_PACKET_##out((_npack + MAX_OUT_##out - 1) \
                                           / MAX_OUT_##out);            \
-                       while (npack) {                                 \
-                               int nout = MIN2(npack, MAX_OUT_##out);  \
-                               npack -= nout;                          \
+                       while (_npack) {                                \
+                               int _nout = MIN2(_npack, MAX_OUT_##out);\
+                               _npack -= _nout;                        \
                                                                        \
                                OUT_INDICES_##out(render, start, delta, \
-                                                 nout);                \
-                               start += nout;                          \
+                                                 _nout);               \
+                               start += _nout;                         \
                        }                                               \
                }                                                       \
        } while (0)
                }                                                       \
        } while (0)
 
-/*
- * Select an appropriate dispatch function for the given index buffer.
- */
 static void
-get_array_dispatch(struct nouveau_array_state *a, dispatch_t *dispatch)
+dispatch_l(struct gl_context *ctx, unsigned int start, int delta,
+          unsigned int n)
 {
-       if (!a->fields) {
-               auto void f(GLcontext *, unsigned int, int, unsigned int);
-
-               void f(GLcontext *ctx, unsigned int start, int delta,
-                      unsigned int n) {
-                       struct nouveau_channel *chan = context_chan(ctx);
-                       RENDER_LOCALS(ctx);
-
-                       EMIT_VBO(L, ctx, start, delta, n);
-               };
-
-               *dispatch = f;
-
-       } else if (a->type == GL_UNSIGNED_INT) {
-               auto void f(GLcontext *, unsigned int, int, unsigned int);
+       struct nouveau_pushbuf *push = context_push(ctx);
+       RENDER_LOCALS(ctx);
 
-               void f(GLcontext *ctx, unsigned int start, int delta,
-                      unsigned int n) {
-                       struct nouveau_channel *chan = context_chan(ctx);
-                       RENDER_LOCALS(ctx);
-
-                       EMIT_VBO(I32, ctx, start, delta, n);
-               };
-
-               *dispatch = f;
-
-       } else {
-               auto void f(GLcontext *, unsigned int, int, unsigned int);
-
-               void f(GLcontext *ctx, unsigned int start, int delta,
-                      unsigned int n) {
-                       struct nouveau_channel *chan = context_chan(ctx);
-                       RENDER_LOCALS(ctx);
+       EMIT_VBO(L, ctx, start, delta, n);
+}
 
-                       EMIT_VBO(I32, ctx, start, delta, n & 1);
-                       EMIT_VBO(I16, ctx, start, delta, n & ~1);
-               };
+static void
+dispatch_i32(struct gl_context *ctx, unsigned int start, int delta,
+            unsigned int n)
+{
+       struct nouveau_pushbuf *push = context_push(ctx);
+       RENDER_LOCALS(ctx);
 
-               *dispatch = f;
-       }
+       EMIT_VBO(I32, ctx, start, delta, n);
 }
 
-/*
- * Select appropriate element extraction functions for the given
- * array.
- */
 static void
-get_array_extract(struct nouveau_array_state *a,
-                 extract_u_t *extract_u, extract_f_t *extract_f)
+dispatch_i16(struct gl_context *ctx, unsigned int start, int delta,
+            unsigned int n)
 {
-#define EXTRACT(in_t, out_t, k)                                                \
-       ({                                                              \
-               auto out_t f(struct nouveau_array_state *, int, int);   \
-               out_t f(struct nouveau_array_state *a, int i, int j) {  \
-                       in_t x = ((in_t *)(a->buf + i * a->stride))[j]; \
-                                                                       \
-                       return (out_t)x / (k);                          \
-               };                                                      \
-               f;                                                      \
-       });
-
-       switch (a->type) {
-       case GL_BYTE:
-               *extract_u = EXTRACT(char, unsigned, 1);
-               *extract_f = EXTRACT(char, float, SCHAR_MAX);
-               break;
-       case GL_UNSIGNED_BYTE:
-               *extract_u = EXTRACT(unsigned char, unsigned, 1);
-               *extract_f = EXTRACT(unsigned char, float, UCHAR_MAX);
-               break;
-       case GL_SHORT:
-               *extract_u = EXTRACT(short, unsigned, 1);
-               *extract_f = EXTRACT(short, float, SHRT_MAX);
-               break;
-       case GL_UNSIGNED_SHORT:
-               *extract_u = EXTRACT(unsigned short, unsigned, 1);
-               *extract_f = EXTRACT(unsigned short, float, USHRT_MAX);
-               break;
-       case GL_INT:
-               *extract_u = EXTRACT(int, unsigned, 1);
-               *extract_f = EXTRACT(int, float, INT_MAX);
-               break;
-       case GL_UNSIGNED_INT:
-               *extract_u = EXTRACT(unsigned int, unsigned, 1);
-               *extract_f = EXTRACT(unsigned int, float, UINT_MAX);
-               break;
-       case GL_FLOAT:
-               *extract_u = EXTRACT(float, unsigned, 1.0 / UINT_MAX);
-               *extract_f = EXTRACT(float, float, 1);
-               break;
+       struct nouveau_pushbuf *push = context_push(ctx);
+       RENDER_LOCALS(ctx);
 
-       default:
-               assert(0);
-       }
+       EMIT_VBO(I32, ctx, start, delta, n & 1);
+       EMIT_VBO(I16, ctx, start, delta, n & ~1);
 }
 
 /*
- * Returns a pointer to a chunk of <size> bytes long GART memory. <bo>
- * will be updated with the buffer object the memory is located in.
- *
- * If <offset> is provided, it will be updated with the offset within
- * <bo> of the allocated memory. Otherwise the returned memory will
- * always be located right at the beginning of <bo>.
+ * Select an appropriate dispatch function for the given index buffer.
  */
-static inline void *
-get_scratch_vbo(GLcontext *ctx, unsigned size, struct nouveau_bo **bo,
-               unsigned *offset)
+static dispatch_t
+get_array_dispatch(struct nouveau_array *a)
 {
-       struct nouveau_scratch_state *scratch = &to_render_state(ctx)->scratch;
-       void *buf;
-
-       if (scratch->buf && offset &&
-           size <= RENDER_SCRATCH_SIZE - scratch->offset) {
-               nouveau_bo_ref(scratch->bo[scratch->index], bo);
-
-               buf = scratch->buf + scratch->offset;
-               *offset = scratch->offset;
-               scratch->offset += size;
-
-       } else if (size <= RENDER_SCRATCH_SIZE) {
-               scratch->index = (scratch->index + 1) % RENDER_SCRATCH_COUNT;
-               nouveau_bo_ref(scratch->bo[scratch->index], bo);
-
-               nouveau_bo_map(*bo, NOUVEAU_BO_WR);
-               buf = scratch->buf = (*bo)->map;
-               nouveau_bo_unmap(*bo);
-
-               if (offset)
-                       *offset = 0;
-               scratch->offset = size;
-
-       } else {
-               nouveau_bo_new(context_dev(ctx),
-                              NOUVEAU_BO_MAP | NOUVEAU_BO_GART, 0, size, bo);
-
-               nouveau_bo_map(*bo, NOUVEAU_BO_WR);
-               buf = (*bo)->map;
-               nouveau_bo_unmap(*bo);
-
-               if (offset)
-                       *offset = 0;
-       }
-
-       return buf;
+       if (!a->fields)
+               return dispatch_l;
+       else if (a->type == GL_UNSIGNED_INT)
+               return dispatch_i32;
+       else
+               return dispatch_i16;
 }
 
 /*
  * Returns how many vertices you can draw using <n> pushbuf dwords.
  */
 static inline unsigned
-get_max_vertices(GLcontext *ctx, const struct _mesa_index_buffer *ib,
-                unsigned n)
+get_max_vertices(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
+                int n)
 {
        struct nouveau_render_state *render = to_render_state(ctx);
 
@@ -277,6 +170,11 @@ get_max_vertices(GLcontext *ctx, const struct _mesa_index_buffer *ib,
                        case GL_UNSIGNED_BYTE:
                                max_out = MAX_OUT_I16;
                                break;
+
+                       default:
+                               assert(0);
+                               max_out = 0;
+                               break;
                        }
                } else {
                        max_out = MAX_OUT_L;
@@ -286,76 +184,26 @@ get_max_vertices(GLcontext *ctx, const struct _mesa_index_buffer *ib,
        }
 }
 
-#include "nouveau_vbo_t.c"
-#include "nouveau_swtnl_t.c"
-
 static void
-TAG(emit_material)(GLcontext *ctx, struct nouveau_array_state *a,
+TAG(emit_material)(struct gl_context *ctx, struct nouveau_array *a,
                   const void *v)
 {
-       const int attr = a->attr - VERT_ATTRIB_GENERIC0;
-       const int state = ((int []) {
-                               NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT,
-                               NOUVEAU_STATE_MATERIAL_BACK_AMBIENT,
-                               NOUVEAU_STATE_MATERIAL_FRONT_DIFFUSE,
-                               NOUVEAU_STATE_MATERIAL_BACK_DIFFUSE,
-                               NOUVEAU_STATE_MATERIAL_FRONT_SPECULAR,
-                               NOUVEAU_STATE_MATERIAL_BACK_SPECULAR,
-                               NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT,
-                               NOUVEAU_STATE_MATERIAL_BACK_AMBIENT,
-                               NOUVEAU_STATE_MATERIAL_FRONT_SHININESS,
-                               NOUVEAU_STATE_MATERIAL_BACK_SHININESS
-                       }) [attr];
+       int attr = a->attr - VERT_ATTRIB_GENERIC0;
+       int state = ((int []) {
+                       NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT,
+                       NOUVEAU_STATE_MATERIAL_BACK_AMBIENT,
+                       NOUVEAU_STATE_MATERIAL_FRONT_DIFFUSE,
+                       NOUVEAU_STATE_MATERIAL_BACK_DIFFUSE,
+                       NOUVEAU_STATE_MATERIAL_FRONT_SPECULAR,
+                       NOUVEAU_STATE_MATERIAL_BACK_SPECULAR,
+                       NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT,
+                       NOUVEAU_STATE_MATERIAL_BACK_AMBIENT,
+                       NOUVEAU_STATE_MATERIAL_FRONT_SHININESS,
+                       NOUVEAU_STATE_MATERIAL_BACK_SHININESS
+               }) [attr];
 
        COPY_4V(ctx->Light.Material.Attrib[attr], (float *)v);
        _mesa_update_material(ctx, 1 << attr);
 
        context_drv(ctx)->emit[state](ctx, state);
 }
-
-static void
-TAG(render_prims)(GLcontext *ctx, const struct gl_client_array **arrays,
-                 const struct _mesa_prim *prims, GLuint nr_prims,
-                 const struct _mesa_index_buffer *ib,
-                 GLboolean index_bounds_valid,
-                 GLuint min_index, GLuint max_index)
-{
-       struct nouveau_context *nctx = to_nouveau_context(ctx);
-
-       nouveau_validate_framebuffer(ctx);
-
-       if (nctx->fallback == HWTNL)
-               TAG(vbo_render_prims)(ctx, arrays, prims, nr_prims, ib,
-                                     index_bounds_valid, min_index, max_index);
-
-       if (nctx->fallback == SWTNL)
-               _tnl_vbo_draw_prims(ctx, arrays, prims, nr_prims, ib,
-                                   index_bounds_valid, min_index, max_index);
-}
-
-void
-TAG(render_init)(GLcontext *ctx)
-{
-       struct nouveau_render_state *render = to_render_state(ctx);
-       struct nouveau_scratch_state *scratch = &render->scratch;
-       int ret, i;
-
-       for (i = 0; i < RENDER_SCRATCH_COUNT; i++) {
-               ret = nouveau_bo_new(context_dev(ctx),
-                                    NOUVEAU_BO_MAP | NOUVEAU_BO_GART,
-                                    0, RENDER_SCRATCH_SIZE, &scratch->bo[i]);
-               assert(!ret);
-       }
-
-       for (i = 0; i < VERT_ATTRIB_MAX; i++)
-               render->map[i] = -1;
-
-       TAG(swtnl_init)(ctx);
-       vbo_set_draw_func(ctx, TAG(render_prims));
-}
-
-void
-TAG(render_destroy)(GLcontext *ctx)
-{
-       TAG(swtnl_destroy)(ctx);
-}