From: Erik Faye-Lund Date: Wed, 17 Jun 2020 13:52:05 +0000 (+0200) Subject: gallium/util: factor out primitive-restart rewriting logic X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0c85d6c523f137571768ab3bb190a201ae294421;p=mesa.git gallium/util: factor out primitive-restart rewriting logic Reviewed-by: Gert Wollny Part-of: --- diff --git a/src/gallium/auxiliary/util/u_prim_restart.c b/src/gallium/auxiliary/util/u_prim_restart.c index a6bfa16dc57..844c5228775 100644 --- a/src/gallium/auxiliary/util/u_prim_restart.c +++ b/src/gallium/auxiliary/util/u_prim_restart.c @@ -57,6 +57,38 @@ read_indirect_elements(struct pipe_context *context, struct pipe_draw_indirect_i return ret; } +void +util_translate_prim_restart_data(unsigned index_size, + void *src_map, void *dst_map, + unsigned count, unsigned restart_index) +{ + if (index_size == 1) { + uint8_t *src = (uint8_t *) src_map; + uint16_t *dst = (uint16_t *) dst_map; + unsigned i; + for (i = 0; i < count; i++) { + dst[i] = (src[i] == restart_index) ? 0xffff : src[i]; + } + } + else if (index_size == 2) { + uint16_t *src = (uint16_t *) src_map; + uint16_t *dst = (uint16_t *) dst_map; + unsigned i; + for (i = 0; i < count; i++) { + dst[i] = (src[i] == restart_index) ? 0xffff : src[i]; + } + } + else { + uint32_t *src = (uint32_t *) src_map; + uint32_t *dst = (uint32_t *) dst_map; + unsigned i; + assert(index_size == 4); + for (i = 0; i < count; i++) { + dst[i] = (src[i] == restart_index) ? 0xffffffff : src[i]; + } + } +} + /** * Translate an index buffer for primitive restart. * Create a new index buffer which is a copy of the original index buffer @@ -113,32 +145,8 @@ util_translate_prim_restart_ib(struct pipe_context *context, if (!src_map) goto error; - if (src_index_size == 1 && dst_index_size == 2) { - uint8_t *src = (uint8_t *) src_map; - uint16_t *dst = (uint16_t *) dst_map; - unsigned i; - for (i = 0; i < count; i++) { - dst[i] = (src[i] == info->restart_index) ? 0xffff : src[i]; - } - } - else if (src_index_size == 2 && dst_index_size == 2) { - uint16_t *src = (uint16_t *) src_map; - uint16_t *dst = (uint16_t *) dst_map; - unsigned i; - for (i = 0; i < count; i++) { - dst[i] = (src[i] == info->restart_index) ? 0xffff : src[i]; - } - } - else { - uint32_t *src = (uint32_t *) src_map; - uint32_t *dst = (uint32_t *) dst_map; - unsigned i; - assert(src_index_size == 4); - assert(dst_index_size == 4); - for (i = 0; i < count; i++) { - dst[i] = (src[i] == info->restart_index) ? 0xffffffff : src[i]; - } - } + util_translate_prim_restart_data(src_index_size, src_map, dst_map, + info->count, info->restart_index); if (src_transfer) pipe_buffer_unmap(context, src_transfer); diff --git a/src/gallium/auxiliary/util/u_prim_restart.h b/src/gallium/auxiliary/util/u_prim_restart.h index de4fcca497c..82f0409a835 100644 --- a/src/gallium/auxiliary/util/u_prim_restart.h +++ b/src/gallium/auxiliary/util/u_prim_restart.h @@ -41,6 +41,10 @@ struct pipe_draw_info; union pipe_index_binding; struct pipe_resource; +void +util_translate_prim_restart_data(unsigned index_size, + void *src_map, void *dst_map, + unsigned count, unsigned restart_index); enum pipe_error util_translate_prim_restart_ib(struct pipe_context *context,