mesa: switch Draw(Range)Elements(BaseVertex) calls to DrawGallium

This makes gallium faster because st/mesa doesn't have to translate
_mesa_prim.

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7679>
This commit is contained in:
Marek Olšák 2020-11-01 16:37:23 -05:00
parent 2358da81d2
commit e99e7aa4c1

View file

@ -279,8 +279,8 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
} }
static inline void static inline unsigned
get_index_size(GLenum type, struct _mesa_index_buffer *ib) get_index_size_shift(GLenum type)
{ {
/* The type is already validated, so use a fast conversion. /* The type is already validated, so use a fast conversion.
* *
@ -290,7 +290,7 @@ get_index_size(GLenum type, struct _mesa_index_buffer *ib)
* *
* Divide by 2 to get 0,1,2. * Divide by 2 to get 0,1,2.
*/ */
ib->index_size_shift = (type - GL_UNSIGNED_BYTE) >> 1; return (type - GL_UNSIGNED_BYTE) >> 1;
} }
/** /**
@ -1005,29 +1005,46 @@ _mesa_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
GLint basevertex, GLuint numInstances, GLint basevertex, GLuint numInstances,
GLuint baseInstance) GLuint baseInstance)
{ {
struct _mesa_index_buffer ib; if (skip_draw_elements(ctx, count, indices))
struct _mesa_prim prim; return;
if (!index_bounds_valid) { if (!index_bounds_valid) {
assert(start == 0u); assert(start == 0u);
assert(end == ~0u); assert(end == ~0u);
} }
if (skip_draw_elements(ctx, count, indices)) struct pipe_draw_info info;
return; struct pipe_draw_start_count draw;
unsigned index_size_shift = get_index_size_shift(type);
struct gl_buffer_object *index_bo = ctx->Array.VAO->IndexBufferObj;
ib.count = count; info.mode = mode;
ib.obj = ctx->Array.VAO->IndexBufferObj; info.vertices_per_patch = ctx->TessCtrlProgram.patch_vertices;
ib.ptr = indices; info.index_size = 1 << index_size_shift;
get_index_size(type, &ib); /* Packed section begin. */
info.primitive_restart = ctx->Array._PrimitiveRestart[index_size_shift];
info.has_user_indices = index_bo == NULL;
info.index_bounds_valid = index_bounds_valid;
info.increment_draw_id = false;
info._pad = 0;
/* Packed section end. */
info.start_instance = baseInstance;
info.instance_count = numInstances;
info.drawid = 0;
info.index_bias = basevertex;
info.restart_index = ctx->Array._RestartIndex[index_size_shift];
prim.begin = 1; if (info.has_user_indices) {
prim.end = 1; info.index.user = indices;
prim.mode = mode; draw.start = 0;
prim.start = 0; } else {
prim.count = count; info.index.gl_bo = index_bo;
prim.basevertex = basevertex; draw.start = (uintptr_t)indices >> index_size_shift;
prim.draw_id = 0; }
info.min_index = start;
info.max_index = end;
draw.count = count;
/* Need to give special consideration to rendering a range of /* Need to give special consideration to rendering a range of
* indices starting somewhere above zero. Typically the * indices starting somewhere above zero. Typically the
@ -1060,12 +1077,7 @@ _mesa_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
* for the latter case elsewhere. * for the latter case elsewhere.
*/ */
ctx->Driver.Draw(ctx, &prim, 1, &ib, ctx->Driver.DrawGallium(ctx, &info, &draw, 1);
index_bounds_valid,
ctx->Array._PrimitiveRestart[ib.index_size_shift],
ctx->Array._RestartIndex[ib.index_size_shift],
start, end,
numInstances, baseInstance);
if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) { if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
_mesa_flush(ctx); _mesa_flush(ctx);
@ -1424,7 +1436,7 @@ _mesa_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
if (primcount == 0) if (primcount == 0)
return; return;
get_index_size(type, &ib); ib.index_size_shift = get_index_size_shift(type);
min_index_ptr = (uintptr_t) indices[0]; min_index_ptr = (uintptr_t) indices[0];
max_index_ptr = 0; max_index_ptr = 0;
@ -1742,7 +1754,7 @@ _mesa_validated_multidrawelementsindirect(struct gl_context *ctx,
ib.count = 0; /* unknown */ ib.count = 0; /* unknown */
ib.obj = ctx->Array.VAO->IndexBufferObj; ib.obj = ctx->Array.VAO->IndexBufferObj;
ib.ptr = NULL; ib.ptr = NULL;
get_index_size(type, &ib); ib.index_size_shift = get_index_size_shift(type);
ctx->Driver.DrawIndirect(ctx, mode, ctx->DrawIndirectBuffer, indirect, ctx->Driver.DrawIndirect(ctx, mode, ctx->DrawIndirectBuffer, indirect,
drawcount, stride, drawcount_buffer, drawcount, stride, drawcount_buffer,