[Mesa-dev] [PATCH 5/6] st/mesa: assume all drivers support user index buffers
Marek Olšák
maraeo at gmail.com
Wed Feb 22 20:00:51 UTC 2017
From: Marek Olšák <marek.olsak at amd.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
---
src/mesa/state_tracker/st_context.c | 2 --
src/mesa/state_tracker/st_context.h | 1 -
src/mesa/state_tracker/st_draw.c | 50 ++++++++++---------------------------
3 files changed, 13 insertions(+), 40 deletions(-)
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index f4ad6d8..4cc4dab 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -331,22 +331,20 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
st->pipe = pipe;
/* XXX: this is one-off, per-screen init: */
st_debug_init();
/* state tracker needs the VBO module */
_vbo_CreateContext(ctx);
st->dirty = ST_ALL_STATES_MASK;
- st->has_user_indexbuf =
- screen->get_param(screen, PIPE_CAP_USER_INDEX_BUFFERS);
st->has_user_constbuf =
screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS);
/* Drivers still have to upload zero-stride vertex attribs manually
* with the GL core profile, but they don't have to deal with any complex
* user vertex buffer uploads.
*/
unsigned vbuf_flags =
ctx->API == API_OPENGL_CORE ? U_VBUF_FLAG_NO_USER_VBOS : 0;
st->cso_context = cso_create_context(pipe, vbuf_flags);
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 942fdd7..bb00384 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -78,21 +78,20 @@ struct st_context
boolean has_time_elapsed;
boolean has_shader_model3;
boolean has_etc1;
boolean has_etc2;
boolean prefer_blit_based_texture_transfer;
boolean force_persample_in_shader;
boolean has_shareable_shaders;
boolean has_half_float_packing;
boolean has_multi_draw_indirect;
boolean has_user_constbuf;
- boolean has_user_indexbuf;
/**
* If a shader can be created when we get its source.
* This means it has only 1 variant, not counting glBitmap and
* glDrawPixels.
*/
boolean shader_has_one_variant[MESA_SHADER_STAGES];
boolean needs_texcoord_semantic;
boolean apply_texture_swizzle_to_border_color;
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 8d54732..f04b6c2 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -81,55 +81,45 @@ all_varyings_in_vbos(const struct gl_vertex_array *arrays[])
!_mesa_is_bufferobj(arrays[i]->BufferObj))
return GL_FALSE;
return GL_TRUE;
}
/**
* Basically, translate Mesa's index buffer information into
* a pipe_index_buffer object.
- * \return TRUE or FALSE for success/failure
*/
-static boolean
+static void
setup_index_buffer(struct st_context *st,
- const struct _mesa_index_buffer *ib,
- struct pipe_index_buffer *ibuffer)
+ const struct _mesa_index_buffer *ib)
{
+ struct pipe_index_buffer ibuffer;
struct gl_buffer_object *bufobj = ib->obj;
- ibuffer->index_size = vbo_sizeof_ib_type(ib->type);
+ ibuffer.index_size = vbo_sizeof_ib_type(ib->type);
/* 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);
- }
- else if (!st->has_user_indexbuf) {
- /* upload indexes from user memory into a real buffer */
- u_upload_data(st->pipe->stream_uploader, 0,
- ib->count * ibuffer->index_size, 4, ib->ptr,
- &ibuffer->offset, &ibuffer->buffer);
- if (!ibuffer->buffer) {
- /* out of memory */
- return FALSE;
- }
- u_upload_unmap(st->pipe->stream_uploader);
+ 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->user_buffer = ib->ptr;
+ ibuffer.buffer = NULL;
+ ibuffer.offset = 0;
+ ibuffer.user_buffer = ib->ptr;
}
- cso_set_index_buffer(st->cso_context, ibuffer);
- return TRUE;
+ cso_set_index_buffer(st->cso_context, &ibuffer);
}
/**
* Set the restart index.
*/
static void
setup_primitive_restart(struct gl_context *ctx,
const struct _mesa_index_buffer *ib,
struct pipe_draw_info *info)
@@ -178,21 +168,20 @@ st_draw_vbo(struct gl_context *ctx,
GLuint nr_prims,
const struct _mesa_index_buffer *ib,
GLboolean index_bounds_valid,
GLuint min_index,
GLuint max_index,
struct gl_transform_feedback_object *tfb_vertcount,
unsigned stream,
struct gl_buffer_object *indirect)
{
struct st_context *st = st_context(ctx);
- struct pipe_index_buffer ibuffer = {0};
struct pipe_draw_info info;
const struct gl_vertex_array **arrays = ctx->Array._DrawArrays;
unsigned i;
/* Mesa core state should have been validated already */
assert(ctx->NewState == 0x0);
st_flush_bitmap_cache(st);
st_invalidate_readpix_cache(st);
@@ -208,24 +197,21 @@ st_draw_vbo(struct gl_context *ctx,
util_draw_init_info(&info);
if (ib) {
/* 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);
- if (!setup_index_buffer(st, ib, &ibuffer)) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBegin/DrawElements/DrawArray");
- return;
- }
+ setup_index_buffer(st, ib);
info.indexed = TRUE;
if (min_index != ~0U && max_index != ~0U) {
info.min_index = min_index;
info.max_index = max_index;
}
/* The VBO module handles restart for the non-indexed GLDrawArrays
* so we only set these fields for indexed drawing:
*/
@@ -269,64 +255,54 @@ st_draw_vbo(struct gl_context *ctx,
cso_draw_vbo(st->cso_context, &info);
}
else if (info.primitive_restart) {
/* don't trim, restarts might be inside index list */
cso_draw_vbo(st->cso_context, &info);
}
else if (u_trim_pipe_prim(prims[i].mode, &info.count)) {
cso_draw_vbo(st->cso_context, &info);
}
}
-
- if (ib && !st->has_user_indexbuf && !_mesa_is_bufferobj(ib->obj)) {
- pipe_resource_reference(&ibuffer.buffer, NULL);
- }
}
static void
st_indirect_draw_vbo(struct gl_context *ctx,
GLuint mode,
struct gl_buffer_object *indirect_data,
GLsizeiptr indirect_offset,
unsigned draw_count,
unsigned stride,
struct gl_buffer_object *indirect_params,
GLsizeiptr indirect_params_offset,
const struct _mesa_index_buffer *ib)
{
struct st_context *st = st_context(ctx);
- struct pipe_index_buffer ibuffer = {0};
struct pipe_draw_info info;
/* Mesa core state should have been validated already */
assert(ctx->NewState == 0x0);
assert(stride);
/* Validate state. */
if ((st->dirty | ctx->NewDriverState) & ST_PIPELINE_RENDER_STATE_MASK ||
st->gfx_shaders_may_be_dirty) {
st_validate_state(st, ST_PIPELINE_RENDER);
}
if (st->vertex_array_out_of_memory) {
return;
}
util_draw_init_info(&info);
if (ib) {
- if (!setup_index_buffer(st, ib, &ibuffer)) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "gl%sDrawElementsIndirect%s",
- (draw_count > 1) ? "Multi" : "",
- indirect_params ? "CountARB" : "");
- return;
- }
+ setup_index_buffer(st, ib);
info.indexed = TRUE;
/* Primitive restart is not handled by the VBO module in this case. */
setup_primitive_restart(ctx, ib, &info);
}
info.mode = translate_prim(ctx, mode);
info.vertices_per_patch = ctx->TessCtrlProgram.patch_vertices;
info.indirect = st_buffer_object(indirect_data)->buffer;
--
2.7.4
More information about the mesa-dev
mailing list