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

gallium: make pipe_draw_indirect_info * a draw_vbo parameter

This removes 8 bytes from pipe_draw_info (think u_threaded_context)
and a lot of info->indirect pointer indirections.
Reviewed-by: Pierre-Eric Pelloux-Prayer's avatarPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <!7441>
parent 1a717dca
......@@ -1722,25 +1722,26 @@ 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_info *info,
const struct pipe_draw_indirect_info *indirect)
{
struct u_vbuf *vbuf = cso->vbuf_current;
/* We can't have both indirect drawing and SO-vertex-count drawing */
assert(!info->indirect ||
info->indirect->buffer == NULL ||
info->indirect->count_from_stream_output == NULL);
assert(!indirect ||
indirect->buffer == NULL ||
indirect->count_from_stream_output == NULL);
/* We can't have SO-vertex-count drawing with an index buffer */
assert(info->index_size == 0 ||
!info->indirect ||
info->indirect->count_from_stream_output == NULL);
!indirect ||
indirect->count_from_stream_output == NULL);
if (vbuf) {
u_vbuf_draw_vbo(vbuf, info);
u_vbuf_draw_vbo(vbuf, info, indirect);
} else {
struct pipe_context *pipe = cso->pipe;
pipe->draw_vbo(pipe, info);
pipe->draw_vbo(pipe, info, indirect);
}
}
......@@ -1757,7 +1758,7 @@ cso_draw_arrays(struct cso_context *cso, uint mode, uint start, uint count)
info.min_index = start;
info.max_index = start + count - 1;
cso_draw_vbo(cso, &info);
cso_draw_vbo(cso, &info, NULL);
}
void
......@@ -1777,5 +1778,5 @@ cso_draw_arrays_instanced(struct cso_context *cso, uint mode,
info.start_instance = start_instance;
info.instance_count = instance_count;
cso_draw_vbo(cso, &info);
cso_draw_vbo(cso, &info, NULL);
}
......@@ -217,7 +217,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_info *info,
const struct pipe_draw_indirect_info *indirect);
void
cso_draw_arrays_instanced(struct cso_context *cso, uint mode,
......
......@@ -323,7 +323,8 @@ 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_info *info,
const struct pipe_draw_indirect_info *indirect);
/*******************************************************************************
......
......@@ -440,14 +440,15 @@ 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,
struct pipe_draw_info *info,
struct pipe_vertex_buffer *vertex_buffer)
{
memcpy(info, raw_info, sizeof(struct pipe_draw_info));
if (raw_info->indirect && raw_info->indirect->count_from_stream_output) {
if (indirect && indirect->count_from_stream_output) {
struct draw_so_target *target =
(struct draw_so_target *)info->indirect->count_from_stream_output;
(struct draw_so_target *)indirect->count_from_stream_output;
assert(vertex_buffer != NULL);
info->count = vertex_buffer->stride == 0 ? 0 :
target->internal_offset / vertex_buffer->stride;
......@@ -455,7 +456,6 @@ resolve_draw_info(const struct pipe_draw_info *raw_info,
/* Stream output draw can not be indexed */
debug_assert(!info->index_size);
info->max_index = info->count - 1;
info->indirect = NULL;
}
}
......@@ -467,7 +467,8 @@ 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_info *info,
const struct pipe_draw_indirect_info *indirect)
{
unsigned instance;
unsigned index_limit;
......@@ -483,7 +484,7 @@ draw_vbo(struct draw_context *draw,
*/
util_fpstate_set_denorms_to_zero(fpstate);
resolve_draw_info(info, &resolved_info, &(draw->pt.vertex_buffer[0]));
resolve_draw_info(info, indirect, &resolved_info, &(draw->pt.vertex_buffer[0]));
info = &resolved_info;
if (info->index_size)
......
......@@ -351,19 +351,19 @@ 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, FILE *f)
dd_dump_draw_vbo(struct dd_draw_state *dstate, struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect, FILE *f)
{
int sh, i;
DUMP(draw_info, info);
if (info->indirect) {
if (info->indirect->buffer)
DUMP_M(resource, info, indirect->buffer);
if (info->indirect->indirect_draw_count)
DUMP_M(resource, info, indirect->indirect_draw_count);
if (info->indirect->count_from_stream_output)
DUMP_M(stream_output_target, info,
indirect->count_from_stream_output);
if (indirect) {
if (indirect->buffer)
DUMP_M(resource, indirect, buffer);
if (indirect->indirect_draw_count)
DUMP_M(resource, indirect, indirect_draw_count);
if (indirect->count_from_stream_output)
DUMP_M(stream_output_target, indirect, count_from_stream_output);
}
fprintf(f, "\n");
......@@ -633,7 +633,8 @@ 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, f);
dd_dump_draw_vbo(state, &call->info.draw_vbo.draw,
&call->info.draw_vbo.indirect, f);
break;
case CALL_LAUNCH_GRID:
dd_dump_launch_grid(state, &call->info.launch_grid, f);
......@@ -1298,7 +1299,8 @@ 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_info *info,
const struct pipe_draw_indirect_info *indirect)
{
struct dd_context *dctx = dd_context(_pipe);
struct pipe_context *pipe = dctx->pipe;
......@@ -1312,25 +1314,23 @@ dd_context_draw_vbo(struct pipe_context *_pipe,
info->index.resource);
}
if (info->indirect) {
record->call.info.draw_vbo.indirect = *info->indirect;
record->call.info.draw_vbo.draw.indirect = &record->call.info.draw_vbo.indirect;
if (indirect) {
record->call.info.draw_vbo.indirect = *indirect;
record->call.info.draw_vbo.indirect.buffer = NULL;
pipe_resource_reference(&record->call.info.draw_vbo.indirect.buffer,
info->indirect->buffer);
indirect->buffer);
record->call.info.draw_vbo.indirect.indirect_draw_count = NULL;
pipe_resource_reference(&record->call.info.draw_vbo.indirect.indirect_draw_count,
info->indirect->indirect_draw_count);
indirect->indirect_draw_count);
record->call.info.draw_vbo.indirect.count_from_stream_output = NULL;
pipe_so_target_reference(&record->call.info.draw_vbo.indirect.count_from_stream_output,
info->indirect->count_from_stream_output);
indirect->count_from_stream_output);
} else {
memset(&record->call.info.draw_vbo.indirect, 0, sizeof(*info->indirect));
memset(&record->call.info.draw_vbo.indirect, 0, sizeof(*indirect));
}
dd_before_draw(dctx, record);
pipe->draw_vbo(pipe, info);
pipe->draw_vbo(pipe, info, indirect);
dd_after_draw(dctx, record);
}
......
......@@ -30,7 +30,8 @@
#include "util/u_inlines.h"
#include "util/u_transfer.h"
static void noop_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
static void noop_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect)
{
}
......
......@@ -114,7 +114,8 @@ 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)
rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *_info,
const struct pipe_draw_indirect_info *_indirect)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
struct pipe_context *pipe = rb_pipe->pipe;
......@@ -132,7 +133,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);
pipe->draw_vbo(pipe, &info, _indirect);
mtx_unlock(&rb_pipe->call_mutex);
rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
......
......@@ -89,7 +89,8 @@ 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_info *info,
const struct pipe_draw_indirect_info *indirect)
{
struct trace_context *tr_ctx = trace_context(_pipe);
struct pipe_context *pipe = tr_ctx->pipe;
......@@ -98,10 +99,11 @@ 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_trace_flush();
pipe->draw_vbo(pipe, info);
pipe->draw_vbo(pipe, info, indirect);
trace_dump_call_end();
}
......
......@@ -793,19 +793,27 @@ void trace_dump_draw_info(const struct pipe_draw_info *state)
trace_dump_member(uint, state, restart_index);
trace_dump_member(ptr, state, index.resource);
trace_dump_struct_end();
}
if (!state->indirect) {
trace_dump_member(ptr, state, indirect);
} else {
trace_dump_member(uint, state, indirect->offset);
trace_dump_member(uint, state, indirect->stride);
trace_dump_member(uint, state, indirect->draw_count);
trace_dump_member(uint, state, indirect->indirect_draw_count_offset);
trace_dump_member(ptr, state, indirect->buffer);
trace_dump_member(ptr, state, indirect->indirect_draw_count);
trace_dump_member(ptr, state, indirect->count_from_stream_output);
void trace_dump_draw_indirect_info(const struct pipe_draw_indirect_info *state)
{
if (!trace_dumping_enabled_locked())
return;
if (!state) {
trace_dump_null();
return;
}
trace_dump_struct_begin("pipe_draw_indirect_info");
trace_dump_member(uint, state, offset);
trace_dump_member(uint, state, stride);
trace_dump_member(uint, state, draw_count);
trace_dump_member(uint, state, indirect_draw_count_offset);
trace_dump_member(ptr, state, buffer);
trace_dump_member(ptr, state, indirect_draw_count);
trace_dump_member(ptr, state, count_from_stream_output);
trace_dump_struct_end();
}
......
......@@ -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_indirect_info(const struct pipe_draw_indirect_info *state);
void trace_dump_blit_info(const struct pipe_blit_info *);
void trace_dump_query_result(unsigned query_type,
......
......@@ -172,7 +172,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);
pc->pipe->draw_vbo(pc->pipe, &new_info, NULL);
pipe_resource_reference(&new_info.index.resource, NULL);
}
......@@ -126,30 +126,31 @@ util_draw_max_index(
}
/* This extracts the draw arguments from the info_in->indirect resource,
/* This extracts the draw arguments from the indirect resource,
* puts them into a new instance of pipe_draw_info, and calls draw_vbo on it.
*/
void
util_draw_indirect(struct pipe_context *pipe,
const struct pipe_draw_info *info_in)
const struct pipe_draw_info *info_in,
const struct pipe_draw_indirect_info *indirect)
{
struct pipe_draw_info info;
struct pipe_transfer *transfer;
uint32_t *params;
unsigned num_params = info_in->index_size ? 5 : 4;
assert(info_in->indirect);
assert(!info_in->indirect->count_from_stream_output);
assert(indirect);
assert(!indirect->count_from_stream_output);
memcpy(&info, info_in, sizeof(info));
uint32_t draw_count = info_in->indirect->draw_count;
uint32_t draw_count = indirect->draw_count;
if (info_in->indirect->indirect_draw_count) {
if (indirect->indirect_draw_count) {
struct pipe_transfer *dc_transfer;
uint32_t *dc_param = pipe_buffer_map_range(pipe,
info_in->indirect->indirect_draw_count,
info_in->indirect->indirect_draw_count_offset,
indirect->indirect_draw_count,
indirect->indirect_draw_count_offset,
4, PIPE_MAP_READ, &dc_transfer);
if (!dc_transfer) {
debug_printf("%s: failed to map indirect draw count buffer\n", __FUNCTION__);
......@@ -160,13 +161,13 @@ util_draw_indirect(struct pipe_context *pipe,
pipe_buffer_unmap(pipe, dc_transfer);
}
if (info_in->indirect->stride)
num_params = MIN2(info_in->indirect->stride / 4, num_params);
if (indirect->stride)
num_params = MIN2(indirect->stride / 4, num_params);
params = (uint32_t *)
pipe_buffer_map_range(pipe,
info_in->indirect->buffer,
info_in->indirect->offset,
(num_params * info_in->indirect->draw_count) * sizeof(uint32_t),
indirect->buffer,
indirect->offset,
(num_params * indirect->draw_count) * sizeof(uint32_t),
PIPE_MAP_READ,
&transfer);
if (!transfer) {
......@@ -181,11 +182,10 @@ util_draw_indirect(struct pipe_context *pipe,
info.index_bias = info_in->index_size ? params[3] : 0;
info.start_instance = info_in->index_size ? params[4] : params[3];
info.drawid = i;
info.indirect = NULL;
pipe->draw_vbo(pipe, &info);
pipe->draw_vbo(pipe, &info, NULL);
params += info_in->indirect->stride / 4;
params += indirect->stride / 4;
}
pipe_buffer_unmap(pipe, transfer);
}
......@@ -63,7 +63,7 @@ util_draw_arrays(struct pipe_context *pipe,
info.min_index = start;
info.max_index = start + count - 1;
pipe->draw_vbo(pipe, &info);
pipe->draw_vbo(pipe, &info, NULL);
}
static inline void
......@@ -85,7 +85,7 @@ util_draw_elements(struct pipe_context *pipe,
info.count = count;
info.index_bias = index_bias;
pipe->draw_vbo(pipe, &info);
pipe->draw_vbo(pipe, &info, NULL);
}
static inline void
......@@ -107,7 +107,7 @@ util_draw_arrays_instanced(struct pipe_context *pipe,
info.min_index = start;
info.max_index = start + count - 1;
pipe->draw_vbo(pipe, &info);
pipe->draw_vbo(pipe, &info, NULL);
}
static inline void
......@@ -134,7 +134,7 @@ util_draw_elements_instanced(struct pipe_context *pipe,
info.start_instance = start_instance;
info.instance_count = instance_count;
pipe->draw_vbo(pipe, &info);
pipe->draw_vbo(pipe, &info, NULL);
}
......@@ -143,7 +143,8 @@ util_draw_elements_instanced(struct pipe_context *pipe,
*/
void
util_draw_indirect(struct pipe_context *pipe,
const struct pipe_draw_info *info);
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect);
unsigned
......
......@@ -200,6 +200,10 @@ util_dump_stream_output_target(FILE *stream,
void
util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state);
void
util_dump_draw_indirect_info(FILE *stream,
const struct pipe_draw_indirect_info *indirect);
void
util_dump_grid_info(FILE *stream, const struct pipe_grid_info *state);
......
......@@ -941,19 +941,26 @@ util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state)
else
util_dump_member(stream, ptr, state, index.resource);
}
util_dump_struct_end(stream);
}
if (!state->indirect) {
util_dump_member(stream, ptr, state, indirect);
} else {
util_dump_member(stream, uint, state, indirect->offset);
util_dump_member(stream, uint, state, indirect->stride);
util_dump_member(stream, uint, state, indirect->draw_count);
util_dump_member(stream, uint, state, indirect->indirect_draw_count_offset);
util_dump_member(stream, ptr, state, indirect->buffer);
util_dump_member(stream, ptr, state, indirect->indirect_draw_count);
util_dump_member(stream, ptr, state, indirect->count_from_stream_output);
void
util_dump_draw_indirect_info(FILE *stream,
const struct pipe_draw_indirect_info *state)
{
if (!state) {
util_dump_null(stream);
return;
}
util_dump_struct_begin(stream, "pipe_draw_indirect_info");
util_dump_member(stream, uint, state, offset);
util_dump_member(stream, uint, state, stride);
util_dump_member(stream, uint, state, draw_count);
util_dump_member(stream, uint, state, indirect_draw_count_offset);
util_dump_member(stream, ptr, state, buffer);
util_dump_member(stream, ptr, state, indirect_draw_count);
util_dump_member(stream, ptr, state, count_from_stream_output);
util_dump_struct_end(stream);
}
......
......@@ -38,7 +38,7 @@ typedef struct {
} DrawElementsIndirectCommand;
static DrawElementsIndirectCommand
read_indirect_elements(struct pipe_context *context, struct pipe_draw_indirect_info *indirect)
read_indirect_elements(struct pipe_context *context, const struct pipe_draw_indirect_info *indirect)
{
DrawElementsIndirectCommand ret;
struct pipe_transfer *transfer = NULL;
......@@ -99,6 +99,7 @@ util_translate_prim_restart_data(unsigned index_size,
enum pipe_error
util_translate_prim_restart_ib(struct pipe_context *context,
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect_info,
struct pipe_resource **dst_buffer)
{
struct pipe_screen *screen = context->screen;
......@@ -114,8 +115,8 @@ util_translate_prim_restart_ib(struct pipe_context *context,
dst_index_size = MAX2(2, info->index_size);
assert(dst_index_size == 2 || dst_index_size == 4);
if (info->indirect && info->indirect->buffer) {
indirect = read_indirect_elements(context, info->indirect);
if (indirect_info && indirect_info->buffer) {
indirect = read_indirect_elements(context, indirect_info);
count = indirect.count;
start = indirect.firstIndex;
}
......@@ -220,7 +221,8 @@ add_range(struct range_info *info, unsigned start, unsigned count)
*/
enum pipe_error
util_draw_vbo_without_prim_restart(struct pipe_context *context,
const struct pipe_draw_info *info)
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect_info)
{
const void *src_map;
struct range_info ranges = {0};
......@@ -235,8 +237,8 @@ util_draw_vbo_without_prim_restart(struct pipe_context *context,
assert(info->index_size);
assert(info->primitive_restart);
if (info->indirect && info->indirect->buffer) {
indirect = read_indirect_elements(context, info->indirect);
if (indirect_info && indirect_info->buffer) {
indirect = read_indirect_elements(context, indirect_info);
info_count = indirect.count;
info_start = indirect.firstIndex;
info_instance_count = indirect.primCount;
......@@ -307,13 +309,12 @@ util_draw_vbo_without_prim_restart(struct pipe_context *context,
/* draw ranges between the restart indexes */
new_info = *info;
/* we've effectively remapped this to a direct draw */
new_info.indirect = NULL;
new_info.instance_count = info_instance_count;
new_info.primitive_restart = FALSE;
for (i = 0; i < ranges.count; i++) {
new_info.start = ranges.ranges[i].start;
new_info.count = ranges.ranges[i].count;
context->draw_vbo(context, &new_info);
context->draw_vbo(context, &new_info, NULL);
}
FREE(ranges.ranges);
......
......@@ -49,11 +49,13 @@ util_translate_prim_restart_data(unsigned index_size,
enum pipe_error
util_translate_prim_restart_ib(struct pipe_context *context,
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect,
struct pipe_resource **dst_buffer);
enum pipe_error
util_draw_vbo_without_prim_restart(struct pipe_context *context,
const struct pipe_draw_info *info);
const struct pipe_draw_info *info,
const struct pipe_draw_indirect_info *indirect);
static inline unsigned
util_prim_restart_index_from_size(unsigned index_size)
......
......@@ -125,7 +125,6 @@ tc_batch_execute(void *job, UNUSED int thread_index)
/* If at least 2 consecutive draw calls can be merged... */
if (next != last && next->call_id == TC_CALL_draw_vbo &&
first_info->draw.drawid == 0 &&
!first_info->draw.indirect &&
is_next_call_a_mergeable_draw(first_info, next, &next_info)) {
/* Merge up to 256 draw calls. */
struct pipe_draw_start_count multi[256];
......@@ -151,7 +150,7 @@ tc_batch_execute(void *job, UNUSED int thread_index)
pipe_resource_reference(&next_info->draw.index.resource, NULL);
}
pipe->multi_draw(pipe, &first_info->draw, multi, num_draws);
pipe->multi_draw(pipe, &first_info->draw, NULL, multi, num_draws);
if (first_info->draw.index_size)
pipe_resource_reference(&first_info->draw.index.resource, NULL);
iter = next;
......@@ -2197,40 +2196,69 @@ tc_call_draw_vbo(struct pipe_context *pipe, union tc_payload *payload)
{
struct tc_full_draw_info *info = (struct tc_full_draw_info*)payload;
pipe->draw_vbo(pipe, &info->draw);
pipe->draw_vbo(pipe, &info->draw, NULL);
if (info->draw.index_size)
pipe_resource_reference(&info->draw.index.resource, NULL);
if (info->draw.indirect) {
pipe_resource_reference(&info->indirect.buffer, NULL);
pipe_resource_reference(&info->indirect.indirect_draw_count, NULL);
pipe_so_target_reference(&info->indirect.count_from_stream_output, NULL);