aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2017-04-02 16:24:39 +0200
committerMarek Olšák <[email protected]>2017-05-10 19:00:16 +0200
commit330d0607ed60fd3edca192e54b4246310f06652f (patch)
tree56bceba5b291ffcf42209ef1ab7ec515a8f5b666 /src/mesa
parent22f6624ed318e8131681ec1f2e7b3a59449df412 (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/mesa')
-rw-r--r--src/mesa/state_tracker/st_draw.c77
-rw-r--r--src/mesa/state_tracker/st_draw_feedback.c20
2 files changed, 40 insertions, 57 deletions
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 29381b654dd..3fee0cd1425 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -86,44 +86,14 @@ all_varyings_in_vbos(const struct gl_vertex_array *arrays[])
/**
- * Basically, translate Mesa's index buffer information into
- * a pipe_index_buffer object.
- */
-static void
-setup_index_buffer(struct st_context *st,
- const struct _mesa_index_buffer *ib)
-{
- struct pipe_index_buffer ibuffer;
- struct gl_buffer_object *bufobj = ib->obj;
-
- ibuffer.index_size = ib->index_size;
-
- /* get/create the index buffer object */
- if (_mesa_is_bufferobj(bufobj)) {
- /* indices are in a real VBO */
- ibuffer.buffer = st_buffer_object(bufobj)->buffer;
- ibuffer.offset = pointer_to_offset(ib->ptr);
- ibuffer.user_buffer = NULL;
- }
- else {
- /* indices are in user space memory */
- ibuffer.buffer = NULL;
- ibuffer.offset = 0;
- ibuffer.user_buffer = ib->ptr;
- }
-
- cso_set_index_buffer(st->cso_context, &ibuffer);
-}
-
-
-/**
* Set the restart index.
*/
static void
-setup_primitive_restart(struct gl_context *ctx, struct pipe_draw_info *info,
- unsigned index_size)
+setup_primitive_restart(struct gl_context *ctx, struct pipe_draw_info *info)
{
if (ctx->Array._PrimitiveRestart) {
+ unsigned index_size = info->index_size;
+
info->restart_index =
_mesa_primitive_restart_index(ctx, index_size);
@@ -176,6 +146,7 @@ st_draw_vbo(struct gl_context *ctx,
struct pipe_draw_info info;
const struct gl_vertex_array **arrays = ctx->Array._DrawArrays;
unsigned i;
+ unsigned start = 0;
/* Mesa core state should have been validated already */
assert(ctx->NewState == 0x0);
@@ -198,19 +169,29 @@ st_draw_vbo(struct gl_context *ctx,
util_draw_init_info(&info);
if (ib) {
+ struct gl_buffer_object *bufobj = ib->obj;
+
/* Get index bounds for user buffers. */
if (!index_bounds_valid)
if (!all_varyings_in_vbos(arrays))
vbo_get_minmax_indices(ctx, prims, ib, &min_index, &max_index,
nr_prims);
- setup_index_buffer(st, ib);
-
- info.indexed = TRUE;
+ info.index_size = ib->index_size;
info.min_index = min_index;
info.max_index = max_index;
- setup_primitive_restart(ctx, &info, ib->index_size);
+ if (_mesa_is_bufferobj(bufobj)) {
+ /* indices are in a real VBO */
+ info.index.resource = st_buffer_object(bufobj)->buffer;
+ start = pointer_to_offset(ib->ptr) / info.index_size;
+ } else {
+ /* indices are in user space memory */
+ info.has_user_indices = true;
+ info.index.user = ib->ptr;
+ }
+
+ setup_primitive_restart(ctx, &info);
}
else {
/* Transform feedback drawing is always non-indexed. */
@@ -226,7 +207,7 @@ st_draw_vbo(struct gl_context *ctx,
/* do actual drawing */
for (i = 0; i < nr_prims; i++) {
info.mode = translate_prim(ctx, prims[i].mode);
- info.start = prims[i].start;
+ info.start = start + prims[i].start;
info.count = prims[i].count;
info.start_instance = prims[i].base_instance;
info.instance_count = prims[i].num_instances;
@@ -239,11 +220,11 @@ st_draw_vbo(struct gl_context *ctx,
}
if (ST_DEBUG & DEBUG_DRAW) {
- debug_printf("st/draw: mode %s start %u count %u indexed %d\n",
+ debug_printf("st/draw: mode %s start %u count %u index_size %d\n",
u_prim_name(info.mode),
info.start,
info.count,
- info.indexed);
+ info.index_size);
}
/* Don't call u_trim_pipe_prim. Drivers should do it if they need it. */
@@ -284,14 +265,20 @@ st_indirect_draw_vbo(struct gl_context *ctx,
memset(&indirect, 0, sizeof(indirect));
util_draw_init_info(&info);
+ info.start = 0; /* index offset / index size */
if (ib) {
- setup_index_buffer(st, ib);
+ struct gl_buffer_object *bufobj = ib->obj;
+
+ /* indices are always in a real VBO */
+ assert(_mesa_is_bufferobj(bufobj));
- info.indexed = TRUE;
+ info.index_size = ib->index_size;
+ info.index.resource = st_buffer_object(bufobj)->buffer;
+ info.start = pointer_to_offset(ib->ptr) / info.index_size;
/* Primitive restart is not handled by the VBO module in this case. */
- setup_primitive_restart(ctx, &info, ib->index_size);
+ setup_primitive_restart(ctx, &info);
}
info.mode = translate_prim(ctx, mode);
@@ -301,10 +288,10 @@ st_indirect_draw_vbo(struct gl_context *ctx,
indirect.offset = indirect_offset;
if (ST_DEBUG & DEBUG_DRAW) {
- debug_printf("st/draw indirect: mode %s drawcount %d indexed %d\n",
+ debug_printf("st/draw indirect: mode %s drawcount %d index_size %d\n",
u_prim_name(info.mode),
draw_count,
- info.indexed);
+ info.index_size);
}
if (!st->has_multi_draw_indirect) {
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index ad92ff5233d..987a1564e28 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -128,7 +128,6 @@ st_feedback_draw_vbo(struct gl_context *ctx,
const struct pipe_shader_state *vs;
struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS];
struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
- struct pipe_index_buffer ibuffer;
struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = {NULL};
struct pipe_transfer *ib_transfer = NULL;
const struct gl_vertex_array **arrays = ctx->Array._DrawArrays;
@@ -238,31 +237,29 @@ st_feedback_draw_vbo(struct gl_context *ctx,
draw_set_vertex_buffers(draw, 0, vp->num_inputs, vbuffers);
draw_set_vertex_elements(draw, vp->num_inputs, velements);
- memset(&ibuffer, 0, sizeof(ibuffer));
+ unsigned start = 0;
+
if (ib) {
struct gl_buffer_object *bufobj = ib->obj;
+ unsigned index_size = ib->index_size;
- ibuffer.index_size = ib->index_size;
- if (ibuffer.index_size == 0)
+ if (index_size == 0)
goto out_unref_vertex;
if (bufobj && bufobj->Name) {
struct st_buffer_object *stobj = st_buffer_object(bufobj);
- pipe_resource_reference(&ibuffer.buffer, stobj->buffer);
- ibuffer.offset = pointer_to_offset(ib->ptr);
-
+ start = pointer_to_offset(ib->ptr) / index_size;
mapped_indices = pipe_buffer_map(pipe, stobj->buffer,
PIPE_TRANSFER_READ, &ib_transfer);
}
else {
- /* skip setting ibuffer.buffer as the draw module does not use it */
mapped_indices = ib->ptr;
}
draw_set_indexes(draw,
- (ubyte *) mapped_indices + ibuffer.offset,
- ibuffer.index_size, ~0);
+ (ubyte *) mapped_indices,
+ index_size, ~0);
}
/* set the constant buffer */
@@ -273,7 +270,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
/* draw here */
for (i = 0; i < nr_prims; i++) {
- draw_arrays(draw, prims[i].mode, prims[i].start, prims[i].count);
+ draw_arrays(draw, prims[i].mode, start + prims[i].start, prims[i].count);
}
@@ -284,7 +281,6 @@ st_feedback_draw_vbo(struct gl_context *ctx,
draw_set_indexes(draw, NULL, 0, 0);
if (ib_transfer)
pipe_buffer_unmap(pipe, ib_transfer);
- pipe_resource_reference(&ibuffer.buffer, NULL);
}
out_unref_vertex: