summaryrefslogtreecommitdiff
path: root/renderscript/include/rs_allocation.rsh
blob: 03bd1ca947efe4c531ddb5197452681b97bb7efb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/** @file rs_allocation.rsh
 *  \brief Allocation routines
 *
 *
 */

#ifndef __RS_ALLOCATION_RSH__
#define __RS_ALLOCATION_RSH__

/**
 * Returns the Allocation for a given pointer.  The pointer should point within
 * a valid allocation.  The results are undefined if the pointer is not from a
 * valid allocation.
 *
 * This function is deprecated and will be removed in the SDK from a future
 * release.
 */
extern rs_allocation __attribute__((overloadable))
    rsGetAllocation(const void *);

/**
 * Query the dimension of an allocation.
 *
 * @return uint32_t The X dimension of the allocation.
 */
extern uint32_t __attribute__((overloadable))
    rsAllocationGetDimX(rs_allocation);

/**
 * Query the dimension of an allocation.
 *
 * @return uint32_t The Y dimension of the allocation.
 */
extern uint32_t __attribute__((overloadable))
    rsAllocationGetDimY(rs_allocation);

/**
 * Query the dimension of an allocation.
 *
 * @return uint32_t The Z dimension of the allocation.
 */
extern uint32_t __attribute__((overloadable))
    rsAllocationGetDimZ(rs_allocation);

/**
 * Query an allocation for the presence of more than one LOD.
 *
 * @return uint32_t Returns 1 if more than one LOD is present, 0 otherwise.
 */
extern uint32_t __attribute__((overloadable))
    rsAllocationGetDimLOD(rs_allocation);

/**
 * Query an allocation for the presence of more than one face.
 *
 * @return uint32_t Returns 1 if more than one face is present, 0 otherwise.
 */
extern uint32_t __attribute__((overloadable))
    rsAllocationGetDimFaces(rs_allocation);

#if (defined(RS_VERSION) && (RS_VERSION >= 14))

/**
 * Copy part of an allocation from another allocation.
 *
 * @param dstAlloc Allocation to copy data into.
 * @param dstOff The offset of the first element to be copied in
 *               the destination allocation.
 * @param dstMip Mip level in the destination allocation.
 * @param count The number of elements to be copied.
 * @param srcAlloc The source data allocation.
 * @param srcOff The offset of the first element in data to be
 *               copied in the source allocation.
 * @param srcMip Mip level in the source allocation.
 */
extern void __attribute__((overloadable))
    rsAllocationCopy1DRange(rs_allocation dstAlloc,
                            uint32_t dstOff, uint32_t dstMip,
                            uint32_t count,
                            rs_allocation srcAlloc,
                            uint32_t srcOff, uint32_t srcMip);

/**
 * Copy a rectangular region into the allocation from another
 * allocation.
 *
 * @param dstAlloc allocation to copy data into.
 * @param dstXoff X offset of the region to update in the
 *                destination allocation.
 * @param dstYoff Y offset of the region to update in the
 *                destination allocation.
 * @param dstMip Mip level in the destination allocation.
 * @param dstFace Cubemap face of the destination allocation,
 *                ignored for allocations that aren't cubemaps.
 * @param width Width of the incoming region to update.
 * @param height Height of the incoming region to update.
 * @param srcAlloc The source data allocation.
 * @param srcXoff X offset in data of the source allocation.
 * @param srcYoff Y offset in data of the source allocation.
 * @param srcMip Mip level in the source allocation.
 * @param srcFace Cubemap face of the source allocation,
 *                ignored for allocations that aren't cubemaps.
 */
extern void __attribute__((overloadable))
    rsAllocationCopy2DRange(rs_allocation dstAlloc,
                            uint32_t dstXoff, uint32_t dstYoff,
                            uint32_t dstMip,
                            rs_allocation_cubemap_face dstFace,
                            uint32_t width, uint32_t height,
                            rs_allocation srcAlloc,
                            uint32_t srcXoff, uint32_t srcYoff,
                            uint32_t srcMip,
                            rs_allocation_cubemap_face srcFace);

#endif //defined(RS_VERSION) && (RS_VERSION >= 14)

/**
 * Extract a single element from an allocation.
 */
extern const void * __attribute__((overloadable))
    rsGetElementAt(rs_allocation a, uint32_t x);
/**
 * \overload
 */
extern const void * __attribute__((overloadable))
    rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y);
/**
 * \overload
 */
extern const void * __attribute__((overloadable))
    rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y, uint32_t z);


#if (defined(RS_VERSION) && (RS_VERSION >= 18))
    #define GET_ELEMENT_AT(T) \
    extern T __attribute__((overloadable)) \
            rsGetElementAt_##T(rs_allocation a, uint32_t x); \
    extern T __attribute__((overloadable)) \
            rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y);  \
    extern T __attribute__((overloadable)) \
            rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y, uint32_t z);
