aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2010-10-29 21:29:15 +0200
committerFrancisco Jerez <[email protected]>2010-10-31 02:45:38 +0200
commit9d1f1fcf136e8f5f427ae203128ff641cc9e7197 (patch)
treefb06f3528ad40c358413b25644b09ef1b7baf035 /src/mesa/drivers/dri
parentdbe1eae785e8a98eb3d515b572c8e5e28b234edd (diff)
dri/nouveau: Use a macro to iterate over the bound vertex attributes.
Diffstat (limited to 'src/mesa/drivers/dri')
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_render.h7
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c23
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c113
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_render.c24
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_render.c28
5 files changed, 83 insertions, 112 deletions
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_render.h b/src/mesa/drivers/dri/nouveau/nouveau_render.h
index a9e8e90faf7..498c7e4acff 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_render.h
+++ b/src/mesa/drivers/dri/nouveau/nouveau_render.h
@@ -84,4 +84,11 @@ struct nouveau_render_state {
#define to_render_state(ctx) (&to_nouveau_context(ctx)->render)
+#define FOR_EACH_ATTR(render, i, attr) \
+ for (i = 0; attr = (render)->map[i], i < NUM_VERTEX_ATTRS; i++)
+
+#define FOR_EACH_BOUND_ATTR(render, i, attr) \
+ for (i = 0; attr = (render)->map[i], i < render->attr_count; i++) \
+ if (attr >= 0)
+
#endif
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c b/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c
index db69e562e79..9cf963a9335 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c
@@ -107,7 +107,7 @@ swtnl_choose_attrs(struct gl_context *ctx)
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct tnl_clipspace *vtx = &tnl->clipspace;
static struct tnl_attr_map map[NUM_VERTEX_ATTRS];
- int fields, i, n = 0;
+ int fields, attr, i, n = 0;
render->mode = VBO;
render->attr_count = NUM_VERTEX_ATTRS;
@@ -143,13 +143,8 @@ swtnl_choose_attrs(struct gl_context *ctx)
_tnl_install_attrs(ctx, map, n, NULL, 0);
- for (i = 0; i < vtx->attr_count; i++) {
- struct tnl_clipspace_attr *ta = &vtx->attr[i];
- struct nouveau_array_state *a = &render->attrs[ta->attrib];
-
- a->stride = vtx->vertex_size;
- a->offset = ta->vertoffset;
- }
+ FOR_EACH_BOUND_ATTR(render, i, attr)
+ render->attrs[attr].stride = vtx->vertex_size;
TAG(render_set_format)(ctx);
}
@@ -187,15 +182,11 @@ static void
swtnl_unbind_vertices(struct gl_context *ctx)
{
struct nouveau_render_state *render = to_render_state(ctx);
- int i;
+ int i, attr;
- for (i = 0; i < render->attr_count; i++) {
- int *attr = &render->map[i];
-
- if (*attr >= 0) {
- nouveau_bo_ref(NULL, &render->attrs[*attr].bo);
- *attr = -1;
- }
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ nouveau_bo_ref(NULL, &render->attrs[attr].bo);
+ render->map[i] = -1;
}
render->attr_count = 0;
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c b/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c
index 4565fcc353b..c93f31819d4 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c
@@ -102,44 +102,39 @@ vbo_init_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
const struct gl_client_array **arrays)
{
struct nouveau_render_state *render = to_render_state(ctx);
- int i;
+ GLboolean imm = (render->mode == IMM);
+ int i, attr;
if (ib)
vbo_init_array(&render->ib, 0, 0, ib->count, ib->type,
ib->obj, ib->ptr, GL_TRUE);
- for (i = 0; i < render->attr_count; i++) {
- int attr = render->map[i];
-
- if (attr >= 0) {
- const struct gl_client_array *array = arrays[attr];
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ const struct gl_client_array *array = arrays[attr];
- vbo_init_array(&render->attrs[attr], attr,
- get_array_stride(ctx, array),
- array->Size, array->Type,
- array->BufferObj, array->Ptr,
- render->mode == IMM);
- }
+ vbo_init_array(&render->attrs[attr], attr,
+ get_array_stride(ctx, array),
+ array->Size, array->Type,
+ array->BufferObj,
+ array->Ptr, imm);
}
}
static void
vbo_deinit_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
- const struct gl_client_array **arrays)
+ const struct gl_client_array **arrays)
{
struct nouveau_render_state *render = to_render_state(ctx);
- int i;
+ int i, attr;
if (ib)
vbo_deinit_array(&render->ib);
- for (i = 0; i < render->attr_count; i++) {
- int *attr = &render->map[i];
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ struct nouveau_array_state *a = &render->attrs[attr];
- if (*attr >= 0) {
- vbo_deinit_array(&render->attrs[*attr]);
- *attr = -1;
- }
+ vbo_deinit_array(a);
+ render->map[i] = -1;
}
render->attr_count = 0;
@@ -164,11 +159,6 @@ vbo_choose_render_mode(struct gl_context *ctx, const struct gl_client_array **ar
}
}
}
-
- if (render->mode == VBO)
- render->attr_count = NUM_VERTEX_ATTRS;
- else
- render->attr_count = 0;
}
static void
@@ -199,10 +189,13 @@ vbo_emit_attr(struct gl_context *ctx, const struct gl_client_array **arrays, int
if (render->mode == VBO) {
render->map[info->vbo_index] = attr;
render->vertex_size += array->_ElementSize;
+ render->attr_count = MAX2(render->attr_count,
+ info->vbo_index + 1);
} else {
render->map[render->attr_count++] = attr;
render->vertex_size += 4 * info->imm_fields;
}
+
}
}
@@ -216,6 +209,7 @@ vbo_choose_attrs(struct gl_context *ctx, const struct gl_client_array **arrays)
/* Reset the vertex size. */
render->vertex_size = 0;
+ render->attr_count = 0;
vbo_emit_attr(ctx, arrays, VERT_ATTRIB_COLOR0);
if (ctx->Fog.ColorSumEnabled && !ctx->Light.Enabled)
@@ -254,17 +248,13 @@ static int
get_max_client_stride(struct gl_context *ctx, const struct gl_client_array **arrays)
{
struct nouveau_render_state *render = to_render_state(ctx);
- int i, s = 0;
+ int i, attr, s = 0;
- for (i = 0; i < render->attr_count; i++) {
- int attr = render->map[i];
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ const struct gl_client_array *a = arrays[attr];
- if (attr >= 0) {
- const struct gl_client_array *a = arrays[attr];
-
- if (!_mesa_is_bufferobj(a->BufferObj))
- s = MAX2(s, get_array_stride(ctx, a));
- }
+ if (!_mesa_is_bufferobj(a->BufferObj))
+ s = MAX2(s, get_array_stride(ctx, a));
}
return s;
@@ -320,33 +310,29 @@ vbo_bind_vertices(struct gl_context *ctx, const struct gl_client_array **arrays,
GLint basevertex, GLuint min_index, GLuint max_index)
{
struct nouveau_render_state *render = to_render_state(ctx);
- int i;
+ int i, attr;
- for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
- int attr = render->map[i];
-
- if (attr >= 0) {
- const struct gl_client_array *array = arrays[attr];
- struct nouveau_array_state *a = &render->attrs[attr];
- unsigned delta = (basevertex + min_index)
- * array->StrideB;
-
- if (a->bo) {
- /* Array in a buffer obj. */
- a->offset = (intptr_t)array->Ptr + delta;
- } else {
- int j, n = max_index - min_index + 1;
- char *sp = (char *)array->Ptr + delta;
- char *dp = nouveau_get_scratch(
- ctx, n * a->stride, &a->bo, &a->offset);
-
- /* Array in client memory, move it to
- * a scratch buffer obj. */
- for (j = 0; j < n; j++)
- memcpy(dp + j * a->stride,
- sp + j * array->StrideB,
- a->stride);
- }
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ const struct gl_client_array *array = arrays[attr];
+ struct nouveau_array_state *a = &render->attrs[attr];
+ unsigned delta = (basevertex + min_index)
+ * array->StrideB;
+
+ if (a->bo) {
+ /* Array in a buffer obj. */
+ a->offset = (intptr_t)array->Ptr + delta;
+ } else {
+ int j, n = max_index - min_index + 1;
+ char *sp = (char *)array->Ptr + delta;
+ char *dp = nouveau_get_scratch(
+ ctx, n * a->stride, &a->bo, &a->offset);
+
+ /* Array in client memory, move it to
+ * a scratch buffer obj. */
+ for (j = 0; j < n; j++)
+ memcpy(dp + j * a->stride,
+ sp + j * array->StrideB,
+ a->stride);
}
}
@@ -404,7 +390,7 @@ vbo_draw_imm(struct gl_context *ctx, const struct gl_client_array **arrays,
struct nouveau_render_state *render = to_render_state(ctx);
struct nouveau_channel *chan = context_chan(ctx);
extract_u_t extract = ib ? render->ib.extract_u : extract_id;
- int i, j, k;
+ int i, j, k, attr;
RENDER_LOCALS(ctx);
for (i = 0; i < nr_prims; i++) {
@@ -421,9 +407,8 @@ vbo_draw_imm(struct gl_context *ctx, const struct gl_client_array **arrays,
j = prims[i].basevertex +
extract(&render->ib, 0, start);
- for (k = 0; k < render->attr_count; k++)
- EMIT_IMM(ctx, &render->attrs[render->map[k]],
- j);
+ FOR_EACH_BOUND_ATTR(render, k, attr)
+ EMIT_IMM(ctx, &render->attrs[attr], j);
}
BATCH_END();
diff --git a/src/mesa/drivers/dri/nouveau/nv10_render.c b/src/mesa/drivers/dri/nouveau/nv10_render.c
index a03ace35366..3daec613af5 100644
--- a/src/mesa/drivers/dri/nouveau/nv10_render.c
+++ b/src/mesa/drivers/dri/nouveau/nv10_render.c
@@ -111,11 +111,9 @@ nv10_render_set_format(struct gl_context *ctx)
struct nouveau_render_state *render = to_render_state(ctx);
struct nouveau_channel *chan = context_chan(ctx);
struct nouveau_grobj *celsius = context_eng3d(ctx);
- int i, hw_format;
-
- for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
- int attr = render->map[i];
+ int i, attr, hw_format;
+ FOR_EACH_ATTR(render, i, attr) {
if (attr >= 0) {
struct nouveau_array_state *a = &render->attrs[attr];
@@ -142,19 +140,15 @@ nv10_render_bind_vertices(struct gl_context *ctx)
struct nouveau_bo_context *bctx = context_bctx(ctx, VERTEX);
struct nouveau_channel *chan = context_chan(ctx);
struct nouveau_grobj *celsius = context_eng3d(ctx);
- int i;
+ int i, attr;
- for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
- int attr = render->map[i];
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ struct nouveau_array_state *a = &render->attrs[attr];
- if (attr >= 0) {
- struct nouveau_array_state *a = &render->attrs[attr];
-
- nouveau_bo_markl(bctx, celsius,
- NV10TCL_VTXBUF_ADDRESS(i),
- a->bo, a->offset,
- NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- }
+ nouveau_bo_markl(bctx, celsius,
+ NV10TCL_VTXBUF_ADDRESS(i),
+ a->bo, a->offset,
+ NOUVEAU_BO_GART | NOUVEAU_BO_RD);
}
BEGIN_RING(chan, celsius, NV10TCL_VERTEX_ARRAY_VALIDATE, 1);
diff --git a/src/mesa/drivers/dri/nouveau/nv20_render.c b/src/mesa/drivers/dri/nouveau/nv20_render.c
index 6b668544627..de62dd5137e 100644
--- a/src/mesa/drivers/dri/nouveau/nv20_render.c
+++ b/src/mesa/drivers/dri/nouveau/nv20_render.c
@@ -135,11 +135,9 @@ nv20_render_set_format(struct gl_context *ctx)
struct nouveau_render_state *render = to_render_state(ctx);
struct nouveau_channel *chan = context_chan(ctx);
struct nouveau_grobj *kelvin = context_eng3d(ctx);
- int i, hw_format;
-
- for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
- int attr = render->map[i];
+ int i, attr, hw_format;
+ FOR_EACH_ATTR(render, i, attr) {
if (attr >= 0) {
struct nouveau_array_state *a = &render->attrs[attr];
@@ -164,21 +162,17 @@ nv20_render_bind_vertices(struct gl_context *ctx)
struct nouveau_bo_context *bctx = context_bctx(ctx, VERTEX);
struct nouveau_channel *chan = context_chan(ctx);
struct nouveau_grobj *kelvin = context_eng3d(ctx);
- int i;
+ int i, attr;
- for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
- int attr = render->map[i];
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ struct nouveau_array_state *a = &render->attrs[attr];
- if (attr >= 0) {
- struct nouveau_array_state *a = &render->attrs[attr];
-
- nouveau_bo_mark(bctx, kelvin,
- NV20TCL_VTXBUF_ADDRESS(i),
- a->bo, a->offset, 0,
- 0, NV20TCL_VTXBUF_ADDRESS_DMA1,
- NOUVEAU_BO_LOW | NOUVEAU_BO_OR |
- NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- }
+ nouveau_bo_mark(bctx, kelvin,
+ NV20TCL_VTXBUF_ADDRESS(i),
+ a->bo, a->offset, 0,
+ 0, NV20TCL_VTXBUF_ADDRESS_DMA1,
+ NOUVEAU_BO_LOW | NOUVEAU_BO_OR |
+ NOUVEAU_BO_GART | NOUVEAU_BO_RD);
}
BEGIN_RING(chan, kelvin, NV20TCL_VTX_CACHE_INVALIDATE, 1);