blob: 7b072b29a0faba202623316636312069b608b9ad [file] [log] [blame]
Dave Airlie91b70d82010-08-12 20:20:23 +10001/*
2 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23#include "pipe/p_context.h"
24#include "util/u_index_modify.h"
25#include "util/u_inlines.h"
26
Marek Olšák76db3302010-12-29 04:52:55 +010027/* Ubyte indices. */
28
29void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context,
Marek Olšákbf469f42012-04-24 21:14:44 +020030 struct pipe_index_buffer *ib,
Marek Olšákbc8d0472017-02-17 12:55:24 +010031 unsigned add_transfer_flags,
Marek Olšák76db3302010-12-29 04:52:55 +010032 int index_bias,
33 unsigned start,
34 unsigned count,
35 void *out)
Dave Airlie91b70d82010-08-12 20:20:23 +100036{
Marek Olšákbf469f42012-04-24 21:14:44 +020037 struct pipe_transfer *src_transfer = NULL;
38 const unsigned char *in_map;
Marek Olšák76db3302010-12-29 04:52:55 +010039 unsigned short *out_map = out;
Dave Airlie91b70d82010-08-12 20:20:23 +100040 unsigned i;
41
Marek Olšákbf469f42012-04-24 21:14:44 +020042 if (ib->user_buffer) {
43 in_map = ib->user_buffer;
44 } else {
45 in_map = pipe_buffer_map(context, ib->buffer,
46 PIPE_TRANSFER_READ |
Marek Olšákbc8d0472017-02-17 12:55:24 +010047 add_transfer_flags,
Marek Olšákbf469f42012-04-24 21:14:44 +020048 &src_transfer);
49 }
Dave Airlie91b70d82010-08-12 20:20:23 +100050 in_map += start;
51
52 for (i = 0; i < count; i++) {
53 *out_map = (unsigned short)(*in_map + index_bias);
54 in_map++;
55 out_map++;
56 }
57
Marek Olšákbf469f42012-04-24 21:14:44 +020058 if (src_transfer)
59 pipe_buffer_unmap(context, src_transfer);
Dave Airlie91b70d82010-08-12 20:20:23 +100060}
61
Marek Olšák76db3302010-12-29 04:52:55 +010062/* Ushort indices. */
63
64void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context,
Marek Olšákbf469f42012-04-24 21:14:44 +020065 struct pipe_index_buffer *ib,
Marek Olšákbc8d0472017-02-17 12:55:24 +010066 unsigned add_transfer_flags,
Marek Olšák76db3302010-12-29 04:52:55 +010067 int index_bias,
68 unsigned start, unsigned count,
69 void *out)
70{
71 struct pipe_transfer *in_transfer = NULL;
Marek Olšákbf469f42012-04-24 21:14:44 +020072 const unsigned short *in_map;
Marek Olšák76db3302010-12-29 04:52:55 +010073 unsigned short *out_map = out;
74 unsigned i;
75
Marek Olšákbf469f42012-04-24 21:14:44 +020076 if (ib->user_buffer) {
77 in_map = ib->user_buffer;
78 } else {
79 in_map = pipe_buffer_map(context, ib->buffer,
80 PIPE_TRANSFER_READ |
Marek Olšákbc8d0472017-02-17 12:55:24 +010081 add_transfer_flags,
Marek Olšákbf469f42012-04-24 21:14:44 +020082 &in_transfer);
83 }
Dave Airlie91b70d82010-08-12 20:20:23 +100084 in_map += start;
Marek Olšák76db3302010-12-29 04:52:55 +010085
Dave Airlie91b70d82010-08-12 20:20:23 +100086 for (i = 0; i < count; i++) {
87 *out_map = (unsigned short)(*in_map + index_bias);
88 in_map++;
89 out_map++;
90 }
91
Marek Olšákbf469f42012-04-24 21:14:44 +020092 if (in_transfer)
93 pipe_buffer_unmap(context, in_transfer);
Dave Airlie91b70d82010-08-12 20:20:23 +100094}
95
Marek Olšák76db3302010-12-29 04:52:55 +010096/* Uint indices. */
97
98void util_rebuild_uint_elts_to_userptr(struct pipe_context *context,
Marek Olšákbf469f42012-04-24 21:14:44 +020099 struct pipe_index_buffer *ib,
Marek Olšákbc8d0472017-02-17 12:55:24 +0100100 unsigned add_transfer_flags,
Marek Olšák76db3302010-12-29 04:52:55 +0100101 int index_bias,
102 unsigned start, unsigned count,
103 void *out)
104{
105 struct pipe_transfer *in_transfer = NULL;
Marek Olšákbf469f42012-04-24 21:14:44 +0200106 const unsigned int *in_map;
Marek Olšák76db3302010-12-29 04:52:55 +0100107 unsigned int *out_map = out;
108 unsigned i;
109
Marek Olšákbf469f42012-04-24 21:14:44 +0200110 if (ib->user_buffer) {
111 in_map = ib->user_buffer;
112 } else {
113 in_map = pipe_buffer_map(context, ib->buffer,
114 PIPE_TRANSFER_READ |
Marek Olšákbc8d0472017-02-17 12:55:24 +0100115 add_transfer_flags,
Marek Olšákbf469f42012-04-24 21:14:44 +0200116 &in_transfer);
117 }
Dave Airlie91b70d82010-08-12 20:20:23 +1000118 in_map += start;
Marek Olšák76db3302010-12-29 04:52:55 +0100119
Dave Airlie91b70d82010-08-12 20:20:23 +1000120 for (i = 0; i < count; i++) {
121 *out_map = (unsigned int)(*in_map + index_bias);
122 in_map++;
123 out_map++;
124 }
125
Marek Olšákbf469f42012-04-24 21:14:44 +0200126 if (in_transfer)
127 pipe_buffer_unmap(context, in_transfer);
Marek Olšák76db3302010-12-29 04:52:55 +0100128}