From 64242b23c1893dd6e1c048beee0e1573aeaf1abc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 3 Jan 2012 21:28:41 +0100 Subject: [PATCH] u_vbuf: cleanup the computation of how many vertices to upload/translate --- src/gallium/auxiliary/util/u_vbuf.c | 39 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/gallium/auxiliary/util/u_vbuf.c b/src/gallium/auxiliary/util/u_vbuf.c index b210ec2feb2..4e94e40269b 100644 --- a/src/gallium/auxiliary/util/u_vbuf.c +++ b/src/gallium/auxiliary/util/u_vbuf.c @@ -922,7 +922,8 @@ u_vbuf_draw_begin(struct u_vbuf *mgrb, const struct pipe_draw_info *info) { struct u_vbuf_priv *mgr = (struct u_vbuf_priv*)mgrb; - int start, count; + int start_vertex; + unsigned num_vertices; if (!mgr->incompatible_vb_layout && !mgr->ve->incompatible_layout && @@ -932,40 +933,46 @@ u_vbuf_draw_begin(struct u_vbuf *mgrb, if (info->indexed) { int min_index, max_index; + bool index_bounds_valid = false; if (info->max_index != ~0) { - min_index = info->min_index + info->index_bias; - max_index = info->max_index + info->index_bias; + min_index = info->min_index; + max_index = info->max_index; + index_bounds_valid = true; } else if (u_vbuf_need_minmax_index(mgr)) { u_vbuf_get_minmax_index(mgr->pipe, &mgr->b.index_buffer, info, &min_index, &max_index); - min_index += info->index_bias; - max_index += info->index_bias; + index_bounds_valid = true; + } + + /* If the index bounds are valid, it means some upload or translation + * of per-vertex attribs will be performed. */ + if (index_bounds_valid) { + assert(min_index <= max_index); + + start_vertex = min_index + info->index_bias; + num_vertices = max_index + 1 - min_index; } else { + /* Nothing to do for per-vertex attribs. */ + start_vertex = 0; + num_vertices = 0; min_index = 0; - max_index = 0; } - - assert(min_index <= max_index); - start = min_index; - count = max_index + 1 - min_index; } else { - start = info->start; - count = info->count; + start_vertex = info->start; + num_vertices = info->count; } - assert(count > 0); - /* Translate vertices with non-native layouts or formats. */ if (mgr->incompatible_vb_layout || mgr->ve->incompatible_layout) { /* XXX check the return value */ - u_vbuf_translate_begin(mgr, start, count, + u_vbuf_translate_begin(mgr, start_vertex, num_vertices, info->start_instance, info->instance_count); } /* Upload user buffers. */ if (mgr->any_user_vbs) { - u_vbuf_upload_buffers(mgr, start, count, + u_vbuf_upload_buffers(mgr, start_vertex, num_vertices, info->start_instance, info->instance_count); } -- 2.30.2