#else
    #define GET_ELEMENT_AT(T) \
    static inline T __attribute__((overloadable)) \
            rsGetElementAt_##T(rs_allocation a, uint32_t x) {  \
        return ((T *)rsGetElementAt(a, x))[0]; \
    } \
    static inline T __attribute__((overloadable)) \
            rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y) {  \
        return ((T *)rsGetElementAt(a, x, y))[0]; \
    } \
    static inline T __attribute__((overloadable)) \
            rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) {  \
        return ((T *)rsGetElementAt(a, x, y, z))[0]; \
    }
#endif

GET_ELEMENT_AT(char)
GET_ELEMENT_AT(char2)
GET_ELEMENT_AT(char3)
GET_ELEMENT_AT(char4)
GET_ELEMENT_AT(uchar)
GET_ELEMENT_AT(uchar2)
GET_ELEMENT_AT(uchar3)
GET_ELEMENT_AT(uchar4)
GET_ELEMENT_AT(short)
GET_ELEMENT_AT(short2)
GET_ELEMENT_AT(short3)
GET_ELEMENT_AT(short4)
GET_ELEMENT_AT(ushort)
GET_ELEMENT_AT(ushort2)
GET_ELEMENT_AT(ushort3)
GET_ELEMENT_AT(ushort4)
GET_ELEMENT_AT(int)
GET_ELEMENT_AT(int2)
GET_ELEMENT_AT(int3)
GET_ELEMENT_AT(int4)
GET_ELEMENT_AT(uint)
GET_ELEMENT_AT(uint2)
GET_ELEMENT_AT(uint3)
GET_ELEMENT_AT(uint4)
GET_ELEMENT_AT(long)
GET_ELEMENT_AT(long2)
GET_ELEMENT_AT(long3)
GET_ELEMENT_AT(long4)
GET_ELEMENT_AT(ulong)
GET_ELEMENT_AT(ulong2)
GET_ELEMENT_AT(ulong3)
GET_ELEMENT_AT(ulong4)
GET_ELEMENT_AT(float)
GET_ELEMENT_AT(float2)
GET_ELEMENT_AT(float3)
GET_ELEMENT_AT(float4)
GET_ELEMENT_AT(double)
GET_ELEMENT_AT(double2)
GET_ELEMENT_AT(double3)
GET_ELEMENT_AT(double4)

#undef GET_ELEMENT_AT

// Jelly Bean
#if (defined(RS_VERSION) && (RS_VERSION >= 16))

/**
 * Send the contents of the Allocation to the queue.
 * @param a allocation to work on
 */
extern const void __attribute__((overloadable))
    rsAllocationIoSend(rs_allocation a);

/**
 * Receive a new set of contents from the queue.
 * @param a allocation to work on
 */
extern const void __attribute__((overloadable))
    rsAllocationIoReceive(rs_allocation a);


/**
 * Get the element object describing the allocation's layout
 * @param a allocation to get data from
 * @return element describing allocation layout
 */
extern rs_element __attribute__((overloadable))
    rsAllocationGetElement(rs_allocation a);

/**
 * Fetch allocation in a way described by the sampler
 * @param a 1D allocation to sample from
 * @param s sampler state
 * @param location to sample from
 */
extern const float4 __attribute__((overloadable))
    rsSample(rs_allocation a, rs_sampler s, float location);
/**
 * Fetch allocation in a way described by the sampler
 * @param a 1D allocation to sample from
 * @param s sampler state
 * @param location to sample from
 * @param lod mip level to sample from, for fractional values
 *            mip levels will be interpolated if
 *            RS_SAMPLER_LINEAR_MIP_LINEAR is used
 */
extern const float4 __attribute__((overloadable))
    rsSample(rs_allocation a, rs_sampler s, float location, float lod);

/**
 * Fetch allocation in a way described by the sampler
 * @param a 2D allocation to sample from
 * @param s sampler state
 * @param location to sample from
 */
extern const float4 __attribute__((overloadable))
    rsSample(rs_allocation a, rs_sampler s, float2 location);

/**
 * Fetch allocation in a way described by the sampler
 * @param a 2D allocation to sample from
 * @param s sampler state
 * @param location to sample from
 * @param lod mip level to sample from, for fractional values
 *            mip levels will be interpolated if
 *            RS_SAMPLER_LINEAR_MIP_LINEAR is used
 */
extern const float4 __attribute__((overloadable))
    rsSample(rs_allocation a, rs_sampler s, float2 location, float lod);

#endif // (defined(RS_VERSION) && (RS_VERSION >= 16))

#if (defined(RS_VERSION) && (RS_VERSION >= 18))

/**
 * Set single element of an allocation.
 */
extern void __attribute__((overloadable))
    rsSetElementAt(rs_allocation a, void* ptr, uint32_t x);

/**
 * \overload
 */
extern void __attribute__((overloadable))
    rsSetElementAt(rs_allocation a, void* ptr, uint32_t x, uint32_t y);

