1 /*
2 * Copyright 2010 Marek Olšák <[email protected]>
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "r300_context.h"
7 #include "util/u_index_modify.h"
8 #include "util/u_upload_mgr.h"
9
10
r300_translate_index_buffer(struct r300_context * r300,const struct pipe_draw_info * info,struct pipe_resource ** out_buffer,unsigned * index_size,unsigned index_offset,unsigned * start,unsigned count,const uint8_t ** export_ptr)11 void r300_translate_index_buffer(struct r300_context *r300,
12 const struct pipe_draw_info *info,
13 struct pipe_resource **out_buffer,
14 unsigned *index_size, unsigned index_offset,
15 unsigned *start, unsigned count,
16 const uint8_t **export_ptr)
17 {
18 unsigned out_offset;
19 void **ptr = (void **)export_ptr;
20
21 switch (*index_size) {
22 case 1:
23 *out_buffer = NULL;
24 u_upload_alloc(r300->uploader, 0, count * 2, 4,
25 &out_offset, out_buffer, ptr);
26
27 util_shorten_ubyte_elts_to_userptr(
28 &r300->context, info, PIPE_MAP_UNSYNCHRONIZED, index_offset,
29 *start, count, *ptr);
30
31 *index_size = 2;
32 *start = out_offset / 2;
33 break;
34
35 case 2:
36 if (index_offset) {
37 *out_buffer = NULL;
38 u_upload_alloc(r300->uploader, 0, count * 2, 4,
39 &out_offset, out_buffer, ptr);
40
41 util_rebuild_ushort_elts_to_userptr(&r300->context, info,
42 PIPE_MAP_UNSYNCHRONIZED,
43 index_offset, *start,
44 count, *ptr);
45
46 *start = out_offset / 2;
47 }
48 break;
49
50 case 4:
51 if (index_offset) {
52 *out_buffer = NULL;
53 u_upload_alloc(r300->uploader, 0, count * 4, 4,
54 &out_offset, out_buffer, ptr);
55
56 util_rebuild_uint_elts_to_userptr(&r300->context, info,
57 PIPE_MAP_UNSYNCHRONIZED,
58 index_offset, *start,
59 count, *ptr);
60
61 *start = out_offset / 4;
62 }
63 break;
64 }
65 }
66