diff options
author | Christoph Bumiller <[email protected]> | 2013-04-05 14:29:36 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2014-07-02 00:47:09 +0200 |
commit | bc198f8e63f8fa297a458892c1c51ba8808c73a5 (patch) | |
tree | 5f842e6f56746e9d49eaffe3e727cc2b6b8c8268 /src/gallium/auxiliary/util | |
parent | a27b3582a60ac2be2b1d6594b042d2bb6438d81a (diff) |
gallium: add facilities for indirect drawing
v2:
Added comments to util_draw_indirect, clarified and fixed map size.
Removed unlikely().
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_draw.c | 43 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_draw.h | 8 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_dump_state.c | 3 |
3 files changed, 54 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_draw.c b/src/gallium/auxiliary/util/u_draw.c index 83d9284b895..b9f8fcd3c2a 100644 --- a/src/gallium/auxiliary/util/u_draw.c +++ b/src/gallium/auxiliary/util/u_draw.c @@ -27,6 +27,7 @@ #include "util/u_debug.h" +#include "util/u_inlines.h" #include "util/u_math.h" #include "util/u_format.h" #include "util/u_draw.h" @@ -123,3 +124,45 @@ util_draw_max_index( return max_index + 1; } + + +/* This extracts the draw arguments from the info_in->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) +{ + struct pipe_draw_info info; + struct pipe_transfer *transfer; + uint32_t *params; + const unsigned num_params = info_in->indexed ? 5 : 4; + + assert(info_in->indirect); + assert(!info_in->count_from_stream_output); + + memcpy(&info, info_in, sizeof(info)); + + params = (uint32_t *) + pipe_buffer_map_range(pipe, + info_in->indirect, + info_in->indirect_offset, + num_params * sizeof(uint32_t), + PIPE_TRANSFER_READ, + &transfer); + if (!transfer) { + debug_printf("%s: failed to map indirect buffer\n", __FUNCTION__); + return; + } + + info.count = params[0]; + info.instance_count = params[1]; + info.start = params[2]; + info.index_bias = info_in->indexed ? params[3] : 0; + info.start_instance = info_in->indexed ? params[4] : params[3]; + info.indirect = NULL; + + pipe_buffer_unmap(pipe, transfer); + + pipe->draw_vbo(pipe, &info); +} diff --git a/src/gallium/auxiliary/util/u_draw.h b/src/gallium/auxiliary/util/u_draw.h index 5a7ead27e31..9fc3e9924e1 100644 --- a/src/gallium/auxiliary/util/u_draw.h +++ b/src/gallium/auxiliary/util/u_draw.h @@ -142,6 +142,14 @@ util_draw_range_elements(struct pipe_context *pipe, } +/* This converts an indirect draw into a direct draw by mapping the indirect + * buffer, extracting its arguments, and calling pipe->draw_vbo. + */ +void +util_draw_indirect(struct pipe_context *pipe, + const struct pipe_draw_info *info); + + unsigned util_draw_max_index( const struct pipe_vertex_buffer *vertex_buffers, diff --git a/src/gallium/auxiliary/util/u_dump_state.c b/src/gallium/auxiliary/util/u_dump_state.c index 12f1d2d6e0c..e6614d5d22c 100644 --- a/src/gallium/auxiliary/util/u_dump_state.c +++ b/src/gallium/auxiliary/util/u_dump_state.c @@ -759,6 +759,9 @@ util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state) util_dump_member(stream, ptr, state, count_from_stream_output); + util_dump_member(stream, ptr, state, indirect); + util_dump_member(stream, uint, state, indirect_offset); + util_dump_struct_end(stream); } |