summaryrefslogtreecommitdiff
path: root/src/mesa
diff options
context:
space:
mode:
authorMarek Olšák <marek.olsak@amd.com>2022-12-11 17:53:59 -0500
committerMarek Olšák <marek.olsak@amd.com>2022-12-18 14:23:22 -0500
commit819627041e737b05d7a9a5c74e29fd9994ec9115 (patch)
tree85f5f35076b5e895cb9fe654ab1132c9b97f1988 /src/mesa
parentea11f48a53e31fdc94c122d1259f45658635748f (diff)
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>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/main/dd.h1
-rw-r--r--src/mesa/main/draw.c50
-rw-r--r--src/mesa/state_tracker/st_draw.c20
-rw-r--r--src/mesa/state_tracker/st_draw_feedback.c3
-rw-r--r--src/mesa/vbo/vbo_minmax_index.c6
-rw-r--r--src/mesa/vbo/vbo_save_api.c2
-rw-r--r--src/mesa/vbo/vbo_save_draw.c3
7 files changed, 48 insertions, 37 deletions
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 02f96c66d6c..972f515dba9 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -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,
diff --git a/src/mesa/main/draw.c b/src/mesa/main/draw.c
index 29db6eab60f..980541cd8c7 100644
--- a/src/mesa/main/draw.c
+++ b/src/mesa/main/draw.c
@@ -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;
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 167ef63e0b0..29b232f28e9 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -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;
}
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index 4914ab2b15e..341f5af0d0b 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -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);
}
diff --git a/src/mesa/vbo/vbo_minmax_index.c b/src/mesa/vbo/vbo_minmax_index.c
index c761780f686..c0851fa7c5a 100644
--- a/src/mesa/vbo/vbo_minmax_index.c
+++ b/src/mesa/vbo/vbo_minmax_index.c
@@ -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,
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index 7fa3df3b2f4..5f92a4d16ff 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -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;
diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c
index 284da5e8fa1..b5cf711a64b 100644
--- a/src/mesa/vbo/vbo_save_draw.c
+++ b/src/mesa/vbo/vbo_save_draw.c
@@ -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);