blob: fb5c4f6ddb65bf54214aadec796542a7511538be [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 Samsc500e742011-07-25 12:58:37 -0700252#if 1//(RS_VERSION >= 14)
Jason Sams73495472010-07-29 17:31:14 -0700253extern void __attribute__((overloadable))
Jason Samsc500e742011-07-25 12:58:37 -0700254 rsForEach(rs_script script, rs_allocation input, rs_allocation output);
Jason Samsace3e012010-07-15 17:11:13 -0700255
Jason Sams73495472010-07-29 17:31:14 -0700256extern void __attribute__((overloadable))
Jason Samsc500e742011-07-25 12:58:37 -0700257 rsForEach(rs_script script, rs_allocation input, rs_allocation output,
258 const void * usrData, size_t usrDataLen);
259
260extern void __attribute__((overloadable))
261 rsForEach(rs_script script, rs_allocation input, rs_allocation output,
262 const void * usrData, size_t usrDataLen, const rs_script_call_t *);
263#else
264extern void __attribute__((overloadable))
Jason Sams73495472010-07-29 17:31:14 -0700265 rsForEach(rs_script script, rs_allocation input,
266 rs_allocation output, const void * usrData,
267 const rs_script_call_t *);
Jason Samsc500e742011-07-25 12:58:37 -0700268#endif
Jason Samsc61346b2010-05-28 18:23:22 -0700269
Jason Samsc500e742011-07-25 12:58:37 -0700270// Move me once dependant changes are in.
271extern void __attribute__((overloadable))
272 rsForEach(rs_script script, rs_allocation input,
273 rs_allocation output, const void * usrData);
Jason Samse1eb6152011-06-21 16:42:30 -0700274
275
276/**
277 * Atomic add one to the value at addr.
278 * Equal to rsAtomicAdd(addr, 1)
279 *
280 * @param addr Address of value to increment
281 *
282 * @return old value
283 */
284extern int32_t __attribute__((overloadable))
285 rsAtomicInc(volatile int32_t* addr);
286/**
287 * Atomic add one to the value at addr.
288 * Equal to rsAtomicAdd(addr, 1)
289 *
290 * @param addr Address of value to increment
291 *
292 * @return old value
293 */
294extern uint32_t __attribute__((overloadable))
295 rsAtomicInc(volatile uint32_t* addr);
296
297/**
298 * Atomic subtract one from the value at addr. Equal to rsAtomicSub(addr, 1)
299 *
300 * @param addr Address of value to decrement
301 *
302 * @return old value
303 */
304extern int32_t __attribute__((overloadable))
305 rsAtomicDec(volatile int32_t* addr);
306/**
307 * Atomic subtract one from the value at addr. Equal to rsAtomicSub(addr, 1)
308 *
309 * @param addr Address of value to decrement
310 *
311 * @return old value
312 */
313extern uint32_t __attribute__((overloadable))
314 rsAtomicDec(volatile uint32_t* addr);
315
316/**
317 * Atomic add a value to the value at addr. addr[0] += value
318 *
319 * @param addr Address of value to modify
320 * @param value Amount to add to the value at addr
321 *
322 * @return old value
323 */
324extern int32_t __attribute__((overloadable))
325 rsAtomicAdd(volatile int32_t* addr, int32_t value);
326/**
327 * Atomic add a value to the value at addr. addr[0] += value
328 *
329 * @param addr Address of value to modify
330 * @param value Amount to add to the value at addr
331 *
332 * @return old value
333 */
334extern uint32_t __attribute__((overloadable))
335 rsAtomicAdd(volatile uint32_t* addr, uint32_t value);
336
337/**
338 * Atomic Subtract a value from the value at addr. addr[0] -= value
339 *
340 * @param addr Address of value to modify
341 * @param value Amount to subtract from the value at addr
342 *
343 * @return old value
344 */
345extern int32_t __attribute__((overloadable))
346 rsAtomicSub(volatile int32_t* addr, int32_t value);
347/**
348 * Atomic Subtract a value from the value at addr. addr[0] -= value
349 *
350 * @param addr Address of value to modify
351 * @param value Amount to subtract from the value at addr
352 *
353 * @return old value
354 */
355extern uint32_t __attribute__((overloadable))
356 rsAtomicSub(volatile uint32_t* addr, uint32_t value);
357
358/**
359 * Atomic Bitwise and a value from the value at addr. addr[0] &= value
360 *
361 * @param addr Address of value to modify
362 * @param value Amount to and with the value at addr
363 *
364 * @return old value
365 */
366extern int32_t __attribute__((overloadable))
367 rsAtomicAnd(volatile int32_t* addr, int32_t value);
368/**
369 * Atomic Bitwise and a value from the value at addr. addr[0] &= value
370 *
371 * @param addr Address of value to modify
372 * @param value Amount to and with the value at addr
373 *
374 * @return old value
375 */
376extern uint32_t __attribute__((overloadable))
377 rsAtomicAnd(volatile uint32_t* addr, uint32_t value);
378
379/**
380 * Atomic Bitwise or a value from the value at addr. addr[0] |= value
381 *
382 * @param addr Address of value to modify
383 * @param value Amount to or with the value at addr
384 *
385 * @return old value
386 */
387extern int32_t __attribute__((overloadable))
388 rsAtomicOr(volatile int32_t* addr, int32_t value);
389/**
390 * Atomic Bitwise or a value from the value at addr. addr[0] |= value
391 *
392 * @param addr Address of value to modify
393 * @param value Amount to or with the value at addr
394 *
395 * @return old value
396 */
397extern uint32_t __attribute__((overloadable))
398 rsAtomicOr(volatile uint32_t* addr, uint32_t value);
399
400/**
401 * Atomic Bitwise xor a value from the value at addr. addr[0] ^= value
402 *
403 * @param addr Address of value to modify
404 * @param value Amount to xor with the value at addr
405 *
406 * @return old value
407 */
408extern uint32_t __attribute__((overloadable))
409 rsAtomicXor(volatile uint32_t* addr, uint32_t value);
410/**
411 * Atomic Bitwise xor a value from the value at addr. addr[0] ^= value
412 *
413 * @param addr Address of value to modify
414 * @param value Amount to xor with the value at addr
415 *
416 * @return old value
417 */
418extern int32_t __attribute__((overloadable))
419 rsAtomicXor(volatile int32_t* addr, int32_t value);
420
421/**
422 * Atomic Set the value at addr to the min of addr and value
423 * addr[0] = rsMin(addr[0], value)
424 *
425 * @param addr Address of value to modify
426 * @param value comparison value
427 *
428 * @return old value
429 */
430extern uint32_t __attribute__((overloadable))
431 rsAtomicMin(volatile uint32_t* addr, uint32_t value);
432/**
433 * Atomic Set the value at addr to the min of addr and value
434 * addr[0] = rsMin(addr[0], value)
435 *
436 * @param addr Address of value to modify
437 * @param value comparison value
438 *
439 * @return old value
440 */
441extern int32_t __attribute__((overloadable))
442 rsAtomicMin(volatile int32_t* addr, int32_t value);
443
444/**
445 * Atomic Set the value at addr to the max of addr and value
446 * addr[0] = rsMax(addr[0], value)
447 *
448 * @param addr Address of value to modify
449 * @param value comparison value
450 *
451 * @return old value
452 */
453extern uint32_t __attribute__((overloadable))
454 rsAtomicMax(volatile uint32_t* addr, uint32_t value);
455/**
456 * Atomic Set the value at addr to the max of addr and value
457 * addr[0] = rsMin(addr[0], value)
458 *
459 * @param addr Address of value to modify
460 * @param value comparison value
461 *
462 * @return old value
463 */
464extern int32_t __attribute__((overloadable))
465 rsAtomicMax(volatile int32_t* addr, int32_t value);
466
467/**
468 * Compare-and-set operation with a full memory barrier.
469 *
470 * If the value at addr matches compareValue then newValue is written.
471 *
472 * @param addr The address to compare and replace if the compare passes.
473 * @param compareValue The value to test addr[0] against.
474 * @param newValue The value to write if the test passes.
475 *
476 * @return old value
477 */
478extern int32_t __attribute__((overloadable))
479 rsAtomicCas(volatile int32_t* addr, int32_t compareValue, int32_t newValue);
480
481/**
482 * Compare-and-set operation with a full memory barrier.
483 *
484 * If the value at addr matches compareValue then newValue is written.
485 *
486 * @param addr The address to compare and replace if the compare passes.
487 * @param compareValue The value to test addr[0] against.
488 * @param newValue The value to write if the test passes.
489 *
490 * @return old value
491 */
492extern uint32_t __attribute__((overloadable))
493 rsAtomicCas(volatile uint32_t* addr, int32_t compareValue, int32_t newValue);
494
495
Jason Samsc4cdf452010-07-07 11:55:51 -0700496#endif