Commit a7930673 authored by Mike Blumenkrantz's avatar Mike Blumenkrantz 🏋 Committed by Marge Bot
Browse files

zink: consolidate and optimize index buffer handling during draw



this can be reorganized to have more readable handling
Reviewed-by: default avatarDave Airlie <airlied@redhat.com>
Part-of: <!11746>
parent 47ba3b79
Pipeline #354657 waiting for manual action with stages
......@@ -442,15 +442,28 @@ zink_draw_vbo(struct pipe_context *pctx,
ctx->gfx_pipeline_state.primitive_restart = dinfo->primitive_restart;
unsigned index_offset = 0;
unsigned index_size = dinfo->index_size;
struct pipe_resource *index_buffer = NULL;
if (dinfo->index_size > 0) {
if (dinfo->has_user_indices) {
if (!util_upload_index_buffer(pctx, dinfo, &draws[0], &index_buffer, &index_offset, 4)) {
debug_printf("util_upload_index_buffer() failed\n");
return;
}
} else
index_buffer = dinfo->index.resource;
if (index_size > 0) {
if (dinfo->has_user_indices) {
if (!util_upload_index_buffer(pctx, dinfo, &draws[0], &index_buffer, &index_offset, 4)) {
debug_printf("util_upload_index_buffer() failed\n");
return;
}
zink_batch_reference_resource_move(batch, zink_resource(index_buffer));
} else {
index_buffer = dinfo->index.resource;
zink_batch_reference_resource_rw(batch, zink_resource(index_buffer), false);
}
assert(index_size <= 4 && index_size != 3);
assert(index_size != 1 || screen->info.have_EXT_index_type_uint8);
const VkIndexType index_type[3] = {
VK_INDEX_TYPE_UINT8_EXT,
VK_INDEX_TYPE_UINT16,
VK_INDEX_TYPE_UINT32,
};
struct zink_resource *res = zink_resource(index_buffer);
vkCmdBindIndexBuffer(batch->state->cmdbuf, res->obj->buffer, index_offset, index_type[index_size >> 1]);
}
bool have_streamout = !!ctx->num_so_targets;
......@@ -625,7 +638,7 @@ zink_draw_vbo(struct pipe_context *pctx,
zink_bind_vertex_buffers(batch, ctx);
if (BITSET_TEST(ctx->gfx_stages[PIPE_SHADER_VERTEX]->nir->info.system_values_read, SYSTEM_VALUE_BASE_VERTEX)) {
unsigned draw_mode_is_indexed = dinfo->index_size > 0;
unsigned draw_mode_is_indexed = index_size > 0;
vkCmdPushConstants(batch->state->cmdbuf, ctx->curr_program->base.layout, VK_SHADER_STAGE_VERTEX_BIT,
offsetof(struct zink_gfx_push_constant, draw_mode_is_indexed), sizeof(unsigned),
&draw_mode_is_indexed);
......@@ -659,29 +672,7 @@ zink_draw_vbo(struct pipe_context *pctx,
unsigned draw_id = drawid_offset;
bool needs_drawid = ctx->drawid_broken;
batch->state->draw_count += num_draws;
if (dinfo->index_size > 0) {
VkIndexType index_type;
unsigned index_size = dinfo->index_size;
if (need_index_buffer_unref)
/* index buffer will have been promoted from uint8 to uint16 in this case */
index_size = MAX2(index_size, 2);
switch (index_size) {
case 1:
assert(screen->info.have_EXT_index_type_uint8);
index_type = VK_INDEX_TYPE_UINT8_EXT;
break;
case 2:
index_type = VK_INDEX_TYPE_UINT16;
break;
case 4:
index_type = VK_INDEX_TYPE_UINT32;
break;
default:
unreachable("unknown index size!");
}
struct zink_resource *res = zink_resource(index_buffer);
vkCmdBindIndexBuffer(batch->state->cmdbuf, res->obj->buffer, index_offset, index_type);
zink_batch_reference_resource_rw(batch, res, false);
if (index_size > 0) {
if (dindirect && dindirect->buffer) {
assert(num_draws == 1);
if (needs_drawid)
......@@ -730,9 +721,6 @@ zink_draw_vbo(struct pipe_context *pctx,
}
}
if (dinfo->index_size > 0 && (dinfo->has_user_indices || need_index_buffer_unref))
pipe_resource_reference(&index_buffer, NULL);
if (have_streamout) {
for (unsigned i = 0; i < ctx->num_so_targets; i++) {
struct zink_so_target *t = zink_so_target(ctx->so_targets[i]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment