blob: f38f72c4ee084aac0d4bc1963d4e4639c8bc5b3a [file] [log] [blame]
Jason Samsc4cdf452010-07-07 11:55:51 -07001#ifndef __RS_MATH_RSH__
2#define __RS_MATH_RSH__
3
Jason Sams09aeb8a2011-01-28 15:49:07 -08004/**
5 * Copy reference to the specified object.
6 *
7 * @param dst
8 * @param src
9 */
Jason Samsc0936852010-08-16 12:41:48 -070010extern void __attribute__((overloadable))
11 rsSetObject(rs_element *dst, rs_element src);
12extern void __attribute__((overloadable))
13 rsSetObject(rs_type *dst, rs_type src);
14extern void __attribute__((overloadable))
15 rsSetObject(rs_allocation *dst, rs_allocation src);
16extern void __attribute__((overloadable))
17 rsSetObject(rs_sampler *dst, rs_sampler src);
18extern void __attribute__((overloadable))
19 rsSetObject(rs_script *dst, rs_script src);
20extern void __attribute__((overloadable))
21 rsSetObject(rs_mesh *dst, rs_mesh src);
22extern void __attribute__((overloadable))
23 rsSetObject(rs_program_fragment *dst, rs_program_fragment src);
24extern void __attribute__((overloadable))
25 rsSetObject(rs_program_vertex *dst, rs_program_vertex src);
26extern void __attribute__((overloadable))
27 rsSetObject(rs_program_raster *dst, rs_program_raster src);
28extern void __attribute__((overloadable))
29 rsSetObject(rs_program_store *dst, rs_program_store src);
30extern void __attribute__((overloadable))
31 rsSetObject(rs_font *dst, rs_font src);
32
Jason Sams09aeb8a2011-01-28 15:49:07 -080033/**
34 * Sets the object to NULL.
35 *
36 * @return bool
37 */
Jason Samsc0936852010-08-16 12:41:48 -070038extern void __attribute__((overloadable))
39 rsClearObject(rs_element *dst);
40extern void __attribute__((overloadable))
41 rsClearObject(rs_type *dst);
42extern void __attribute__((overloadable))
43 rsClearObject(rs_allocation *dst);
44extern void __attribute__((overloadable))
45 rsClearObject(rs_sampler *dst);
46extern void __attribute__((overloadable))
47 rsClearObject(rs_script *dst);
48extern void __attribute__((overloadable))
49 rsClearObject(rs_mesh *dst);
50extern void __attribute__((overloadable))
51 rsClearObject(rs_program_fragment *dst);
52extern void __attribute__((overloadable))
53 rsClearObject(rs_program_vertex *dst);
54extern void __attribute__((overloadable))
55 rsClearObject(rs_program_raster *dst);
56extern void __attribute__((overloadable))
57 rsClearObject(rs_program_store *dst);
58extern void __attribute__((overloadable))
59 rsClearObject(rs_font *dst);
60
Jason Sams09aeb8a2011-01-28 15:49:07 -080061/**
62 * Tests if the object is valid. Returns true if the object is valid, false if
63 * it is NULL.
64 *
65 * @return bool
66 */
Jason Samsc0936852010-08-16 12:41:48 -070067extern bool __attribute__((overloadable))
68 rsIsObject(rs_element);
69extern bool __attribute__((overloadable))
70 rsIsObject(rs_type);
71extern bool __attribute__((overloadable))
72 rsIsObject(rs_allocation);
73extern bool __attribute__((overloadable))
74 rsIsObject(rs_sampler);
75extern bool __attribute__((overloadable))
76 rsIsObject(rs_script);
77extern bool __attribute__((overloadable))
78 rsIsObject(rs_mesh);
79extern bool __attribute__((overloadable))
80 rsIsObject(rs_program_fragment);
81extern bool __attribute__((overloadable))
82 rsIsObject(rs_program_vertex);
83extern bool __attribute__((overloadable))
84 rsIsObject(rs_program_raster);
85extern bool __attribute__((overloadable))
86 rsIsObject(rs_program_store);
87extern bool __attribute__((overloadable))
88 rsIsObject(rs_font);
89
90
Jason Sams09aeb8a2011-01-28 15:49:07 -080091/**
92 * Returns the Allocation for a given pointer. The pointer should point within
93 * a valid allocation. The results are undefined if the pointer is not from a
94 * valid allocation.
95 */
Jason Samsef5867a2010-07-28 11:17:53 -070096extern rs_allocation __attribute__((overloadable))
97 rsGetAllocation(const void *);
Jason Sams73495472010-07-29 17:31:14 -070098
Jason Sams09aeb8a2011-01-28 15:49:07 -080099/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800100 * Query the dimension of an allocation.
101 *
102 * @return uint32_t The X dimension of the allocation.
103 */
Jason Samsef5867a2010-07-28 11:17:53 -0700104extern uint32_t __attribute__((overloadable))
105 rsAllocationGetDimX(rs_allocation);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800106
107/**
108 * Query the dimension of an allocation.
109 *
110 * @return uint32_t The Y dimension of the allocation.
111 */
Jason Samsef5867a2010-07-28 11:17:53 -0700112extern uint32_t __attribute__((overloadable))
113 rsAllocationGetDimY(rs_allocation);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800114
115/**
116 * Query the dimension of an allocation.
117 *
118 * @return uint32_t The Z dimension of the allocation.
119 */
Jason Samsef5867a2010-07-28 11:17:53 -0700120extern uint32_t __attribute__((overloadable))
121 rsAllocationGetDimZ(rs_allocation);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800122
123/**
124 * Query an allocation for the presence of more than one LOD.
125 *
126 * @return uint32_t Returns 1 if more than one LOD is present, 0 otherwise.
127 */
Jason Samsef5867a2010-07-28 11:17:53 -0700128extern uint32_t __attribute__((overloadable))
129 rsAllocationGetDimLOD(rs_allocation);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800130
131/**
132 * Query an allocation for the presence of more than one face.
133 *
134 * @return uint32_t Returns 1 if more than one face is present, 0 otherwise.
135 */
Jason Samsef5867a2010-07-28 11:17:53 -0700136extern uint32_t __attribute__((overloadable))
137 rsAllocationGetDimFaces(rs_allocation);
Jason Sams22fa3712010-05-19 17:22:57 -0700138
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700139/**
140 * Copy part of an allocation from another allocation.
141 *
142 * @param dstAlloc Allocation to copy data into.
143 * @param dstOff The offset of the first element to be copied in
144 * the destination allocation.
145 * @param dstMip Mip level in the destination allocation.
146 * @param count The number of elements to be copied.
147 * @param srcAlloc The source data allocation.
148 * @param srcOff The offset of the first element in data to be
149 * copied in the source allocation.
150 * @param srcMip Mip level in the source allocation.
151 */
152extern void __attribute__((overloadable))
153 rsAllocationCopy1DRange(rs_allocation dstAlloc,
154 uint32_t dstOff, uint32_t dstMip,
155 uint32_t count,
156 rs_allocation srcAlloc,
157 uint32_t srcOff, uint32_t srcMip);
158
159/**
160 * Copy a rectangular region into the allocation from another
161 * allocation.
162 *
163 * @param dstAlloc allocation to copy data into.
164 * @param dstXoff X offset of the region to update in the
165 * destination allocation.
166 * @param dstYoff Y offset of the region to update in the
167 * destination allocation.
168 * @param dstMip Mip level in the destination allocation.
169 * @param dstFace Cubemap face of the destination allocation,
170 * ignored for allocations that aren't cubemaps.
171 * @param width Width of the incoming region to update.
172 * @param height Height of the incoming region to update.
173 * @param srcAlloc The source data allocation.
174 * @param srcXoff X offset in data of the source allocation.
175 * @param srcYoff Y offset in data of the source allocation.
176 * @param srcMip Mip level in the source allocation.
177 * @param srcFace Cubemap face of the source allocation,
178 * ignored for allocations that aren't cubemaps.
179 */
180extern void __attribute__((overloadable))
181 rsAllocationCopy2DRange(rs_allocation dstAlloc,
182 uint32_t dstXoff, uint32_t dstYoff,
183 uint32_t dstMip,
184 rs_allocation_cubemap_face dstFace,
185 uint32_t width, uint32_t height,
186 rs_allocation srcAlloc,
187 uint32_t srcXoff, uint32_t srcYoff,
188 uint32_t srcMip,
189 rs_allocation_cubemap_face srcFace);
190
Jason Sams73495472010-07-29 17:31:14 -0700191// Extract a single element from an allocation.
Jason Sams7bf29dd2010-07-19 15:38:19 -0700192extern const void * __attribute__((overloadable))
193 rsGetElementAt(rs_allocation, uint32_t x);
194extern const void * __attribute__((overloadable))
195 rsGetElementAt(rs_allocation, uint32_t x, uint32_t y);
196extern const void * __attribute__((overloadable))
197 rsGetElementAt(rs_allocation, uint32_t x, uint32_t y, uint32_t z);
Jason Sams22fa3712010-05-19 17:22:57 -0700198
Jason Sams73495472010-07-29 17:31:14 -0700199// Return a random value between 0 (or min_value) and max_malue.
200extern int __attribute__((overloadable))
201 rsRand(int max_value);
202extern int __attribute__((overloadable))
203 rsRand(int min_value, int max_value);
204extern float __attribute__((overloadable))
205 rsRand(float max_value);
206extern float __attribute__((overloadable))
207 rsRand(float min_value, float max_value);
Jason Sams22fa3712010-05-19 17:22:57 -0700208
Jason Sams73495472010-07-29 17:31:14 -0700209// return the fractional part of a float
210// min(v - ((int)floor(v)), 0x1.fffffep-1f);
211extern float __attribute__((overloadable))
212 rsFrac(float);
Jason Sams22fa3712010-05-19 17:22:57 -0700213
Jason Sams73495472010-07-29 17:31:14 -0700214// Send a message back to the client. Will not block and returns true
215// if the message was sendable and false if the fifo was full.
216// A message ID is required. Data payload is optional.
217extern bool __attribute__((overloadable))
218 rsSendToClient(int cmdID);
219extern bool __attribute__((overloadable))
220 rsSendToClient(int cmdID, const void *data, uint len);
221
222// Send a message back to the client, blocking until the message is queued.
223// A message ID is required. Data payload is optional.
224extern void __attribute__((overloadable))
225 rsSendToClientBlocking(int cmdID);
226extern void __attribute__((overloadable))
227 rsSendToClientBlocking(int cmdID, const void *data, uint len);
Jason Sams22fa3712010-05-19 17:22:57 -0700228
Jason Samsdd663fa2010-08-11 13:26:28 -0700229
Jason Samsc61346b2010-05-28 18:23:22 -0700230// Script to Script
Jason Samsdd663fa2010-08-11 13:26:28 -0700231enum rs_for_each_strategy {
232 RS_FOR_EACH_STRATEGY_SERIAL,
233 RS_FOR_EACH_STRATEGY_DONT_CARE,
234 RS_FOR_EACH_STRATEGY_DST_LINEAR,
235 RS_FOR_EACH_STRATEGY_TILE_SMALL,
236 RS_FOR_EACH_STRATEGY_TILE_MEDIUM,
237 RS_FOR_EACH_STRATEGY_TILE_LARGE
238};
239
Jason Samsace3e012010-07-15 17:11:13 -0700240typedef struct rs_script_call {
Jason Samsdd663fa2010-08-11 13:26:28 -0700241 enum rs_for_each_strategy strategy;
Jason Sams479e2922010-07-09 15:34:32 -0700242 uint32_t xStart;
243 uint32_t xEnd;
244 uint32_t yStart;
245 uint32_t yEnd;
246 uint32_t zStart;
247 uint32_t zEnd;
248 uint32_t arrayStart;
249 uint32_t arrayEnd;
Jason Samsace3e012010-07-15 17:11:13 -0700250} rs_script_call_t;
Jason Sams479e2922010-07-09 15:34:32 -0700251
Jason Sams73495472010-07-29 17:31:14 -0700252extern void __attribute__((overloadable))
253 rsForEach(rs_script script, rs_allocation input,
254 rs_allocation output, const void * usrData);
Jason Samsace3e012010-07-15 17:11:13 -0700255
Jason Sams73495472010-07-29 17:31:14 -0700256extern void __attribute__((overloadable))
257 rsForEach(rs_script script, rs_allocation input,
258 rs_allocation output, const void * usrData,
259 const rs_script_call_t *);
Jason Samsc61346b2010-05-28 18:23:22 -0700260
Jason Samse1eb6152011-06-21 16:42:30 -0700261
262
263/**
264 * Atomic add one to the value at addr.
265 * Equal to rsAtomicAdd(addr, 1)
266 *
267 * @param addr Address of value to increment
268 *
269 * @return old value
270 */
271extern int32_t __attribute__((overloadable))
272 rsAtomicInc(volatile int32_t* addr);
273/**
274 * Atomic add one to the value at addr.
275 * Equal to rsAtomicAdd(addr, 1)
276 *
277 * @param addr Address of value to increment
278 *
279 * @return old value
280 */
281extern uint32_t __attribute__((overloadable))
282 rsAtomicInc(volatile uint32_t* addr);
283
284/**
285 * Atomic subtract one from the value at addr. Equal to rsAtomicSub(addr, 1)
286 *
287 * @param addr Address of value to decrement
288 *
289 * @return old value
290 */
291extern int32_t __attribute__((overloadable))
292 rsAtomicDec(volatile int32_t* addr);
293/**
294 * Atomic subtract one from the value at addr. Equal to rsAtomicSub(addr, 1)
295 *
296 * @param addr Address of value to decrement
297 *
298 * @return old value
299 */
300extern uint32_t __attribute__((overloadable))
301 rsAtomicDec(volatile uint32_t* addr);
302
303/**
304 * Atomic add a value to the value at addr. addr[0] += value
305 *
306 * @param addr Address of value to modify
307 * @param value Amount to add to the value at addr
308 *
309 * @return old value
310 */
311extern int32_t __attribute__((overloadable))
312 rsAtomicAdd(volatile int32_t* addr, int32_t value);
313/**
314 * Atomic add a value to the value at addr. addr[0] += value
315 *
316 * @param addr Address of value to modify
317 * @param value Amount to add to the value at addr
318 *
319 * @return old value
320 */
321extern uint32_t __attribute__((overloadable))
322 rsAtomicAdd(volatile uint32_t* addr, uint32_t value);
323
324/**
325 * Atomic Subtract a value from the value at addr. addr[0] -= value
326 *
327 * @param addr Address of value to modify
328 * @param value Amount to subtract from the value at addr
329 *
330 * @return old value
331 */
332extern int32_t __attribute__((overloadable))
333 rsAtomicSub(volatile int32_t* addr, int32_t value);
334/**
335 * Atomic Subtract a value from the value at addr. addr[0] -= value
336 *
337 * @param addr Address of value to modify
338 * @param value Amount to subtract from the value at addr
339 *
340 * @return old value
341 */
342extern uint32_t __attribute__((overloadable))
343 rsAtomicSub(volatile uint32_t* addr, uint32_t value);
344
345/**
346 * Atomic Bitwise and a value from the value at addr. addr[0] &= value
347 *
348 * @param addr Address of value to modify
349 * @param value Amount to and with the value at addr
350 *
351 * @return old value
352 */
353extern int32_t __attribute__((overloadable))
354 rsAtomicAnd(volatile int32_t* addr, int32_t value);
355/**
356 * Atomic Bitwise and a value from the value at addr. addr[0] &= value
357 *
358 * @param addr Address of value to modify
359 * @param value Amount to and with the value at addr
360 *
361 * @return old value
362 */
363extern uint32_t __attribute__((overloadable))
364 rsAtomicAnd(volatile uint32_t* addr, uint32_t value);
365
366/**
367 * Atomic Bitwise or a value from the value at addr. addr[0] |= value
368 *
369 * @param addr Address of value to modify
370 * @param value Amount to or with the value at addr
371 *
372 * @return old value
373 */
374extern int32_t __attribute__((overloadable))
375 rsAtomicOr(volatile int32_t* addr, int32_t value);
376/**
377 * Atomic Bitwise or a value from the value at addr. addr[0] |= value
378 *
379 * @param addr Address of value to modify
380 * @param value Amount to or with the value at addr
381 *
382 * @return old value
383 */
384extern uint32_t __attribute__((overloadable))
385 rsAtomicOr(volatile uint32_t* addr, uint32_t value);
386
387/**
388 * Atomic Bitwise xor a value from the value at addr. addr[0] ^= value
389 *
390 * @param addr Address of value to modify
391 * @param value Amount to xor with the value at addr
392 *
393 * @return old value
394 */
395extern uint32_t __attribute__((overloadable))
396 rsAtomicXor(volatile uint32_t* addr, uint32_t value);
397/**
398 * Atomic Bitwise xor a value from the value at addr. addr[0] ^= value
399 *
400 * @param addr Address of value to modify
401 * @param value Amount to xor with the value at addr
402 *
403 * @return old value
404 */
405extern int32_t __attribute__((overloadable))
406 rsAtomicXor(volatile int32_t* addr, int32_t value);
407
408/**
409 * Atomic Set the value at addr to the min of addr and value
410 * addr[0] = rsMin(addr[0], value)
411 *
412 * @param addr Address of value to modify
413 * @param value comparison value
414 *
415 * @return old value
416 */
417extern uint32_t __attribute__((overloadable))
418 rsAtomicMin(volatile uint32_t* addr, uint32_t value);
419/**
420 * Atomic Set the value at addr to the min of addr and value
421 * addr[0] = rsMin(addr[0], value)
422 *
423 * @param addr Address of value to modify
424 * @param value comparison value
425 *
426 * @return old value
427 */
428extern int32_t __attribute__((overloadable))
429 rsAtomicMin(volatile int32_t* addr, int32_t value);
430
431/**
432 * Atomic Set the value at addr to the max of addr and value
433 * addr[0] = rsMax(addr[0], value)
434 *
435 * @param addr Address of value to modify
436 * @param value comparison value
437 *
438 * @return old value
439 */
440extern uint32_t __attribute__((overloadable))
441 rsAtomicMax(volatile uint32_t* addr, uint32_t value);
442/**
443 * Atomic Set the value at addr to the max of addr and value
444 * addr[0] = rsMin(addr[0], value)
445 *
446 * @param addr Address of value to modify
447 * @param value comparison value
448 *
449 * @return old value
450 */
451extern int32_t __attribute__((overloadable))
452 rsAtomicMax(volatile int32_t* addr, int32_t value);
453
454/**
455 * Compare-and-set operation with a full memory barrier.
456 *
457 * If the value at addr matches compareValue then newValue is written.
458 *
459 * @param addr The address to compare and replace if the compare passes.
460 * @param compareValue The value to test addr[0] against.
461 * @param newValue The value to write if the test passes.
462 *
463 * @return old value
464 */
465extern int32_t __attribute__((overloadable))
466 rsAtomicCas(volatile int32_t* addr, int32_t compareValue, int32_t newValue);
467
468/**
469 * Compare-and-set operation with a full memory barrier.
470 *
471 * If the value at addr matches compareValue then newValue is written.
472 *
473 * @param addr The address to compare and replace if the compare passes.
474 * @param compareValue The value to test addr[0] against.
475 * @param newValue The value to write if the test passes.
476 *
477 * @return old value
478 */
479extern uint32_t __attribute__((overloadable))
480 rsAtomicCas(volatile uint32_t* addr, int32_t compareValue, int32_t newValue);
481
482
Jason Samsc4cdf452010-07-07 11:55:51 -0700483#endif