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/u_draw.c | |
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/u_draw.c')
-rw-r--r-- | src/gallium/auxiliary/util/u_draw.c | 43 |
1 files changed, 43 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); +} |