Commit 1cd455b1 authored by Marek Olšák's avatar Marek Olšák Committed by Marge Bot

gallium: extend draw_vbo to support multi draws

Essentially rename multi_draw to draw_vbo and remove start and count
from pipe_draw_info.

This is only an interface change. It doesn't add multi draw support
anywhere.
Acked-by: Pierre-Eric Pelloux-Prayer's avatarPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <!7441>
parent 80b39107
......@@ -1723,7 +1723,8 @@ cso_restore_state(struct cso_context *cso)
void
cso_draw_vbo(struct cso_context *cso,
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect)
const struct pipe_draw_indirect_info *indirect,
const struct pipe_draw_start_count draw)
{
struct u_vbuf *vbuf = cso->vbuf_current;
......@@ -1738,10 +1739,10 @@ cso_draw_vbo(struct cso_context *cso,
indirect->count_from_stream_output == NULL);
if (vbuf) {
u_vbuf_draw_vbo(vbuf, info, indirect);
u_vbuf_draw_vbo(vbuf, info, indirect, draw);
} else {
struct pipe_context *pipe = cso->pipe;
pipe->draw_vbo(pipe, info, indirect);
pipe->draw_vbo(pipe, info, indirect, &draw, 1);
}
}
......@@ -1749,16 +1750,18 @@ void
cso_draw_arrays(struct cso_context *cso, uint mode, uint start, uint count)
{
struct pipe_draw_info info;
struct pipe_draw_start_count draw;
util_draw_init_info(&info);
info.mode = mode;
info.start = start;
info.count = count;
info.min_index = start;
info.max_index = start + count - 1;
cso_draw_vbo(cso, &info, NULL);
draw.start = start;
draw.count = count;
cso_draw_vbo(cso, &info, NULL, draw);
}
void
......@@ -1767,16 +1770,18 @@ cso_draw_arrays_instanced(struct cso_context *cso, uint mode,
uint start_instance, uint instance_count)
{
struct pipe_draw_info info;
struct pipe_draw_start_count draw;
util_draw_init_info(&info);
info.mode = mode;
info.start = start;
info.count = count;
info.min_index = start;
info.max_index = start + count - 1;
info.start_instance = start_instance;
info.instance_count = instance_count;
cso_draw_vbo(cso, &info, NULL);
draw.start = start;
draw.count = count;
cso_draw_vbo(cso, &info, NULL, draw);
}
......@@ -218,7 +218,8 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx,
void
cso_draw_vbo(struct cso_context *cso,
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect);
const struct pipe_draw_indirect_info *indirect,
const struct pipe_draw_start_count draw);
void
cso_draw_arrays_instanced(struct cso_context *cso, uint mode,
......
......@@ -324,7 +324,9 @@ draw_set_mapped_so_targets(struct draw_context *draw,
void draw_vbo(struct draw_context *draw,
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect);
const struct pipe_draw_indirect_info *indirect,
const struct pipe_draw_start_count *draws,
unsigned num_draws);
/*******************************************************************************
......
......@@ -382,11 +382,12 @@ draw_print_arrays(struct draw_context *draw, uint prim, int start, uint count)
*/
static void
draw_pt_arrays_restart(struct draw_context *draw,
const struct pipe_draw_info *info)
const struct pipe_draw_info *info,
const struct pipe_draw_start_count *draw_info)
{
const unsigned prim = info->mode;
const unsigned start = info->start;
const unsigned count = info->count;
const unsigned start = draw_info->start;
const unsigned count = draw_info->count;
const unsigned elt_max = draw->pt.user.eltMax;
unsigned i, j, cur_start, cur_count;
/* The largest index within a loop using the i variable as the index.
......@@ -441,21 +442,24 @@ draw_pt_arrays_restart(struct draw_context *draw,
static void
resolve_draw_info(const struct pipe_draw_info *raw_info,
const struct pipe_draw_indirect_info *indirect,
const struct pipe_draw_start_count *raw_draw,
struct pipe_draw_info *info,
struct pipe_draw_start_count *draw,
struct pipe_vertex_buffer *vertex_buffer)
{
memcpy(info, raw_info, sizeof(struct pipe_draw_info));
memcpy(draw, raw_draw, sizeof(struct pipe_draw_start_count));
if (indirect && indirect->count_from_stream_output) {
struct draw_so_target *target =
(struct draw_so_target *)indirect->count_from_stream_output;
assert(vertex_buffer != NULL);
info->count = vertex_buffer->stride == 0 ? 0 :
draw->count = vertex_buffer->stride == 0 ? 0 :
target->internal_offset / vertex_buffer->stride;
/* Stream output draw can not be indexed */
debug_assert(!info->index_size);
info->max_index = info->count - 1;
info->max_index = draw->count - 1;
}
}
......@@ -468,13 +472,16 @@ resolve_draw_info(const struct pipe_draw_info *raw_info,
void
draw_vbo(struct draw_context *draw,
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect)
const struct pipe_draw_indirect_info *indirect,
const struct pipe_draw_start_count *draws,
unsigned num_draws)
{
unsigned instance;
unsigned index_limit;
unsigned count;
unsigned fpstate = util_fpstate_get();
struct pipe_draw_info resolved_info;
struct pipe_draw_start_count resolved_draw;
if (info->instance_count == 0)
return;
......@@ -484,13 +491,16 @@ draw_vbo(struct draw_context *draw,
*/
util_fpstate_set_denorms_to_zero(fpstate);
resolve_draw_info(info, indirect, &resolved_info, &(draw->pt.vertex_buffer[0]));
resolve_draw_info(info, indirect, &draws[0], &resolved_info,
&resolved_draw, &(draw->pt.vertex_buffer[0]));
info = &resolved_info;
draws = &resolved_draw;
num_draws = 1;
if (info->index_size)
assert(draw->pt.user.elts);
count = info->count;
count = draws[0].count;
draw->pt.user.eltBias = info->index_bias;
draw->pt.user.min_index = info->min_index;
......@@ -502,7 +512,7 @@ draw_vbo(struct draw_context *draw,
if (0)
debug_printf("draw_vbo(mode=%u start=%u count=%u):\n",
info->mode, info->start, count);
info->mode, draws[0].start, count);
if (0)
tgsi_dump(draw->vs.vertex_shader->state.tokens, 0);
......@@ -530,7 +540,7 @@ draw_vbo(struct draw_context *draw,
}
if (0)
draw_print_arrays(draw, info->mode, info->start, MIN2(count, 20));
draw_print_arrays(draw, info->mode, draws[0].start, MIN2(count, 20));
index_limit = util_draw_max_index(draw->pt.vertex_buffer,
draw->pt.vertex_element,
......@@ -554,7 +564,7 @@ draw_vbo(struct draw_context *draw,
}
draw->pt.max_index = index_limit - 1;
draw->start_index = info->start;
draw->start_index = draws[0].start;
/*
* TODO: We could use draw->pt.max_index to further narrow
......@@ -575,10 +585,10 @@ draw_vbo(struct draw_context *draw,
draw_new_instance(draw);
if (info->primitive_restart) {
draw_pt_arrays_restart(draw, info);
draw_pt_arrays_restart(draw, info, &draws[0]);
}
else {
draw_pt_arrays(draw, info->mode, info->start, count);
draw_pt_arrays(draw, info->mode, draws[0].start, count);
}
}
......
......@@ -352,11 +352,13 @@ dd_dump_flush(struct dd_draw_state *dstate, struct call_flush *info, FILE *f)
static void
dd_dump_draw_vbo(struct dd_draw_state *dstate, struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect, FILE *f)
const struct pipe_draw_indirect_info *indirect,
const struct pipe_draw_start_count *draw, FILE *f)
{
int sh, i;
DUMP(draw_info, info);
DUMP(draw_start_count, draw);
if (indirect) {
if (indirect->buffer)
DUMP_M(resource, indirect, buffer);
......@@ -633,8 +635,9 @@ dd_dump_call(FILE *f, struct dd_draw_state *state, struct dd_call *call)
dd_dump_flush(state, &call->info.flush, f);
break;
case CALL_DRAW_VBO:
dd_dump_draw_vbo(state, &call->info.draw_vbo.draw,
&call->info.draw_vbo.indirect, f);
dd_dump_draw_vbo(state, &call->info.draw_vbo.info,
&call->info.draw_vbo.indirect,
&call->info.draw_vbo.draw, f);
break;
case CALL_LAUNCH_GRID:
dd_dump_launch_grid(state, &call->info.launch_grid, f);
......@@ -710,11 +713,11 @@ dd_unreference_copy_of_call(struct dd_call *dst)
pipe_so_target_reference(&dst->info.draw_vbo.indirect.count_from_stream_output, NULL);
pipe_resource_reference(&dst->info.draw_vbo.indirect.buffer, NULL);
pipe_resource_reference(&dst->info.draw_vbo.indirect.indirect_draw_count, NULL);
if (dst->info.draw_vbo.draw.index_size &&
!dst->info.draw_vbo.draw.has_user_indices)
pipe_resource_reference(&dst->info.draw_vbo.draw.index.resource, NULL);
if (dst->info.draw_vbo.info.index_size &&
!dst->info.draw_vbo.info.has_user_indices)
pipe_resource_reference(&dst->info.draw_vbo.info.index.resource, NULL);
else
dst->info.draw_vbo.draw.index.user = NULL;
dst->info.draw_vbo.info.index.user = NULL;
break;
case CALL_LAUNCH_GRID:
pipe_resource_reference(&dst->info.launch_grid.indirect, NULL);
......@@ -1300,17 +1303,20 @@ dd_context_flush(struct pipe_context *_pipe,
static void
dd_context_draw_vbo(struct pipe_context *_pipe,
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect)
const struct pipe_draw_indirect_info *indirect,
const struct pipe_draw_start_count *draws,
unsigned num_draws)
{
struct dd_context *dctx = dd_context(_pipe);
struct pipe_context *pipe = dctx->pipe;
struct dd_draw_record *record = dd_create_record(dctx);
record->call.type = CALL_DRAW_VBO;
record->call.info.draw_vbo.draw = *info;
record->call.info.draw_vbo.info = *info;
record->call.info.draw_vbo.draw = draws[0];
if (info->index_size && !info->has_user_indices) {
record->call.info.draw_vbo.draw.index.resource = NULL;
pipe_resource_reference(&record->call.info.draw_vbo.draw.index.resource,
record->call.info.draw_vbo.info.index.resource = NULL;
pipe_resource_reference(&record->call.info.draw_vbo.info.index.resource,
info->index.resource);
}
......@@ -1330,7 +1336,7 @@ dd_context_draw_vbo(struct pipe_context *_pipe,
}
dd_before_draw(dctx, record);
pipe->draw_vbo(pipe, info, indirect);
pipe->draw_vbo(pipe, info, indirect, draws, num_draws);
dd_after_draw(dctx, record);
}
......
......@@ -122,8 +122,9 @@ struct call_flush {
};
struct call_draw_info {
struct pipe_draw_info draw;
struct pipe_draw_info info;
struct pipe_draw_indirect_info indirect;
struct pipe_draw_start_count draw;
};
struct call_get_query_result_resource {
......
......@@ -31,7 +31,9 @@
#include "util/u_transfer.h"
static void noop_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect)
const struct pipe_draw_indirect_info *indirect,
const struct pipe_draw_start_count *draws,
unsigned num_draws)
{
}
......
......@@ -115,7 +115,9 @@ rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
static void
rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *_info,
const struct pipe_draw_indirect_info *_indirect)
const struct pipe_draw_indirect_info *_indirect,
const struct pipe_draw_start_count *draws,
unsigned num_draws)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
struct pipe_context *pipe = rb_pipe->pipe;
......@@ -133,7 +135,7 @@ rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *_info,
if (!(rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] && rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT]->disabled) &&
!(rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] && rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY]->disabled) &&
!(rb_pipe->curr.shader[PIPE_SHADER_VERTEX] && rb_pipe->curr.shader[PIPE_SHADER_VERTEX]->disabled))
pipe->draw_vbo(pipe, &info, _indirect);
pipe->draw_vbo(pipe, &info, _indirect, draws, num_draws);
mtx_unlock(&rb_pipe->call_mutex);
rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
......
......@@ -90,7 +90,9 @@ trace_surface_unwrap(struct trace_context *tr_ctx,
static void
trace_context_draw_vbo(struct pipe_context *_pipe,
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect)
const struct pipe_draw_indirect_info *indirect,
const struct pipe_draw_start_count *draws,
unsigned num_draws)
{
struct trace_context *tr_ctx = trace_context(_pipe);
struct pipe_context *pipe = tr_ctx->pipe;
......@@ -100,10 +102,12 @@ trace_context_draw_vbo(struct pipe_context *_pipe,
trace_dump_arg(ptr, pipe);
trace_dump_arg(draw_info, info);
trace_dump_arg(draw_indirect_info, indirect);
trace_dump_struct_array(draw_start_count, draws, num_draws);
trace_dump_arg(uint, num_draws);
trace_dump_trace_flush();
pipe->draw_vbo(pipe, info, indirect);
pipe->draw_vbo(pipe, info, indirect, draws, num_draws);
trace_dump_call_end();
}
......
......@@ -775,11 +775,7 @@ void trace_dump_draw_info(const struct pipe_draw_info *state)
trace_dump_member(uint, state, index_size);
trace_dump_member(uint, state, has_user_indices);
trace_dump_member(uint, state, mode);
trace_dump_member(uint, state, start);
trace_dump_member(uint, state, count);
trace_dump_member(uint, state, start_instance);
trace_dump_member(uint, state, instance_count);
......@@ -796,6 +792,17 @@ void trace_dump_draw_info(const struct pipe_draw_info *state)
trace_dump_struct_end();
}
void trace_dump_draw_start_count(const struct pipe_draw_start_count *state)
{
if (!trace_dumping_enabled_locked())
return;
trace_dump_struct_begin("pipe_draw_start_count");
trace_dump_member(uint, state, start);
trace_dump_member(uint, state, count);
trace_dump_struct_end();
}
void trace_dump_draw_indirect_info(const struct pipe_draw_indirect_info *state)
{
if (!trace_dumping_enabled_locked())
......
......@@ -82,6 +82,8 @@ void trace_dump_shader_buffer(const struct pipe_shader_buffer *buffer);
void trace_dump_draw_info(const struct pipe_draw_info *state);
void trace_dump_draw_start_count(const struct pipe_draw_start_count *state);
void trace_dump_draw_indirect_info(const struct pipe_draw_indirect_info *state);
void trace_dump_blit_info(const struct pipe_blit_info *);
......
......@@ -97,9 +97,11 @@ util_primconvert_save_rasterizer_state(struct primconvert_context *pc,
void
util_primconvert_draw_vbo(struct primconvert_context *pc,
const struct pipe_draw_info *info)
const struct pipe_draw_info *info,
const struct pipe_draw_start_count *draw)
{
struct pipe_draw_info new_info;
struct pipe_draw_start_count new_draw;
struct pipe_transfer *src_transfer = NULL;
u_translate_func trans_func;
u_generate_func gen_func;
......@@ -121,10 +123,10 @@ util_primconvert_draw_vbo(struct primconvert_context *pc,
unsigned index_size;
u_index_translator(pc->cfg.primtypes_mask,
info->mode, info->index_size, info->count,
info->mode, info->index_size, draw->count,
pc->api_pv, pc->api_pv,
info->primitive_restart ? PR_ENABLE : PR_DISABLE,
&mode, &index_size, &new_info.count,
&mode, &index_size, &new_draw.count,
&trans_func);
new_info.mode = mode;
new_info.index_size = index_size;
......@@ -140,31 +142,31 @@ util_primconvert_draw_vbo(struct primconvert_context *pc,
unsigned index_size;
u_index_generator(pc->cfg.primtypes_mask,
info->mode, info->start, info->count,
info->mode, draw->start, draw->count,
pc->api_pv, pc->api_pv,
&mode, &index_size, &new_info.count,
&mode, &index_size, &new_draw.count,
&gen_func);
new_info.mode = mode;
new_info.index_size = index_size;
}
u_upload_alloc(pc->pipe->stream_uploader, 0, new_info.index_size * new_info.count, 4,
u_upload_alloc(pc->pipe->stream_uploader, 0, new_info.index_size * new_draw.count, 4,
&ib_offset, &new_info.index.resource, &dst);
new_info.start = ib_offset / new_info.index_size;
new_draw.start = ib_offset / new_info.index_size;
if (info->index_size) {
trans_func(src, info->start, info->count, new_info.count, info->restart_index, dst);
trans_func(src, draw->start, draw->count, new_draw.count, info->restart_index, dst);
if (pc->cfg.fixed_prim_restart && info->primitive_restart) {
new_info.restart_index = (1ull << (new_info.index_size * 8)) - 1;
if (info->restart_index != new_info.restart_index)
util_translate_prim_restart_data(new_info.index_size, dst, dst,
new_info.count,
new_draw.count,
info->restart_index);
}
}
else {
gen_func(info->start, new_info.count, dst);
gen_func(draw->start, new_draw.count, dst);
}
if (src_transfer)
......@@ -173,7 +175,7 @@ util_primconvert_draw_vbo(struct primconvert_context *pc,
u_upload_unmap(pc->pipe->stream_uploader);
/* to the translated draw: */
pc->pipe->draw_vbo(pc->pipe, &new_info, NULL);
pc->pipe->draw_vbo(pc->pipe, &new_info, NULL, &new_draw, 1);
pipe_resource_reference(&new_info.index.resource, NULL);
}
......@@ -46,6 +46,7 @@ void util_primconvert_save_rasterizer_state(struct primconvert_context *pc,
const struct pipe_rasterizer_state
*rast);
void util_primconvert_draw_vbo(struct primconvert_context *pc,
const struct pipe_draw_info *info);
const struct pipe_draw_info *info,
const struct pipe_draw_start_count *draw);
#endif /* U_PRIMCONVERT_H_ */
......@@ -176,14 +176,16 @@ util_draw_indirect(struct pipe_context *pipe,
}
for (unsigned i = 0; i < draw_count; i++) {
info.count = params[0];
struct pipe_draw_start_count draw;
draw.count = params[0];
info.instance_count = params[1];
info.start = params[2];
draw.start = params[2];
info.index_bias = info_in->index_size ? params[3] : 0;
info.start_instance = info_in->index_size ? params[4] : params[3];
info.drawid = i;
pipe->draw_vbo(pipe, &info, NULL);
pipe->draw_vbo(pipe, &info, NULL, &draw, 1);
params += indirect->stride / 4;
}
......
......@@ -55,15 +55,17 @@ util_draw_arrays(struct pipe_context *pipe,
uint count)
{
struct pipe_draw_info info;
struct pipe_draw_start_count draw;
util_draw_init_info(&info);
info.mode = mode;
info.start = start;
info.count = count;
info.min_index = start;
info.max_index = start + count - 1;
pipe->draw_vbo(pipe, &info, NULL);
draw.start = start;
draw.count = count;
pipe->draw_vbo(pipe, &info, NULL, &draw, 1);
}
static inline void
......@@ -75,17 +77,19 @@ util_draw_elements(struct pipe_context *pipe,
uint count)
{
struct pipe_draw_info info;
struct pipe_draw_start_count draw;
util_draw_init_info(&info);
info.index.user = indices;
info.has_user_indices = true;
info.index_size = index_size;
info.mode = mode;
info.start = start;
info.count = count;
info.index_bias = index_bias;
pipe->draw_vbo(pipe, &info, NULL);
draw.start = start;
draw.count = count;
pipe->draw_vbo(pipe, &info, NULL, &draw, 1);
}
static inline void
......@@ -97,18 +101,20 @@ util_draw_arrays_instanced(struct pipe_context *pipe,
uint instance_count)
{
struct pipe_draw_info info;
struct pipe_draw_start_count draw;
util_draw_init_info(&info);
info.mode = mode;
info.start = start;
info.count = count;
info.start_instance = start_instance;
info.instance_count = instance_count;
info.index_bounds_valid = true;
info.min_index = start;
info.max_index = start + count - 1;
pipe->draw_vbo(pipe, &info, NULL);
draw.start = start;
draw.count = count;
pipe->draw_vbo(pipe, &info, NULL, &draw, 1);
}
static inline void
......@@ -123,19 +129,21 @@ util_draw_elements_instanced(struct pipe_context *pipe,
uint instance_count)
{
struct pipe_draw_info info;
struct pipe_draw_start_count draw;
util_draw_init_info(&info);
info.index.user = indices;
info.has_user_indices = true;
info.index_size = index_size;
info.mode = mode;
info.start = start;
info.count = count;
info.index_bias = index_bias;
info.start_instance = start_instance;
info.instance_count = instance_count;