Path: blob/21.2-virgl/src/gallium/auxiliary/util/u_index_modify.c
4561 views
/*1* Copyright 2010 Marek Olšák <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE. */2122#include "pipe/p_context.h"23#include "util/u_index_modify.h"24#include "util/u_inlines.h"2526/* Ubyte indices. */2728void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context,29const struct pipe_draw_info *info,30unsigned add_transfer_flags,31int index_bias,32unsigned start,33unsigned count,34void *out)35{36struct pipe_transfer *src_transfer = NULL;37const unsigned char *in_map;38unsigned short *out_map = out;39unsigned i;4041if (info->has_user_indices) {42in_map = info->index.user;43} else {44in_map = pipe_buffer_map(context, info->index.resource,45PIPE_MAP_READ |46add_transfer_flags,47&src_transfer);48}49in_map += start;5051for (i = 0; i < count; i++) {52*out_map = (unsigned short)(*in_map + index_bias);53in_map++;54out_map++;55}5657if (src_transfer)58pipe_buffer_unmap(context, src_transfer);59}6061/* Ushort indices. */6263void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context,64const struct pipe_draw_info *info,65unsigned add_transfer_flags,66int index_bias,67unsigned start, unsigned count,68void *out)69{70struct pipe_transfer *in_transfer = NULL;71const unsigned short *in_map;72unsigned short *out_map = out;73unsigned i;7475if (info->has_user_indices) {76in_map = info->index.user;77} else {78in_map = pipe_buffer_map(context, info->index.resource,79PIPE_MAP_READ |80add_transfer_flags,81&in_transfer);82}83in_map += start;8485for (i = 0; i < count; i++) {86*out_map = (unsigned short)(*in_map + index_bias);87in_map++;88out_map++;89}9091if (in_transfer)92pipe_buffer_unmap(context, in_transfer);93}9495/* Uint indices. */9697void util_rebuild_uint_elts_to_userptr(struct pipe_context *context,98const struct pipe_draw_info *info,99unsigned add_transfer_flags,100int index_bias,101unsigned start, unsigned count,102void *out)103{104struct pipe_transfer *in_transfer = NULL;105const unsigned int *in_map;106unsigned int *out_map = out;107unsigned i;108109if (info->has_user_indices) {110in_map = info->index.user;111} else {112in_map = pipe_buffer_map(context, info->index.resource,113PIPE_MAP_READ |114add_transfer_flags,115&in_transfer);116}117in_map += start;118119for (i = 0; i < count; i++) {120*out_map = (unsigned int)(*in_map + index_bias);121in_map++;122out_map++;123}124125if (in_transfer)126pipe_buffer_unmap(context, in_transfer);127}128129130