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) ...@@ -1722,25 +1722,26 @@ cso_restore_state(struct cso_context *cso)
void void
cso_draw_vbo(struct cso_context *cso, 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; struct u_vbuf *vbuf = cso->vbuf_current;
/* We can't have both indirect drawing and SO-vertex-count drawing */ /* We can't have both indirect drawing and SO-vertex-count drawing */
assert(!info->indirect || assert(!indirect ||
info->indirect->buffer == NULL || indirect->buffer == NULL ||
info->indirect->count_from_stream_output == NULL); indirect->count_from_stream_output == NULL);
/* We can't have SO-vertex-count drawing with an index buffer */ /* We can't have SO-vertex-count drawing with an index buffer */
assert(info->index_size == 0 || assert(info->index_size == 0 ||
!info->indirect || !indirect ||
info->indirect->count_from_stream_output == NULL); indirect->count_from_stream_output == NULL);
if (vbuf) { if (vbuf) {
u_vbuf_draw_vbo(vbuf, info); u_vbuf_draw_vbo(vbuf, info, indirect);
} else { } else {
struct pipe_context *pipe = cso->pipe; 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) ...@@ -1757,7 +1758,7 @@ cso_draw_arrays(struct cso_context *cso, uint mode, uint start, uint count)
info.min_index = start; info.min_index = start;
info.max_index = start + count - 1; info.max_index = start + count - 1;
cso_draw_vbo(cso, &info); cso_draw_vbo(cso, &info, NULL);
} }
void void
...@@ -1777,5 +1778,5 @@ cso_draw_arrays_instanced(struct cso_context *cso, uint mode, ...@@ -1777,5 +1778,5 @@ cso_draw_arrays_instanced(struct cso_context *cso, uint mode,
info.start_instance = start_instance; info.start_instance = start_instance;
info.instance_count = instance_count; 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, ...@@ -217,7 +217,8 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx,
void void
cso_draw_vbo(struct cso_context *cso, 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 void
cso_draw_arrays_instanced(struct cso_context *cso, uint mode, cso_draw_arrays_instanced(struct cso_context *cso, uint mode,
......
...@@ -323,7 +323,8 @@ draw_set_mapped_so_targets(struct draw_context *draw, ...@@ -323,7 +323,8 @@ draw_set_mapped_so_targets(struct draw_context *draw,
*/ */
void draw_vbo(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, ...@@ -440,14 +440,15 @@ draw_pt_arrays_restart(struct draw_context *draw,
*/ */
static void static void
resolve_draw_info(const struct pipe_draw_info *raw_info, resolve_draw_info(const struct pipe_draw_info *raw_info,
const struct pipe_draw_indirect_info *indirect,
struct pipe_draw_info *info, struct pipe_draw_info *info,
struct pipe_vertex_buffer *vertex_buffer) struct pipe_vertex_buffer *vertex_buffer)
{ {
memcpy(info, raw_info, sizeof(struct pipe_draw_info)); 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 *target =
(struct draw_so_target *)info->indirect->count_from_stream_output; (struct draw_so_target *)indirect->count_from_stream_output;
assert(vertex_buffer != NULL); assert(vertex_buffer != NULL);
info->count = vertex_buffer->stride == 0 ? 0 : info->count = vertex_buffer->stride == 0 ? 0 :
target->internal_offset / vertex_buffer->stride; target->internal_offset / vertex_buffer->stride;
...@@ -455,7 +456,6 @@ resolve_draw_info(const struct pipe_draw_info *raw_info, ...@@ -455,7 +456,6 @@ resolve_draw_info(const struct pipe_draw_info *raw_info,
/* Stream output draw can not be indexed */ /* Stream output draw can not be indexed */
debug_assert(!info->index_size); debug_assert(!info->index_size);
info->max_index = info->count - 1; info->max_index = info->count - 1;
info->indirect = NULL;
} }
} }
...@@ -467,7 +467,8 @@ resolve_draw_info(const struct pipe_draw_info *raw_info, ...@@ -467,7 +467,8 @@ resolve_draw_info(const struct pipe_draw_info *raw_info,
*/ */
void void
draw_vbo(struct draw_context *draw, 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 instance;
unsigned index_limit; unsigned index_limit;
...@@ -483,7 +484,7 @@ draw_vbo(struct draw_context *draw, ...@@ -483,7 +484,7 @@ draw_vbo(struct draw_context *draw,
*/ */
util_fpstate_set_denorms_to_zero(fpstate); 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; info = &resolved_info;
if (info->index_size) if (info->index_size)
......
...@@ -351,19 +351,19 @@ dd_dump_flush(struct dd_draw_state *dstate, struct call_flush *info, FILE *f) ...@@ -351,19 +351,19 @@ dd_dump_flush(struct dd_draw_state *dstate, struct call_flush *info, FILE *f)
} }
static void 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; int sh, i;
DUMP(draw_info, info); DUMP(draw_info, info);
if (info->indirect) { if (indirect) {
if (info->indirect->buffer) if (indirect->buffer)
DUMP_M(resource, info, indirect->buffer); DUMP_M(resource, indirect, buffer);
if (info->indirect->indirect_draw_count) if (indirect->indirect_draw_count)
DUMP_M(resource, info, indirect->indirect_draw_count); DUMP_M(resource, indirect, indirect_draw_count);
if (info->indirect->count_from_stream_output) if (indirect->count_from_stream_output)
DUMP_M(stream_output_target, info, DUMP_M(stream_output_target, indirect, count_from_stream_output);
indirect->count_from_stream_output);
} }
fprintf(f, "\n"); fprintf(f, "\n");
...@@ -633,7 +633,8 @@ dd_dump_call(FILE *f, struct dd_draw_state *state, struct dd_call *call) ...@@ -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); dd_dump_flush(state, &call->info.flush, f);
break; break;
case CALL_DRAW_VBO: 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; break;
case CALL_LAUNCH_GRID: case CALL_LAUNCH_GRID:
dd_dump_launch_grid(state, &call->info.launch_grid, f); dd_dump_launch_grid(state, &call->info.launch_grid, f);
...@@ -1298,7 +1299,8 @@ dd_context_flush(struct pipe_context *_pipe, ...@@ -1298,7 +1299,8 @@ dd_context_flush(struct pipe_context *_pipe,
static void static void
dd_context_draw_vbo(struct pipe_context *_pipe, 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 dd_context *dctx = dd_context(_pipe);
struct pipe_context *pipe = dctx->pipe; struct pipe_context *pipe = dctx->pipe;
...@@ -1312,25 +1314,23 @@ dd_context_draw_vbo(struct pipe_context *_pipe, ...@@ -1312,25 +1314,23 @@ dd_context_draw_vbo(struct pipe_context *_pipe,
info->index.resource); info->index.resource);
} }
if (info->indirect) { if (indirect) {
record->call.info.draw_vbo.indirect = *info->indirect; record->call.info.draw_vbo.indirect = *indirect;
record->call.info.draw_vbo.draw.indirect = &record->call.info.draw_vbo.indirect;
record->call.info.draw_vbo.indirect.buffer = NULL; record->call.info.draw_vbo.indirect.buffer = NULL;
pipe_resource_reference(&record->call.info.draw_vbo.indirect.buffer, 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; record->call.info.draw_vbo.indirect.indirect_draw_count = NULL;
pipe_resource_reference(&record->call.info.draw_vbo.indirect.indirect_draw_count, 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; 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, 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 { } 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); dd_before_draw(dctx, record);
pipe->draw_vbo(pipe, info); pipe->draw_vbo(pipe, info, indirect);
dd_after_draw(dctx, record); dd_after_draw(dctx, record);
} }
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
#include "util/u_inlines.h" #include "util/u_inlines.h"
#include "util/u_transfer.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) ...@@ -114,7 +114,8 @@ rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
} }
static void 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 rbug_context *rb_pipe = rbug_context(_pipe);
struct pipe_context *pipe = rb_pipe->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) ...@@ -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) && 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_GEOMETRY] && rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY]->disabled) &&
!(rb_pipe->curr.shader[PIPE_SHADER_VERTEX] && rb_pipe->curr.shader[PIPE_SHADER_VERTEX]->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); mtx_unlock(&rb_pipe->call_mutex);
rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER); rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
......
...@@ -89,7 +89,8 @@ trace_surface_unwrap(struct trace_context *tr_ctx, ...@@ -89,7 +89,8 @@ trace_surface_unwrap(struct trace_context *tr_ctx,
static void static void
trace_context_draw_vbo(struct pipe_context *_pipe, 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 trace_context *tr_ctx = trace_context(_pipe);
struct pipe_context *pipe = tr_ctx->pipe; struct pipe_context *pipe = tr_ctx->pipe;
...@@ -98,10 +99,11 @@ trace_context_draw_vbo(struct pipe_context *_pipe, ...@@ -98,10 +99,11 @@ trace_context_draw_vbo(struct pipe_context *_pipe,
trace_dump_arg(ptr, pipe); trace_dump_arg(ptr, pipe);
trace_dump_arg(draw_info, info); trace_dump_arg(draw_info, info);
trace_dump_arg(draw_indirect_info, indirect);
trace_dump_trace_flush(); trace_dump_trace_flush();
pipe->draw_vbo(pipe, info); pipe->draw_vbo(pipe, info, indirect);
trace_dump_call_end(); trace_dump_call_end();
} }
......
...@@ -793,19 +793,27 @@ void trace_dump_draw_info(const struct pipe_draw_info *state) ...@@ -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(uint, state, restart_index);
trace_dump_member(ptr, state, index.resource); trace_dump_member(ptr, state, index.resource);
trace_dump_struct_end();
}
if (!state->indirect) { void trace_dump_draw_indirect_info(const struct pipe_draw_indirect_info *state)
trace_dump_member(ptr, state, indirect); {
} else { if (!trace_dumping_enabled_locked())
trace_dump_member(uint, state, indirect->offset); return;
trace_dump_member(uint, state, indirect->stride);
trace_dump_member(uint, state, indirect->draw_count); if (!state) {
trace_dump_member(uint, state, indirect->indirect_draw_count_offset); trace_dump_null();
trace_dump_member(ptr, state, indirect->buffer); return;
trace_dump_member(ptr, state, indirect->indirect_draw_count);
trace_dump_member(ptr, state, indirect->count_from_stream_output);
} }
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(); trace_dump_struct_end();
} }
......
...@@ -82,6 +82,8 @@ void trace_dump_shader_buffer(const struct pipe_shader_buffer *buffer); ...@@ -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_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_blit_info(const struct pipe_blit_info *);
void trace_dump_query_result(unsigned query_type, void trace_dump_query_result(unsigned query_type,
......
...@@ -172,7 +172,7 @@ util_primconvert_draw_vbo(struct primconvert_context *pc, ...@@ -172,7 +172,7 @@ util_primconvert_draw_vbo(struct primconvert_context *pc,
u_upload_unmap(pc->pipe->stream_uploader); u_upload_unmap(pc->pipe->stream_uploader);
/* to the translated draw: */ /* 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); pipe_resource_reference(&new_info.index.resource, NULL);
} }
...@@ -126,30 +126,31 @@ util_draw_max_index( ...@@ -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. * puts them into a new instance of pipe_draw_info, and calls draw_vbo on it.
*/ */
void void
util_draw_indirect(struct pipe_context *pipe, 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_draw_info info;
struct pipe_transfer *transfer; struct pipe_transfer *transfer;
uint32_t *params; uint32_t *params;
unsigned num_params = info_in->index_size ? 5 : 4; unsigned num_params = info_in->index_size ? 5 : 4;
assert(info_in->indirect); assert(indirect);
assert(!info_in->indirect->count_from_stream_output); assert(!indirect->count_from_stream_output);
memcpy(&info, info_in, sizeof(info)); 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; struct pipe_transfer *dc_transfer;
uint32_t *dc_param = pipe_buffer_map_range(pipe, uint32_t *dc_param = pipe_buffer_map_range(pipe,
info_in->indirect->indirect_draw_count, indirect->indirect_draw_count,
info_in->indirect->indirect_draw_count_offset, indirect->indirect_draw_count_offset,
4, PIPE_MAP_READ, &dc_transfer); 4, PIPE_MAP_READ, &dc_transfer);
if (!dc_transfer) { if (!dc_transfer) {
debug_printf("%s: failed to map indirect draw count buffer\n", __FUNCTION__); debug_printf("%s: failed to map indirect draw count buffer\n", __FUNCTION__);
...@@ -160,13 +161,13 @@ util_draw_indirect(struct pipe_context *pipe, ...@@ -160,13 +161,13 @@ util_draw_indirect(struct pipe_context *pipe,
pipe_buffer_unmap(pipe, dc_transfer); pipe_buffer_unmap(pipe, dc_transfer);
} }
if (info_in->indirect->stride) if (indirect->stride)
num_params = MIN2(info_in->indirect->stride / 4, num_params); num_params = MIN2(indirect->stride / 4, num_params);
params = (uint32_t *) params = (uint32_t *)
pipe_buffer_map_range(pipe, pipe_buffer_map_range(pipe,
info_in->indirect->buffer, indirect->buffer,
info_in->indirect->offset, indirect->offset,
(num_params * info_in->indirect->draw_count) * sizeof(uint32_t), (num_params * indirect->draw_count) * sizeof(uint32_t),
PIPE_MAP_READ, PIPE_MAP_READ,
&transfer); &transfer);
if (!transfer) { if (!transfer) {
...@@ -181,11 +182,10 @@ util_draw_indirect(struct pipe_context *pipe, ...@@ -181,11 +182,10 @@ util_draw_indirect(struct pipe_context *pipe,
info.index_bias = info_in->index_size ? params[3] : 0; info.index_bias = info_in->index_size ? params[3] : 0;
info.start_instance = info_in->index_size ? params[4] : params[3]; info.start_instance = info_in->index_size ? params[4] : params[3];
info.drawid = i; 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); pipe_buffer_unmap(pipe, transfer);
} }
...@@ -63,7 +63,7 @@ util_draw_arrays(struct pipe_context *pipe, ...@@ -63,7 +63,7 @@ util_draw_arrays(struct pipe_context *pipe,
info.min_index = start; info.min_index = start;
info.max_index = start + count - 1; info.max_index = start + count - 1;
pipe->draw_vbo(pipe, &info); pipe->draw_vbo(pipe, &info, NULL);
} }
static inline void static inline void
...@@ -85,7 +85,7 @@ util_draw_elements(struct pipe_context *pipe, ...@@ -85,7 +85,7 @@ util_draw_elements(struct pipe_context *pipe,
info.count = count; info.count = count;
info.index_bias = index_bias; info.index_bias = index_bias;
pipe->draw_vbo(pipe, &info); pipe->draw_vbo(pipe, &info, NULL);
} }
static inline void