1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2010 Marek Olšák <maraeo@gmail.com> 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 22bf215546Sopenharmony_ci 23bf215546Sopenharmony_ci#include "pipe/p_context.h" 24bf215546Sopenharmony_ci#include "util/u_index_modify.h" 25bf215546Sopenharmony_ci#include "util/u_inlines.h" 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci/* Ubyte indices. */ 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_civoid util_shorten_ubyte_elts_to_userptr(struct pipe_context *context, 30bf215546Sopenharmony_ci const struct pipe_draw_info *info, 31bf215546Sopenharmony_ci unsigned add_transfer_flags, 32bf215546Sopenharmony_ci int index_bias, 33bf215546Sopenharmony_ci unsigned start, 34bf215546Sopenharmony_ci unsigned count, 35bf215546Sopenharmony_ci void *out) 36bf215546Sopenharmony_ci{ 37bf215546Sopenharmony_ci struct pipe_transfer *src_transfer = NULL; 38bf215546Sopenharmony_ci const unsigned char *in_map; 39bf215546Sopenharmony_ci unsigned short *out_map = out; 40bf215546Sopenharmony_ci unsigned i; 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci if (info->has_user_indices) { 43bf215546Sopenharmony_ci in_map = info->index.user; 44bf215546Sopenharmony_ci } else { 45bf215546Sopenharmony_ci in_map = pipe_buffer_map(context, info->index.resource, 46bf215546Sopenharmony_ci PIPE_MAP_READ | 47bf215546Sopenharmony_ci add_transfer_flags, 48bf215546Sopenharmony_ci &src_transfer); 49bf215546Sopenharmony_ci } 50bf215546Sopenharmony_ci in_map += start; 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci for (i = 0; i < count; i++) { 53bf215546Sopenharmony_ci *out_map = (unsigned short)(*in_map + index_bias); 54bf215546Sopenharmony_ci in_map++; 55bf215546Sopenharmony_ci out_map++; 56bf215546Sopenharmony_ci } 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci if (src_transfer) 59bf215546Sopenharmony_ci pipe_buffer_unmap(context, src_transfer); 60bf215546Sopenharmony_ci} 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci/* Ushort indices. */ 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_civoid util_rebuild_ushort_elts_to_userptr(struct pipe_context *context, 65bf215546Sopenharmony_ci const struct pipe_draw_info *info, 66bf215546Sopenharmony_ci unsigned add_transfer_flags, 67bf215546Sopenharmony_ci int index_bias, 68bf215546Sopenharmony_ci unsigned start, unsigned count, 69bf215546Sopenharmony_ci void *out) 70bf215546Sopenharmony_ci{ 71bf215546Sopenharmony_ci struct pipe_transfer *in_transfer = NULL; 72bf215546Sopenharmony_ci const unsigned short *in_map; 73bf215546Sopenharmony_ci unsigned short *out_map = out; 74bf215546Sopenharmony_ci unsigned i; 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci if (info->has_user_indices) { 77bf215546Sopenharmony_ci in_map = info->index.user; 78bf215546Sopenharmony_ci } else { 79bf215546Sopenharmony_ci in_map = pipe_buffer_map(context, info->index.resource, 80bf215546Sopenharmony_ci PIPE_MAP_READ | 81bf215546Sopenharmony_ci add_transfer_flags, 82bf215546Sopenharmony_ci &in_transfer); 83bf215546Sopenharmony_ci } 84bf215546Sopenharmony_ci in_map += start; 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_ci for (i = 0; i < count; i++) { 87bf215546Sopenharmony_ci *out_map = (unsigned short)(*in_map + index_bias); 88bf215546Sopenharmony_ci in_map++; 89bf215546Sopenharmony_ci out_map++; 90bf215546Sopenharmony_ci } 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci if (in_transfer) 93bf215546Sopenharmony_ci pipe_buffer_unmap(context, in_transfer); 94bf215546Sopenharmony_ci} 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci/* Uint indices. */ 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_civoid util_rebuild_uint_elts_to_userptr(struct pipe_context *context, 99bf215546Sopenharmony_ci const struct pipe_draw_info *info, 100bf215546Sopenharmony_ci unsigned add_transfer_flags, 101bf215546Sopenharmony_ci int index_bias, 102bf215546Sopenharmony_ci unsigned start, unsigned count, 103bf215546Sopenharmony_ci void *out) 104bf215546Sopenharmony_ci{ 105bf215546Sopenharmony_ci struct pipe_transfer *in_transfer = NULL; 106bf215546Sopenharmony_ci const unsigned int *in_map; 107bf215546Sopenharmony_ci unsigned int *out_map = out; 108bf215546Sopenharmony_ci unsigned i; 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci if (info->has_user_indices) { 111bf215546Sopenharmony_ci in_map = info->index.user; 112bf215546Sopenharmony_ci } else { 113bf215546Sopenharmony_ci in_map = pipe_buffer_map(context, info->index.resource, 114bf215546Sopenharmony_ci PIPE_MAP_READ | 115bf215546Sopenharmony_ci add_transfer_flags, 116bf215546Sopenharmony_ci &in_transfer); 117bf215546Sopenharmony_ci } 118bf215546Sopenharmony_ci in_map += start; 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_ci for (i = 0; i < count; i++) { 121bf215546Sopenharmony_ci *out_map = (unsigned int)(*in_map + index_bias); 122bf215546Sopenharmony_ci in_map++; 123bf215546Sopenharmony_ci out_map++; 124bf215546Sopenharmony_ci } 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci if (in_transfer) 127bf215546Sopenharmony_ci pipe_buffer_unmap(context, in_transfer); 128bf215546Sopenharmony_ci} 129