diff options
author | Marek Olšák <[email protected]> | 2017-04-02 16:24:39 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2017-05-10 19:00:16 +0200 |
commit | 330d0607ed60fd3edca192e54b4246310f06652f (patch) | |
tree | 56bceba5b291ffcf42209ef1ab7ec515a8f5b666 /src/gallium/auxiliary | |
parent | 22f6624ed318e8131681ec1f2e7b3a59449df412 (diff) |
gallium: remove pipe_index_buffer and set_index_buffer
pipe_draw_info::indexed is replaced with index_size. index_size == 0 means
non-indexed.
Instead of pipe_index_buffer::offset, pipe_draw_info::start is used.
For indexed indirect draws, pipe_draw_info::start is added to the indirect
start. This is the only case when "start" affects indirect draws.
pipe_draw_info::index is a union. Use either index::resource or
index::user depending on the value of pipe_draw_info::has_user_indices.
v2: fixes for nine, svga
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/cso_cache/cso_context.c | 16 | ||||
-rw-r--r-- | src/gallium/auxiliary/cso_cache/cso_context.h | 4 | ||||
-rw-r--r-- | src/gallium/auxiliary/draw/draw_context.c | 3 | ||||
-rw-r--r-- | src/gallium/auxiliary/draw/draw_pt.c | 6 | ||||
-rw-r--r-- | src/gallium/auxiliary/indices/u_primconvert.c | 56 | ||||
-rw-r--r-- | src/gallium/auxiliary/indices/u_primconvert.h | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_draw.c | 6 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_draw.h | 9 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_dump.h | 3 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_dump_state.c | 23 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_helpers.c | 44 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_helpers.h | 11 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_index_modify.c | 24 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_index_modify.h | 7 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_prim_restart.c | 54 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_prim_restart.h | 9 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_vbuf.c | 135 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_vbuf.h | 2 |
18 files changed, 138 insertions, 276 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 68f7b9e7bfe..5558385e4c2 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -349,8 +349,6 @@ void cso_destroy_context( struct cso_context *ctx ) unsigned i; if (ctx->pipe) { - ctx->pipe->set_index_buffer(ctx->pipe, NULL); - ctx->pipe->bind_blend_state( ctx->pipe, NULL ); ctx->pipe->bind_rasterizer_state( ctx->pipe, NULL ); @@ -1697,20 +1695,6 @@ cso_restore_state(struct cso_context *cso) /* drawing */ void -cso_set_index_buffer(struct cso_context *cso, - const struct pipe_index_buffer *ib) -{ - struct u_vbuf *vbuf = cso->vbuf; - - if (vbuf) { - u_vbuf_set_index_buffer(vbuf, ib); - } else { - struct pipe_context *pipe = cso->pipe; - pipe->set_index_buffer(pipe, ib); - } -} - -void cso_draw_vbo(struct cso_context *cso, const struct pipe_draw_info *info) { diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index 742bbb516f1..c21e83849ef 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -222,10 +222,6 @@ void cso_restore_constant_buffer_slot0(struct cso_context *cso, /* drawing */ void -cso_set_index_buffer(struct cso_context *cso, - const struct pipe_index_buffer *ib); - -void cso_draw_vbo(struct cso_context *cso, const struct pipe_draw_info *info); diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c index 0eee0751069..9791ec5506a 100644 --- a/src/gallium/auxiliary/draw/draw_context.c +++ b/src/gallium/auxiliary/draw/draw_context.c @@ -777,9 +777,6 @@ void draw_set_render( struct draw_context *draw, /** * Tell the draw module where vertex indexes/elements are located, and * their size (in bytes). - * - * Note: the caller must apply the pipe_index_buffer::offset value to - * the address. The draw module doesn't do that. */ void draw_set_indexes(struct draw_context *draw, diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c index 5a49acb64d3..be76a30f97c 100644 --- a/src/gallium/auxiliary/draw/draw_pt.c +++ b/src/gallium/auxiliary/draw/draw_pt.c @@ -443,7 +443,7 @@ resolve_draw_info(const struct pipe_draw_info *raw_info, info->count = target->internal_offset / vertex_buffer->stride; /* Stream output draw can not be indexed */ - debug_assert(!info->indexed); + debug_assert(!info->index_size); info->max_index = info->count - 1; } } @@ -473,7 +473,7 @@ draw_vbo(struct draw_context *draw, info = &resolved_info; assert(info->instance_count > 0); - if (info->indexed) + if (info->index_size) assert(draw->pt.user.elts); count = info->count; @@ -481,7 +481,7 @@ draw_vbo(struct draw_context *draw, draw->pt.user.eltBias = info->index_bias; draw->pt.user.min_index = info->min_index; draw->pt.user.max_index = info->max_index; - draw->pt.user.eltSize = info->indexed ? draw->pt.user.eltSizeIB : 0; + draw->pt.user.eltSize = info->index_size ? draw->pt.user.eltSizeIB : 0; if (0) debug_printf("draw_vbo(mode=%u start=%u count=%u):\n", diff --git a/src/gallium/auxiliary/indices/u_primconvert.c b/src/gallium/auxiliary/indices/u_primconvert.c index 1ffca4b593c..778f174e39c 100644 --- a/src/gallium/auxiliary/indices/u_primconvert.c +++ b/src/gallium/auxiliary/indices/u_primconvert.c @@ -33,7 +33,6 @@ * * // emulate unsupported primitives: * if (info->mode needs emulating) { - * util_primconvert_save_index_buffer(ctx->primconvert, &ctx->indexbuf); * util_primconvert_save_rasterizer_state(ctx->primconvert, ctx->rasterizer); * util_primconvert_draw_vbo(ctx->primconvert, info); * return; @@ -53,7 +52,6 @@ struct primconvert_context { struct pipe_context *pipe; - struct pipe_index_buffer saved_ib; uint32_t primtypes_mask; unsigned api_pv; }; @@ -73,26 +71,10 @@ util_primconvert_create(struct pipe_context *pipe, uint32_t primtypes_mask) void util_primconvert_destroy(struct primconvert_context *pc) { - util_primconvert_save_index_buffer(pc, NULL); FREE(pc); } void -util_primconvert_save_index_buffer(struct primconvert_context *pc, - const struct pipe_index_buffer *ib) -{ - if (ib) { - pipe_resource_reference(&pc->saved_ib.buffer, ib->buffer); - pc->saved_ib.index_size = ib->index_size; - pc->saved_ib.offset = ib->offset; - pc->saved_ib.user_buffer = ib->user_buffer; - } - else { - pipe_resource_reference(&pc->saved_ib.buffer, NULL); - } -} - -void util_primconvert_save_rasterizer_state(struct primconvert_context *pc, const struct pipe_rasterizer_state *rast) @@ -108,18 +90,15 @@ void util_primconvert_draw_vbo(struct primconvert_context *pc, const struct pipe_draw_info *info) { - struct pipe_index_buffer *ib = &pc->saved_ib; - struct pipe_index_buffer new_ib; struct pipe_draw_info new_info; struct pipe_transfer *src_transfer = NULL; u_translate_func trans_func; u_generate_func gen_func; const void *src = NULL; void *dst; + unsigned ib_offset; - memset(&new_ib, 0, sizeof(new_ib)); util_draw_init_info(&new_info); - new_info.indexed = true; new_info.min_index = info->min_index; new_info.max_index = info->max_index; new_info.index_bias = info->index_bias; @@ -127,38 +106,43 @@ util_primconvert_draw_vbo(struct primconvert_context *pc, new_info.instance_count = info->instance_count; new_info.primitive_restart = info->primitive_restart; new_info.restart_index = info->restart_index; - if (info->indexed) { + if (info->index_size) { enum pipe_prim_type mode = 0; + unsigned index_size; u_index_translator(pc->primtypes_mask, - info->mode, pc->saved_ib.index_size, info->count, + info->mode, info->index_size, info->count, pc->api_pv, pc->api_pv, info->primitive_restart ? PR_ENABLE : PR_DISABLE, - &mode, &new_ib.index_size, &new_info.count, + &mode, &index_size, &new_info.count, &trans_func); new_info.mode = mode; - src = ib->user_buffer; + new_info.index_size = index_size; + src = info->has_user_indices ? info->index.user : NULL; if (!src) { - src = pipe_buffer_map(pc->pipe, ib->buffer, + src = pipe_buffer_map(pc->pipe, info->index.resource, PIPE_TRANSFER_READ, &src_transfer); } - src = (const uint8_t *)src + ib->offset; + src = (const uint8_t *)src; } else { enum pipe_prim_type mode = 0; + unsigned index_size; u_index_generator(pc->primtypes_mask, info->mode, info->start, info->count, pc->api_pv, pc->api_pv, - &mode, &new_ib.index_size, &new_info.count, + &mode, &index_size, &new_info.count, &gen_func); new_info.mode = mode; + new_info.index_size = index_size; } - u_upload_alloc(pc->pipe->stream_uploader, 0, new_ib.index_size * new_info.count, 4, - &new_ib.offset, &new_ib.buffer, &dst); + u_upload_alloc(pc->pipe->stream_uploader, 0, new_info.index_size * new_info.count, 4, + &ib_offset, &new_info.index.resource, &dst); + new_info.start = ib_offset / new_info.index_size; - if (info->indexed) { + if (info->index_size) { trans_func(src, info->start, info->count, new_info.count, info->restart_index, dst); } else { @@ -170,14 +154,8 @@ util_primconvert_draw_vbo(struct primconvert_context *pc, u_upload_unmap(pc->pipe->stream_uploader); - /* bind new index buffer: */ - pc->pipe->set_index_buffer(pc->pipe, &new_ib); - /* to the translated draw: */ pc->pipe->draw_vbo(pc->pipe, &new_info); - /* and then restore saved ib: */ - pc->pipe->set_index_buffer(pc->pipe, ib); - - pipe_resource_reference(&new_ib.buffer, NULL); + pipe_resource_reference(&new_info.index.resource, NULL); } diff --git a/src/gallium/auxiliary/indices/u_primconvert.h b/src/gallium/auxiliary/indices/u_primconvert.h index 73ffea0ca29..02ee0639dfb 100644 --- a/src/gallium/auxiliary/indices/u_primconvert.h +++ b/src/gallium/auxiliary/indices/u_primconvert.h @@ -34,8 +34,6 @@ struct primconvert_context; struct primconvert_context *util_primconvert_create(struct pipe_context *pipe, uint32_t primtypes_mask); void util_primconvert_destroy(struct primconvert_context *pc); -void util_primconvert_save_index_buffer(struct primconvert_context *pc, - const struct pipe_index_buffer *ib); void util_primconvert_save_rasterizer_state(struct primconvert_context *pc, const struct pipe_rasterizer_state *rast); diff --git a/src/gallium/auxiliary/util/u_draw.c b/src/gallium/auxiliary/util/u_draw.c index e7abbfc422b..a7590f7f043 100644 --- a/src/gallium/auxiliary/util/u_draw.c +++ b/src/gallium/auxiliary/util/u_draw.c @@ -136,7 +136,7 @@ util_draw_indirect(struct pipe_context *pipe, struct pipe_draw_info info; struct pipe_transfer *transfer; uint32_t *params; - const unsigned num_params = info_in->indexed ? 5 : 4; + const unsigned num_params = info_in->index_size ? 5 : 4; assert(info_in->indirect); assert(!info_in->count_from_stream_output); @@ -158,8 +158,8 @@ util_draw_indirect(struct pipe_context *pipe, info.count = params[0]; info.instance_count = params[1]; info.start = params[2]; - info.index_bias = info_in->indexed ? params[3] : 0; - info.start_instance = info_in->indexed ? params[4] : params[3]; + info.index_bias = info_in->index_size ? params[3] : 0; + info.start_instance = info_in->index_size ? params[4] : params[3]; info.indirect = NULL; pipe_buffer_unmap(pipe, transfer); diff --git a/src/gallium/auxiliary/util/u_draw.h b/src/gallium/auxiliary/util/u_draw.h index b6ea3de8905..e8af14051b1 100644 --- a/src/gallium/auxiliary/util/u_draw.h +++ b/src/gallium/auxiliary/util/u_draw.h @@ -67,15 +67,15 @@ util_draw_arrays(struct pipe_context *pipe, } static inline void -util_draw_elements(struct pipe_context *pipe, int index_bias, - enum pipe_prim_type mode, +util_draw_elements(struct pipe_context *pipe, unsigned index_size, + int index_bias, enum pipe_prim_type mode, uint start, uint count) { struct pipe_draw_info info; util_draw_init_info(&info); - info.indexed = TRUE; + info.index_size = index_size; info.mode = mode; info.start = start; info.count = count; @@ -108,6 +108,7 @@ util_draw_arrays_instanced(struct pipe_context *pipe, static inline void util_draw_elements_instanced(struct pipe_context *pipe, + unsigned index_size, int index_bias, enum pipe_prim_type mode, uint start, @@ -118,7 +119,7 @@ util_draw_elements_instanced(struct pipe_context *pipe, struct pipe_draw_info info; util_draw_init_info(&info); - info.indexed = TRUE; + info.index_size = index_size; info.mode = mode; info.start = start; info.count = count; diff --git a/src/gallium/auxiliary/util/u_dump.h b/src/gallium/auxiliary/util/u_dump.h index 3a701ac5be9..408c270040f 100644 --- a/src/gallium/auxiliary/util/u_dump.h +++ b/src/gallium/auxiliary/util/u_dump.h @@ -173,9 +173,6 @@ util_dump_constant_buffer(FILE *stream, const struct pipe_constant_buffer *state); void -util_dump_index_buffer(FILE *stream, const struct pipe_index_buffer *state); - -void util_dump_vertex_buffer(FILE *stream, const struct pipe_vertex_buffer *state); diff --git a/src/gallium/auxiliary/util/u_dump_state.c b/src/gallium/auxiliary/util/u_dump_state.c index 5e42bdd3028..c62229a5fe1 100644 --- a/src/gallium/auxiliary/util/u_dump_state.c +++ b/src/gallium/auxiliary/util/u_dump_state.c @@ -834,25 +834,6 @@ util_dump_constant_buffer(FILE *stream, void -util_dump_index_buffer(FILE *stream, const struct pipe_index_buffer *state) -{ - if (!state) { - util_dump_null(stream); - return; - } - - util_dump_struct_begin(stream, "pipe_index_buffer"); - - util_dump_member(stream, uint, state, index_size); - util_dump_member(stream, uint, state, offset); - util_dump_member(stream, ptr, state, buffer); - util_dump_member(stream, ptr, state, user_buffer); - - util_dump_struct_end(stream); -} - - -void util_dump_vertex_buffer(FILE *stream, const struct pipe_vertex_buffer *state) { if (!state) { @@ -919,7 +900,8 @@ util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state) util_dump_struct_begin(stream, "pipe_draw_info"); - util_dump_member(stream, bool, state, indexed); + util_dump_member(stream, uint, state, index_size); + util_dump_member(stream, uint, state, has_user_indices); util_dump_member(stream, enum_prim_mode, state, mode); util_dump_member(stream, uint, state, start); @@ -939,6 +921,7 @@ util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state) util_dump_member(stream, bool, state, primitive_restart); util_dump_member(stream, uint, state, restart_index); + util_dump_member(stream, ptr, state, index.resource); util_dump_member(stream, ptr, state, count_from_stream_output); if (!state->indirect) { diff --git a/src/gallium/auxiliary/util/u_helpers.c b/src/gallium/auxiliary/util/u_helpers.c index f91cb0c158d..e0feade3acd 100644 --- a/src/gallium/auxiliary/util/u_helpers.c +++ b/src/gallium/auxiliary/util/u_helpers.c @@ -98,48 +98,24 @@ void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst, *dst_count = util_last_bit(enabled_buffers); } - -void -util_set_index_buffer(struct pipe_index_buffer *dst, - const struct pipe_index_buffer *src) -{ - if (src) { - pipe_resource_reference(&dst->buffer, src->buffer); - memcpy(dst, src, sizeof(*dst)); - } - else { - pipe_resource_reference(&dst->buffer, NULL); - memset(dst, 0, sizeof(*dst)); - } -} - /** * Given a user index buffer, save the structure to "saved", and upload it. */ bool -util_save_and_upload_index_buffer(struct pipe_context *pipe, - const struct pipe_draw_info *info, - const struct pipe_index_buffer *ib, - struct pipe_index_buffer *out_saved) +util_upload_index_buffer(struct pipe_context *pipe, + const struct pipe_draw_info *info, + struct pipe_resource **out_buffer, + unsigned *out_offset) { - struct pipe_index_buffer new_ib = {0}; - unsigned start_offset = info->start * ib->index_size; + unsigned start_offset = info->start * info->index_size; u_upload_data(pipe->stream_uploader, start_offset, - info->count * ib->index_size, 4, - (char*)ib->user_buffer + start_offset, - &new_ib.offset, &new_ib.buffer); - if (!new_ib.buffer) - return false; + info->count * info->index_size, 4, + (char*)info->index.user + start_offset, + out_offset, out_buffer); u_upload_unmap(pipe->stream_uploader); - - new_ib.offset -= start_offset; - new_ib.index_size = ib->index_size; - - util_set_index_buffer(out_saved, ib); - pipe->set_index_buffer(pipe, &new_ib); - pipe_resource_reference(&new_ib.buffer, NULL); - return true; + *out_offset -= start_offset; + return *out_buffer != NULL; } struct pipe_query * diff --git a/src/gallium/auxiliary/util/u_helpers.h b/src/gallium/auxiliary/util/u_helpers.h index 2b382a1a54e..ab970d791b1 100644 --- a/src/gallium/auxiliary/util/u_helpers.h +++ b/src/gallium/auxiliary/util/u_helpers.h @@ -45,13 +45,10 @@ void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst, const struct pipe_vertex_buffer *src, unsigned start_slot, unsigned count); -void util_set_index_buffer(struct pipe_index_buffer *dst, - const struct pipe_index_buffer *src); - -bool util_save_and_upload_index_buffer(struct pipe_context *pipe, - const struct pipe_draw_info *info, - const struct pipe_index_buffer *ib, - struct pipe_index_buffer *out_saved); +bool util_upload_index_buffer(struct pipe_context *pipe, + const struct pipe_draw_info *info, + struct pipe_resource **out_buffer, + unsigned *out_offset); struct pipe_query * util_begin_pipestat_query(struct pipe_context *ctx); diff --git a/src/gallium/auxiliary/util/u_index_modify.c b/src/gallium/auxiliary/util/u_index_modify.c index d86be24bcd6..4e9349a7db6 100644 --- a/src/gallium/auxiliary/util/u_index_modify.c +++ b/src/gallium/auxiliary/util/u_index_modify.c @@ -27,7 +27,7 @@ /* Ubyte indices. */ void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context, - const struct pipe_index_buffer *ib, + const struct pipe_draw_info *info, unsigned add_transfer_flags, int index_bias, unsigned start, @@ -39,10 +39,10 @@ void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context, unsigned short *out_map = out; unsigned i; - if (ib->user_buffer) { - in_map = ib->user_buffer; + if (info->has_user_indices) { + in_map = info->index.user; } else { - in_map = pipe_buffer_map(context, ib->buffer, + in_map = pipe_buffer_map(context, info->index.resource, PIPE_TRANSFER_READ | add_transfer_flags, &src_transfer); @@ -62,7 +62,7 @@ void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context, /* Ushort indices. */ void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context, - const struct pipe_index_buffer *ib, + const struct pipe_draw_info *info, unsigned add_transfer_flags, int index_bias, unsigned start, unsigned count, @@ -73,10 +73,10 @@ void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context, unsigned short *out_map = out; unsigned i; - if (ib->user_buffer) { - in_map = ib->user_buffer; + if (info->has_user_indices) { + in_map = info->index.user; } else { - in_map = pipe_buffer_map(context, ib->buffer, + in_map = pipe_buffer_map(context, info->index.resource, PIPE_TRANSFER_READ | add_transfer_flags, &in_transfer); @@ -96,7 +96,7 @@ void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context, /* Uint indices. */ void util_rebuild_uint_elts_to_userptr(struct pipe_context *context, - const struct pipe_index_buffer *ib, + const struct pipe_draw_info *info, unsigned add_transfer_flags, int index_bias, unsigned start, unsigned count, @@ -107,10 +107,10 @@ void util_rebuild_uint_elts_to_userptr(struct pipe_context *context, unsigned int *out_map = out; unsigned i; - if (ib->user_buffer) { - in_map = ib->user_buffer; + if (info->has_user_indices) { + in_map = info->index.user; } else { - in_map = pipe_buffer_map(context, ib->buffer, + in_map = pipe_buffer_map(context, info->index.resource, PIPE_TRANSFER_READ | add_transfer_flags, &in_transfer); diff --git a/src/gallium/auxiliary/util/u_index_modify.h b/src/gallium/auxiliary/util/u_index_modify.h index d009199b012..ba96725bedd 100644 --- a/src/gallium/auxiliary/util/u_index_modify.h +++ b/src/gallium/auxiliary/util/u_index_modify.h @@ -25,10 +25,9 @@ struct pipe_context; struct pipe_resource; -struct pipe_index_buffer; void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context, - const struct pipe_index_buffer *ib, + const struct pipe_draw_info *info, unsigned add_transfer_flags, int index_bias, unsigned start, @@ -36,14 +35,14 @@ void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context, void *out); void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context, - const struct pipe_index_buffer *ib, + const struct pipe_draw_info *info, unsigned add_transfer_flags, int index_bias, unsigned start, unsigned count, void *out); void util_rebuild_uint_elts_to_userptr(struct pipe_context *context, - const struct pipe_index_buffer *ib, + const struct pipe_draw_info *info, unsigned add_transfer_flags, int index_bias, unsigned start, unsigned count, diff --git a/src/gallium/auxiliary/util/u_prim_restart.c b/src/gallium/auxiliary/util/u_prim_restart.c index e45aa562a4f..9ff93a7f669 100644 --- a/src/gallium/auxiliary/util/u_prim_restart.c +++ b/src/gallium/auxiliary/util/u_prim_restart.c @@ -39,28 +39,26 @@ */ enum pipe_error util_translate_prim_restart_ib(struct pipe_context *context, - struct pipe_index_buffer *src_buffer, - struct pipe_resource **dst_buffer, - unsigned num_indexes, - unsigned restart_index) + const struct pipe_draw_info *info, + struct pipe_resource **dst_buffer) { struct pipe_screen *screen = context->screen; struct pipe_transfer *src_transfer = NULL, *dst_transfer = NULL; void *src_map = NULL, *dst_map = NULL; - const unsigned src_index_size = src_buffer->index_size; + const unsigned src_index_size = info->index_size; unsigned dst_index_size; /* 1-byte indexes are converted to 2-byte indexes, 4-byte stays 4-byte */ - dst_index_size = MAX2(2, src_buffer->index_size); + dst_index_size = MAX2(2, info->index_size); assert(dst_index_size == 2 || dst_index_size == 4); /* no user buffers for now */ - assert(src_buffer->user_buffer == NULL); + assert(!info->has_user_indices); /* Create new index buffer */ *dst_buffer = pipe_buffer_create(screen, PIPE_BIND_INDEX_BUFFER, PIPE_USAGE_STREAM, - num_indexes * dst_index_size); + info->count * dst_index_size); if (!*dst_buffer) goto error; @@ -71,9 +69,9 @@ util_translate_prim_restart_ib(struct pipe_context *context, goto error; /* Map original / src index buffer */ - src_map = pipe_buffer_map_range(context, src_buffer->buffer, - src_buffer->offset, - num_indexes * src_index_size, + src_map = pipe_buffer_map_range(context, info->index.resource, + info->start * src_index_size, + info->count * src_index_size, PIPE_TRANSFER_READ, &src_transfer); if (!src_map) @@ -83,16 +81,16 @@ util_translate_prim_restart_ib(struct pipe_context *context, uint8_t *src = (uint8_t *) src_map; uint16_t *dst = (uint16_t *) dst_map; unsigned i; - for (i = 0; i < num_indexes; i++) { - dst[i] = (src[i] == restart_index) ? 0xffff : src[i]; + for (i = 0; i < info->count; i++) { + dst[i] = (src[i] == info->restart_index) ? 0xffff : src[i]; } } else if (src_index_size == 2 && dst_index_size == 2) { uint16_t *src = (uint16_t *) src_map; uint16_t *dst = (uint16_t *) dst_map; unsigned i; - for (i = 0; i < num_indexes; i++) { - dst[i] = (src[i] == restart_index) ? 0xffff : src[i]; + for (i = 0; i < info->count; i++) { + dst[i] = (src[i] == info->restart_index) ? 0xffff : src[i]; } } else { @@ -101,8 +99,8 @@ util_translate_prim_restart_ib(struct pipe_context *context, unsigned i; assert(src_index_size == 4); assert(dst_index_size == 4); - for (i = 0; i < num_indexes; i++) { - dst[i] = (src[i] == restart_index) ? 0xffffffff : src[i]; + for (i = 0; i < info->count; i++) { + dst[i] = (src[i] == info->restart_index) ? 0xffffffff : src[i]; } } @@ -177,7 +175,6 @@ add_range(struct range_info *info, unsigned start, unsigned count) */ enum pipe_error util_draw_vbo_without_prim_restart(struct pipe_context *context, - const struct pipe_index_buffer *ib, const struct pipe_draw_info *info) { const void *src_map; @@ -186,15 +183,15 @@ util_draw_vbo_without_prim_restart(struct pipe_context *context, struct pipe_transfer *src_transfer = NULL; unsigned i, start, count; - assert(info->indexed); + assert(info->index_size); assert(info->primitive_restart); /* Get pointer to the index data */ - if (ib->buffer) { + if (!info->has_user_indices) { /* map the index buffer (only the range we need to scan) */ - src_map = pipe_buffer_map_range(context, ib->buffer, - ib->offset + info->start * ib->index_size, - info->count * ib->index_size, + src_map = pipe_buffer_map_range(context, info->index.resource, + info->start * info->index_size, + info->count * info->index_size, PIPE_TRANSFER_READ, &src_transfer); if (!src_map) { @@ -202,13 +199,12 @@ util_draw_vbo_without_prim_restart(struct pipe_context *context, } } else { - if (!ib->user_buffer) { + if (!info->index.user) { debug_printf("User-space index buffer is null!"); return PIPE_ERROR_BAD_INPUT; } - src_map = (const uint8_t *) ib->user_buffer - + ib->offset - + info->start * ib->index_size; + src_map = (const uint8_t *) info->index.user + + info->start * info->index_size; } #define SCAN_INDEXES(TYPE) \ @@ -231,9 +227,9 @@ util_draw_vbo_without_prim_restart(struct pipe_context *context, } \ } - start = info->start; + start = 0; count = 0; - switch (ib->index_size) { + switch (info->index_size) { case 1: SCAN_INDEXES(uint8_t); break; diff --git a/src/gallium/auxiliary/util/u_prim_restart.h b/src/gallium/auxiliary/util/u_prim_restart.h index 1e98e0e1b22..0e17ce5eb1a 100644 --- a/src/gallium/auxiliary/util/u_prim_restart.h +++ b/src/gallium/auxiliary/util/u_prim_restart.h @@ -38,20 +38,17 @@ extern "C" { struct pipe_context; struct pipe_draw_info; -struct pipe_index_buffer; +union pipe_index_binding; struct pipe_resource; enum pipe_error util_translate_prim_restart_ib(struct pipe_context *context, - struct pipe_index_buffer *src_buffer, - struct pipe_resource **dst_buffer, - unsigned num_indexes, - unsigned restart_index); + const struct pipe_draw_info *info, + struct pipe_resource **dst_buffer); enum pipe_error util_draw_vbo_without_prim_restart(struct pipe_context *context, - const struct pipe_index_buffer *ib, const struct pipe_draw_info *info); diff --git a/src/gallium/auxiliary/util/u_vbuf.c b/src/gallium/auxiliary/util/u_vbuf.c index 9d6d5297e6a..8361e649ff4 100644 --- a/src/gallium/auxiliary/util/u_vbuf.c +++ b/src/gallium/auxiliary/util/u_vbuf.c @@ -162,9 +162,6 @@ struct u_vbuf { uint32_t dirty_real_vb_mask; /* which buffers are dirty since the last call of set_vertex_buffers */ - /* The index buffer. */ - struct pipe_index_buffer index_buffer; - /* Vertex elements. */ struct u_vbuf_elements *ve, *ve_saved; @@ -372,9 +369,6 @@ void u_vbuf_destroy(struct u_vbuf *mgr) unsigned num_vb = screen->get_shader_param(screen, PIPE_SHADER_VERTEX, PIPE_SHADER_CAP_MAX_INPUTS); - mgr->pipe->set_index_buffer(mgr->pipe, NULL); - pipe_resource_reference(&mgr->index_buffer.buffer, NULL); - mgr->pipe->set_vertex_buffers(mgr->pipe, 0, num_vb, NULL); for (i = 0; i < PIPE_MAX_ATTRIBS; i++) @@ -391,10 +385,10 @@ void u_vbuf_destroy(struct u_vbuf *mgr) static enum pipe_error u_vbuf_translate_buffers(struct u_vbuf *mgr, struct translate_key *key, + const struct pipe_draw_info *info, unsigned vb_mask, unsigned out_vb, int start_vertex, unsigned num_vertices, - int start_index, unsigned num_indices, int min_index, - boolean unroll_indices) + int min_index, boolean unroll_indices) { struct translate *tr; struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = {0}; @@ -440,38 +434,35 @@ u_vbuf_translate_buffers(struct u_vbuf *mgr, struct translate_key *key, /* Translate. */ if (unroll_indices) { - struct pipe_index_buffer *ib = &mgr->index_buffer; struct pipe_transfer *transfer = NULL; - unsigned offset = ib->offset + start_index * ib->index_size; + unsigned offset = info->start * info->index_size; uint8_t *map; - assert((ib->buffer || ib->user_buffer) && ib->index_size); - /* Create and map the output buffer. */ u_upload_alloc(mgr->pipe->stream_uploader, 0, - key->output_stride * num_indices, 4, + key->output_stride * info->count, 4, &out_offset, &out_buffer, (void**)&out_map); if (!out_buffer) return PIPE_ERROR_OUT_OF_MEMORY; - if (ib->user_buffer) { - map = (uint8_t*)ib->user_buffer + offset; + if (info->has_user_indices) { + map = (uint8_t*)info->index.user + offset; } else { - map = pipe_buffer_map_range(mgr->pipe, ib->buffer, offset, - num_indices * ib->index_size, + map = pipe_buffer_map_range(mgr->pipe, info->index.resource, offset, + info->count * info->index_size, PIPE_TRANSFER_READ, &transfer); } - switch (ib->index_size) { + switch (info->index_size) { case 4: - tr->run_elts(tr, (unsigned*)map, num_indices, 0, 0, out_map); + tr->run_elts(tr, (unsigned*)map, info->count, 0, 0, out_map); break; case 2: - tr->run_elts16(tr, (uint16_t*)map, num_indices, 0, 0, out_map); + tr->run_elts16(tr, (uint16_t*)map, info->count, 0, 0, out_map); break; case 1: - tr->run_elts8(tr, map, num_indices, 0, 0, out_map); + tr->run_elts8(tr, map, info->count, 0, 0, out_map); break; } @@ -556,10 +547,9 @@ u_vbuf_translate_find_free_vb_slots(struct u_vbuf *mgr, static boolean u_vbuf_translate_begin(struct u_vbuf *mgr, + const struct pipe_draw_info *info, int start_vertex, unsigned num_vertices, - int start_instance, unsigned num_instances, - int start_index, unsigned num_indices, int min_index, - boolean unroll_indices) + int min_index, boolean unroll_indices) { unsigned mask[VB_NUM] = {0}; struct translate_key key[VB_NUM]; @@ -569,15 +559,15 @@ u_vbuf_translate_begin(struct u_vbuf *mgr, mgr->ve->used_vb_mask; int start[VB_NUM] = { - start_vertex, /* VERTEX */ - start_instance, /* INSTANCE */ - 0 /* CONST */ + start_vertex, /* VERTEX */ + info->start_instance, /* INSTANCE */ + 0 /* CONST */ }; unsigned num[VB_NUM] = { - num_vertices, /* VERTEX */ - num_instances, /* INSTANCE */ - 1 /* CONST */ + num_vertices, /* VERTEX */ + info->instance_count, /* INSTANCE */ + 1 /* CONST */ }; memset(key, 0, sizeof(key)); @@ -664,10 +654,9 @@ u_vbuf_translate_begin(struct u_vbuf *mgr, for (type = 0; type < VB_NUM; type++) { if (key[type].nr_elements) { enum pipe_error err; - err = u_vbuf_translate_buffers(mgr, &key[type], mask[type], + err = u_vbuf_translate_buffers(mgr, &key[type], info, mask[type], mgr->fallback_vbs[type], - start[type], num[type], - start_index, num_indices, min_index, + start[type], num[type], min_index, unroll_indices && type == VB_VERTEX); if (err != PIPE_OK) return FALSE; @@ -889,22 +878,6 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, mgr->dirty_real_vb_mask |= ~mask; } -void u_vbuf_set_index_buffer(struct u_vbuf *mgr, - const struct pipe_index_buffer *ib) -{ - struct pipe_context *pipe = mgr->pipe; - - if (ib) { - assert(ib->offset % ib->index_size == 0); - pipe_resource_reference(&mgr->index_buffer.buffer, ib->buffer); - memcpy(&mgr->index_buffer, ib, sizeof(*ib)); - } else { - pipe_resource_reference(&mgr->index_buffer.buffer, NULL); - } - - pipe->set_index_buffer(pipe, ib); -} - static enum pipe_error u_vbuf_upload_buffers(struct u_vbuf *mgr, int start_vertex, unsigned num_vertices, @@ -1023,42 +996,38 @@ static boolean u_vbuf_mapping_vertex_buffer_blocks(const struct u_vbuf *mgr) } static void u_vbuf_get_minmax_index(struct pipe_context *pipe, - struct pipe_index_buffer *ib, - boolean primitive_restart, - unsigned restart_index, - unsigned start, unsigned count, - int *out_min_index, - int *out_max_index) + const struct pipe_draw_info *info, + int *out_min_index, int *out_max_index) { struct pipe_transfer *transfer = NULL; const void *indices; unsigned i; - if (ib->user_buffer) { - indices = (uint8_t*)ib->user_buffer + - ib->offset + start * ib->index_size; + if (info->has_user_indices) { + indices = (uint8_t*)info->index.user + + info->start * info->index_size; } else { - indices = pipe_buffer_map_range(pipe, ib->buffer, - ib->offset + start * ib->index_size, - count * ib->index_size, + indices = pipe_buffer_map_range(pipe, info->index.resource, + info->start * info->index_size, + info->count * info->index_size, PIPE_TRANSFER_READ, &transfer); } - switch (ib->index_size) { + switch (info->index_size) { case 4: { const unsigned *ui_indices = (const unsigned*)indices; unsigned max_ui = 0; unsigned min_ui = ~0U; - if (primitive_restart) { - for (i = 0; i < count; i++) { - if (ui_indices[i] != restart_index) { + if (info->primitive_restart) { + for (i = 0; i < info->count; i++) { + if (ui_indices[i] != info->restart_index) { if (ui_indices[i] > max_ui) max_ui = ui_indices[i]; if (ui_indices[i] < min_ui) min_ui = ui_indices[i]; } } } else { - for (i = 0; i < count; i++) { + for (i = 0; i < info->count; i++) { if (ui_indices[i] > max_ui) max_ui = ui_indices[i]; if (ui_indices[i] < min_ui) min_ui = ui_indices[i]; } @@ -1071,16 +1040,16 @@ static void u_vbuf_get_minmax_index(struct pipe_context *pipe, const unsigned short *us_indices = (const unsigned short*)indices; unsigned max_us = 0; unsigned min_us = ~0U; - if (primitive_restart) { - for (i = 0; i < count; i++) { - if (us_indices[i] != restart_index) { + if (info->primitive_restart) { + for (i = 0; i < info->count; i++) { + if (us_indices[i] != info->restart_index) { if (us_indices[i] > max_us) max_us = us_indices[i]; if (us_indices[i] < min_us) min_us = us_indices[i]; } } } else { - for (i = 0; i < count; i++) { + for (i = 0; i < info->count; i++) { if (us_indices[i] > max_us) max_us = us_indices[i]; if (us_indices[i] < min_us) min_us = us_indices[i]; } @@ -1093,16 +1062,16 @@ static void u_vbuf_get_minmax_index(struct pipe_context *pipe, const unsigned char *ub_indices = (const unsigned char*)indices; unsigned max_ub = 0; unsigned min_ub = ~0U; - if (primitive_restart) { - for (i = 0; i < count; i++) { - if (ub_indices[i] != restart_index) { + if (info->primitive_restart) { + for (i = 0; i < info->count; i++) { + if (ub_indices[i] != info->restart_index) { if (ub_indices[i] > max_ub) max_ub = ub_indices[i]; if (ub_indices[i] < min_ub) min_ub = ub_indices[i]; } } } else { - for (i = 0; i < count; i++) { + for (i = 0; i < info->count; i++) { if (ub_indices[i] > max_ub) max_ub = ub_indices[i]; if (ub_indices[i] < min_ub) min_ub = ub_indices[i]; } @@ -1167,7 +1136,7 @@ void u_vbuf_draw_vbo(struct u_vbuf *mgr, const struct pipe_draw_info *info) struct pipe_transfer *transfer = NULL; int *data; - if (new_info.indexed) { + if (new_info.index_size) { data = pipe_buffer_map_range(pipe, new_info.indirect->buffer, new_info.indirect->offset, 20, PIPE_TRANSFER_READ, &transfer); @@ -1188,7 +1157,7 @@ void u_vbuf_draw_vbo(struct u_vbuf *mgr, const struct pipe_draw_info *info) new_info.indirect = NULL; } - if (new_info.indexed) { + if (new_info.index_size) { /* See if anything needs to be done for per-vertex attribs. */ if (u_vbuf_need_minmax_index(mgr)) { int max_index; @@ -1197,10 +1166,8 @@ void u_vbuf_draw_vbo(struct u_vbuf *mgr, const struct pipe_draw_info *info) min_index = new_info.min_index; max_index = new_info.max_index; } else { - u_vbuf_get_minmax_index(mgr->pipe, &mgr->index_buffer, - new_info.primitive_restart, - new_info.restart_index, new_info.start, - new_info.count, &min_index, &max_index); + u_vbuf_get_minmax_index(mgr->pipe, &new_info, + &min_index, &max_index); } assert(min_index <= max_index); @@ -1236,16 +1203,14 @@ void u_vbuf_draw_vbo(struct u_vbuf *mgr, const struct pipe_draw_info *info) if (unroll_indices || incompatible_vb_mask || mgr->ve->incompatible_elem_mask) { - if (!u_vbuf_translate_begin(mgr, start_vertex, num_vertices, - new_info.start_instance, - new_info.instance_count, new_info.start, - new_info.count, min_index, unroll_indices)) { + if (!u_vbuf_translate_begin(mgr, &new_info, start_vertex, num_vertices, + min_index, unroll_indices)) { debug_warn_once("u_vbuf_translate_begin() failed"); return; } if (unroll_indices) { - new_info.indexed = FALSE; + new_info.index_size = 0; new_info.index_bias = 0; new_info.min_index = 0; new_info.max_index = new_info.count - 1; diff --git a/src/gallium/auxiliary/util/u_vbuf.h b/src/gallium/auxiliary/util/u_vbuf.h index ddfa844d27f..d0704524561 100644 --- a/src/gallium/auxiliary/util/u_vbuf.h +++ b/src/gallium/auxiliary/util/u_vbuf.h @@ -72,8 +72,6 @@ void u_vbuf_set_vertex_elements(struct u_vbuf *mgr, unsigned count, void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, unsigned start_slot, unsigned count, const struct pipe_vertex_buffer *bufs); -void u_vbuf_set_index_buffer(struct u_vbuf *mgr, - const struct pipe_index_buffer *ib); void u_vbuf_draw_vbo(struct u_vbuf *mgr, const struct pipe_draw_info *info); /* Save/restore functionality. */ |