Path: blob/21.2-virgl/src/gallium/drivers/r300/r300_render_translate.c
4570 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 "r300_context.h"23#include "util/u_index_modify.h"24#include "util/u_upload_mgr.h"252627void r300_translate_index_buffer(struct r300_context *r300,28const struct pipe_draw_info *info,29struct pipe_resource **out_buffer,30unsigned *index_size, unsigned index_offset,31unsigned *start, unsigned count)32{33unsigned out_offset;34void *ptr;3536switch (*index_size) {37case 1:38*out_buffer = NULL;39u_upload_alloc(r300->uploader, 0, count * 2, 4,40&out_offset, out_buffer, &ptr);4142util_shorten_ubyte_elts_to_userptr(43&r300->context, info, PIPE_MAP_UNSYNCHRONIZED, index_offset,44*start, count, ptr);4546*index_size = 2;47*start = out_offset / 2;48break;4950case 2:51if (index_offset) {52*out_buffer = NULL;53u_upload_alloc(r300->uploader, 0, count * 2, 4,54&out_offset, out_buffer, &ptr);5556util_rebuild_ushort_elts_to_userptr(&r300->context, info,57PIPE_MAP_UNSYNCHRONIZED,58index_offset, *start,59count, ptr);6061*start = out_offset / 2;62}63break;6465case 4:66if (index_offset) {67*out_buffer = NULL;68u_upload_alloc(r300->uploader, 0, count * 4, 4,69&out_offset, out_buffer, &ptr);7071util_rebuild_uint_elts_to_userptr(&r300->context, info,72PIPE_MAP_UNSYNCHRONIZED,73index_offset, *start,74count, ptr);7576*start = out_offset / 4;77}78break;79}80}818283