mesa: set pipe_draw_info::index::resource directly and remove gl_bo

The motivation is to remove branching from prepare_indexed_draw
and remove the unsafe hack in vbo_save_playback_vertex_list.

There is some duplication that is not identical in all 3 cases.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20287>
This commit is contained in:
Marek Olšák 2022-12-11 17:53:59 -05:00
parent ea11f48a53
commit 819627041e
8 changed files with 48 additions and 40 deletions

View file

@ -55,8 +55,6 @@
extern "C" {
#endif
struct gl_buffer_object;
/**
* Implementation limits
*/
@ -879,7 +877,6 @@ struct pipe_draw_info
*/
union {
struct pipe_resource *resource; /**< real buffer */
struct gl_buffer_object *gl_bo; /**< for the GL frontend, not passed to drivers */
const void *user; /**< pointer to a user buffer */
} index;

View file

@ -154,7 +154,6 @@ struct dd_function_table {
* - info->min_index (if index_bounds_valid is false)
* - info->max_index (if index_bounds_valid is false)
* - info->drawid (if increment_draw_id is true)
* - info->index.gl_bo (if index_size && !has_user_indices)
*/
void (*DrawGallium)(struct gl_context *ctx,
struct pipe_draw_info *info,

View file

@ -45,6 +45,7 @@
#include "state_tracker/st_context.h"
#include "state_tracker/st_draw.h"
#include "util/u_threaded_context.h"
typedef struct {
GLuint count;
@ -1636,14 +1637,23 @@ _mesa_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
draw.start = 0;
} else {
uintptr_t start = (uintptr_t) indices;
if (unlikely(index_bo->Size < start)) {
if (unlikely(index_bo->Size < start || !index_bo->buffer)) {
_mesa_warning(ctx, "Invalid indices offset 0x%" PRIxPTR
" (indices buffer size is %ld bytes)."
" Draw skipped.", start, index_bo->Size);
" (indices buffer size is %ld bytes)"
" or unallocated buffer (%u). Draw skipped.",
start, index_bo->Size, !!index_bo->buffer);
return;
}
info.index.gl_bo = index_bo;
draw.start = start >> index_size_shift;
if (ctx->st->pipe->draw_vbo == tc_draw_vbo) {
/* Fast path for u_threaded_context to eliminate atomics. */
info.index.resource = _mesa_get_bufferobj_reference(ctx, index_bo);
info.take_index_buffer_ownership = true;
} else {
info.index.resource = index_bo->buffer;
}
}
draw.index_bias = basevertex;
@ -2004,10 +2014,21 @@ _mesa_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
info.view_mask = 0;
info.restart_index = ctx->Array._RestartIndex[index_size_shift];
if (info.has_user_indices)
if (info.has_user_indices) {
info.index.user = (void*)min_index_ptr;
else
info.index.gl_bo = index_bo;
} else {
if (ctx->st->pipe->draw_vbo == tc_draw_vbo) {
/* Fast path for u_threaded_context to eliminate atomics. */
info.index.resource = _mesa_get_bufferobj_reference(ctx, index_bo);
info.take_index_buffer_ownership = true;
} else {
info.index.resource = index_bo->buffer;
}
/* No index buffer storage allocated - nothing to do. */
if (!info.index.resource)
return;
}
if (!fallback &&
(!info.has_user_indices ||
@ -2429,11 +2450,24 @@ _mesa_MultiDrawElementsIndirect(GLenum mode, GLenum type,
/* Packed section end. */
info.restart_index = ctx->Array._RestartIndex[index_size_shift];
struct gl_buffer_object *index_bo = ctx->Array.VAO->IndexBufferObj;
if (ctx->st->pipe->draw_vbo == tc_draw_vbo) {
/* Fast path for u_threaded_context to eliminate atomics. */
info.index.resource = _mesa_get_bufferobj_reference(ctx, index_bo);
info.take_index_buffer_ownership = true;
} else {
info.index.resource = index_bo->buffer;
}
/* No index buffer storage allocated - nothing to do. */
if (!info.index.resource)
return;
const uint8_t *ptr = (const uint8_t *) indirect;
for (unsigned i = 0; i < primcount; i++) {
DrawElementsIndirectCommand *cmd = (DrawElementsIndirectCommand*)ptr;
info.index.gl_bo = ctx->Array.VAO->IndexBufferObj;
info.start_instance = cmd->baseInstance;
info.instance_count = cmd->primCount;

View file

@ -127,26 +127,6 @@ prepare_indexed_draw(/* pass both st and ctx to reduce dereferences */
info->index_bounds_valid = true;
}
if (!info->has_user_indices) {
if (st->pipe->draw_vbo == tc_draw_vbo) {
/* Fast path for u_threaded_context. This eliminates the atomic
* increment for the index buffer refcount when adding it into
* the threaded batch buffer.
*/
info->index.resource =
_mesa_get_bufferobj_reference(ctx, info->index.gl_bo);
info->take_index_buffer_ownership = true;
} else {
info->index.resource = info->index.gl_bo->buffer;
}
/* Return if the bound element array buffer doesn't have any backing
* storage. (nothing to do)
*/
if (unlikely(!info->index.resource))
return false;
}
}
return true;
}

View file

@ -173,9 +173,6 @@ st_feedback_draw_vbo(struct gl_context *ctx,
if (info->has_user_indices) {
mapped_indices = info->index.user;
} else {
info->index.resource = info->index.gl_bo->buffer;
if (!info->index.resource)
return; /* glBufferData wasn't called on the buffer */
mapped_indices = pipe_buffer_map(pipe, info->index.resource,
PIPE_MAP_READ, &ib_transfer);
}

View file

@ -364,6 +364,9 @@ vbo_get_minmax_indices_gallium(struct gl_context *ctx,
info->min_index = ~0;
info->max_index = 0;
struct gl_buffer_object *buf =
info->has_user_indices ? NULL : ctx->Array.VAO->IndexBufferObj;
for (unsigned i = 0; i < num_draws; i++) {
struct pipe_draw_start_count_bias draw = draws[i];
@ -378,8 +381,7 @@ vbo_get_minmax_indices_gallium(struct gl_context *ctx,
continue;
unsigned tmp_min, tmp_max;
vbo_get_minmax_index(ctx, info->has_user_indices ?
NULL : info->index.gl_bo,
vbo_get_minmax_index(ctx, buf,
info->index.user,
(GLintptr)draw.start * info->index_size,
draw.count, info->index_size,

View file

@ -881,7 +881,7 @@ compile_vertex_list(struct gl_context *ctx)
/* The other info fields will be updated in vbo_save_playback_vertex_list */
node->cold->info.index_size = 4;
node->cold->info.instance_count = 1;
node->cold->info.index.gl_bo = node->cold->ib.obj;
node->cold->info.index.resource = node->cold->ib.obj->buffer;
if (merged_prim_count == 1) {
node->cold->info.mode = merged_prims[0].mode;
node->start_count.start = merged_prims[0].start;

View file

@ -343,7 +343,7 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data, bool copy_to_c
assert(ctx->NewState == 0);
struct pipe_draw_info *info = (struct pipe_draw_info *) &node->cold->info;
void *gl_bo = info->index.gl_bo;
if (node->modes) {
ctx->Driver.DrawGalliumMultiMode(ctx, info,
node->start_counts,
@ -355,7 +355,6 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data, bool copy_to_c
ctx->Driver.DrawGallium(ctx, info, 0, node->start_counts,
node->num_draws);
}
info->index.gl_bo = gl_bo;
_mesa_restore_draw_vao(ctx, old_vao, old_vp_input_filter);