#define SET_ELEMENT_AT(T)                                               \
    extern void __attribute__((overloadable))                           \
    rsSetElementAt_##T(rs_allocation a, T val, uint32_t x);             \
    extern void __attribute__((overloadable))                           \
    rsSetElementAt_##T(rs_allocation a, T val, uint32_t x, uint32_t y); \
    extern void __attribute__((overloadable))                           \
    rsSetElementAt_##T(rs_allocation a, T val, uint32_t x, uint32_t y, uint32_t z);


SET_ELEMENT_AT(char)
SET_ELEMENT_AT(char2)
SET_ELEMENT_AT(char3)
SET_ELEMENT_AT(char4)
SET_ELEMENT_AT(uchar)
SET_ELEMENT_AT(uchar2)
SET_ELEMENT_AT(uchar3)
SET_ELEMENT_AT(uchar4)
SET_ELEMENT_AT(short)
SET_ELEMENT_AT(short2)
SET_ELEMENT_AT(short3)
SET_ELEMENT_AT(short4)
SET_ELEMENT_AT(ushort)
SET_ELEMENT_AT(ushort2)
SET_ELEMENT_AT(ushort3)
SET_ELEMENT_AT(ushort4)
SET_ELEMENT_AT(int)
SET_ELEMENT_AT(int2)
SET_ELEMENT_AT(int3)
SET_ELEMENT_AT(int4)
SET_ELEMENT_AT(uint)
SET_ELEMENT_AT(uint2)
SET_ELEMENT_AT(uint3)
SET_ELEMENT_AT(uint4)
SET_ELEMENT_AT(long)
SET_ELEMENT_AT(long2)
SET_ELEMENT_AT(long3)
SET_ELEMENT_AT(long4)
SET_ELEMENT_AT(ulong)
SET_ELEMENT_AT(ulong2)
SET_ELEMENT_AT(ulong3)
SET_ELEMENT_AT(ulong4)
SET_ELEMENT_AT(float)
SET_ELEMENT_AT(float2)
SET_ELEMENT_AT(float3)
SET_ELEMENT_AT(float4)
SET_ELEMENT_AT(double)
SET_ELEMENT_AT(double2)
SET_ELEMENT_AT(double3)
SET_ELEMENT_AT(double4)

#undef SET_ELEMENT_AT


/**
 * Extract a single element from an allocation.
 */
extern const uchar __attribute__((overloadable))
    rsGetElementAtYuv_uchar_Y(rs_allocation a, uint32_t x, uint32_t y);

/**
 * Extract a single element from an allocation.
 *
 * Coordinates are in the dimensions of the Y plane
 */
extern const uchar __attribute__((overloadable))
    rsGetElementAtYuv_uchar_U(rs_allocation a, uint32_t x, uint32_t y);

/**
 * Extract a single element from an allocation.
 *
 * Coordinates are in the dimensions of the Y plane
 */
extern const uchar __attribute__((overloadable))
    rsGetElementAtYuv_uchar_V(rs_allocation a, uint32_t x, uint32_t y);

#endif // (defined(RS_VERSION) && (RS_VERSION >= 18))

#if (defined(RS_VERSION) && (RS_VERSION >= 22))

#define VOP(T)                                                                   \
    extern T __attribute__((overloadable))                                       \
    rsAllocationVLoadX_##T(rs_allocation a, uint32_t x);                         \
    extern T __attribute__((overloadable))                                       \
    rsAllocationVLoadX_##T(rs_allocation a, uint32_t x, uint32_t y);             \
    extern T __attribute__((overloadable))                                       \
    rsAllocationVLoadX_##T(rs_allocation a, uint32_t x, uint32_t y, uint32_t z); \
    extern void __attribute__((overloadable))                                    \
    rsAllocationVStoreX_##T(rs_allocation a, T val, uint32_t x);                 \
    extern void __attribute__((overloadable))                                    \
    rsAllocationVStoreX_##T(rs_allocation a, T val, uint32_t x, uint32_t y);     \
    extern void __attribute__((overloadable))                                    \
    rsAllocationVStoreX_##T(rs_allocation a, T val, uint32_t x, uint32_t y, uint32_t z);

VOP(char2)
VOP(char3)
VOP(char4)
VOP(uchar2)
VOP(uchar3)
VOP(uchar4)
VOP(short2)
VOP(short3)
VOP(short4)
VOP(ushort2)
VOP(ushort3)
VOP(ushort4)
VOP(int2)
VOP(int3)
VOP(int4)
VOP(uint2)
VOP(uint3)
VOP(uint4)
VOP(long2)
VOP(long3)
VOP(long4)
VOP(ulong2)
VOP(ulong3)
VOP(ulong4)
VOP(float2)
VOP(float3)
VOP(float4)
VOP(double2)
VOP(double3)
VOP(double4)

#undef VOP

#endif //(defined(RS_VERSION) && (RS_VERSION >= 22))


#endif