## Overview

RenderScript is a high-performance runtime that provides compute operations at the native level.
RenderScript code is compiled on devices at runtime to allow platform-independence as well.

This reference documentation describes the RenderScript runtime APIs, which you can utilize
to write RenderScript code in C99. The RenderScript compute header files are automatically
included for you.

To use RenderScript, you need to utilize the RenderScript runtime APIs documented here as well
as the Android framework APIs for RenderScript. For documentation on the Android framework
APIs, see the [android.renderscript](https://developer.android.com/reference/android/renderscript/package-summary.html) package reference.

For more information on how to develop with RenderScript and how the runtime and Android
framework APIs interact, see the [RenderScript developer guide](https://developer.android.com/guide/topics/renderscript/index.html) and the [RenderScript samples](https://developer.android.com/resources/samples/RenderScript/index.html).

## Numerical Types

##### Scalars:

<br />

RenderScript supports the following scalar numerical types:

|---|---|---|---|---|
|   | 8 bits | 16 bits | 32 bits | 64 bits |
| Integer: | char, [int8_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int8_t) | short, [int16_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int16_t) | [int32_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int32_t) | long, long long, [int64_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int64_t) |
| Unsigned integer: | uchar, [uint8_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint8_t) | ushort, [uint16_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint16_t) | uint, [uint32_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint32_t) | ulong, [uint64_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint64_t) |
| Floating point: |   | half | float | double |

<br />

##### Vectors:

<br />

RenderScript supports fixed size vectors of length 2, 3, and 4.
Vectors are declared using the common type name followed by a 2, 3, or 4.
E.g. [float4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:float4), [int3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int3), [double2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:double2), [ulong4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:ulong4).

To create vector literals, use the vector type followed by the values enclosed
between curly braces, e.g. `(float3){1.0f, 2.0f, 3.0f}`.

Entries of a vector can be accessed using different naming styles.

Single entries can be accessed by following the variable name with a dot and:

- The letters x, y, z, and w,
- The letters r, g, b, and a,
- The letter s or S, followed by a zero based index.

<br />

For example, with `int4 myVar;` the following are equivalent:  
`
myVar.x == myVar.r == myVar.s0 == myVar.S0`  
`
myVar.y == myVar.g == myVar.s1 == myVar.S1`  
`
myVar.z == myVar.b == myVar.s2 == myVar.S2`  
`
myVar.w == myVar.a == myVar.s3 == myVar.S3`

Multiple entries of a vector can be accessed at once by using an identifier that is
the concatenation of multiple letters or indices. The resulting vector has a size
equal to the number of entries named.

With the example above, the middle two entries can be accessed using
`myVar.yz`, `myVar.gb`, `myVar.s12`, and `myVar.S12`.

The entries don't have to be contiguous or in increasing order. Entries can even be
repeated, as long as we're not trying to assign to it. You also can't mix the naming
styles.

Here are examples of what can or can't be done:  
`
float4 v4;`  
`
float3 v3;`  
`
float2 v2;`  
`
v2 = v4.xx; // Valid`  
`
v3 = v4.zxw; // Valid`  
`
v3 = v4.bba; // Valid`  
`
v3 = v4.s032; // Valid`  
`
v3.s120 = v4.S233; // Valid`  
`
v4.yz = v3.rg; // Valid`  
`
v4.yzx = v3.rg; // Invalid: mismatched sizes`  
`
v4.yzz = v3; // Invalid: z appears twice in an assignment`  
`
v3 = v3.xas0; // Invalid: can't mix xyzw with rgba nor s0...`  
`
v3 = v4.s034; // Invalid: the digit can only be 0, 1, 2, or 3`  
`
`

##### Matrices and Quaternions:

<br />

RenderScript supports fixed size square matrices of floats of size 2x2, 3x3, and 4x4.
The types are named [rs_matrix2x2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:rs_matrix2x2), [rs_matrix3x3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:rs_matrix3x3), and [rs_matrix4x4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:rs_matrix4x4). See
[Matrix Functions](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix) for the list of operations.

Quaternions are also supported via [rs_quaternion](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:rs_quaternion). See [Quaterion Functions](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion) for the list
of operations.

| Types ||
|---|---|
| [char2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:char2) | Two 8 bit signed integers |
| [char3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:char3) | Three 8 bit signed integers |
| [char4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:char4) | Four 8 bit signed integers |
| [double2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:double2) | Two 64 bit floats |
| [double3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:double3) | Three 64 bit floats |
| [double4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:double4) | Four 64 bit floats |
| [float2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:float2) | Two 32 bit floats |
| [float3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:float3) | Three 32 bit floats |
| [float4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:float4) | Four 32 bit floats |
| [half](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:half) | 16 bit floating point value |
| [half2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:half2) | Two 16 bit floats |
| [half3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:half3) | Three 16 bit floats |
| [half4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:half4) | Four 16 bit floats |
| [int16_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int16_t) | 16 bit signed integer |
| [int2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int2) | Two 32 bit signed integers |
| [int3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int3) | Three 32 bit signed integers |
| [int32_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int32_t) | 32 bit signed integer |
| [int4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int4) | Four 32 bit signed integers |
| [int64_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int64_t) | 64 bit signed integer |
| [int8_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:int8_t) | 8 bit signed integer |
| [long2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:long2) | Two 64 bit signed integers |
| [long3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:long3) | Three 64 bit signed integers |
| [long4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:long4) | Four 64 bit signed integers |
| [rs_matrix2x2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:rs_matrix2x2) | 2x2 matrix of 32 bit floats |
| [rs_matrix3x3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:rs_matrix3x3) | 3x3 matrix of 32 bit floats |
| [rs_matrix4x4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:rs_matrix4x4) | 4x4 matrix of 32 bit floats |
| [rs_quaternion](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:rs_quaternion) | Quaternion |
| [short2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:short2) | Two 16 bit signed integers |
| [short3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:short3) | Three 16 bit signed integers |
| [short4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:short4) | Four 16 bit signed integers |
| [size_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:size_t) | Unsigned size type |
| [ssize_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:ssize_t) | Signed size type |
| [uchar](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uchar) | 8 bit unsigned integer |
| [uchar2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uchar2) | Two 8 bit unsigned integers |
| [uchar3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uchar3) | Three 8 bit unsigned integers |
| [uchar4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uchar4) | Four 8 bit unsigned integers |
| [uint](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint) | 32 bit unsigned integer |
| [uint16_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint16_t) | 16 bit unsigned integer |
| [uint2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint2) | Two 32 bit unsigned integers |
| [uint3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint3) | Three 32 bit unsigned integers |
| [uint32_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint32_t) | 32 bit unsigned integer |
| [uint4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint4) | Four 32 bit unsigned integers |
| [uint64_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint64_t) | 64 bit unsigned integer |
| [uint8_t](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:uint8_t) | 8 bit unsigned integer |
| [ulong](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:ulong) | 64 bit unsigned integer |
| [ulong2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:ulong2) | Two 64 bit unsigned integers |
| [ulong3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:ulong3) | Three 64 bit unsigned integers |
| [ulong4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:ulong4) | Four 64 bit unsigned integers |
| [ushort](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:ushort) | 16 bit unsigned integer |
| [ushort2](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:ushort2) | Two 16 bit unsigned integers |
| [ushort3](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:ushort3) | Three 16 bit unsigned integers |
| [ushort4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:ushort4) | Four 16 bit unsigned integers |

## Object Types

The types below are used to manipulate RenderScript objects like allocations, samplers,
elements, and scripts. Most of these object are created using the Java RenderScript APIs.

| Types ||
|---|---|
| [rs_allocation](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_allocation) | Handle to an allocation |
| [rs_allocation_cubemap_face](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_allocation_cubemap_face) | Enum for selecting cube map faces |
| [rs_allocation_usage_type](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_allocation_usage_type) | Bitfield to specify how an allocation is used |
| [rs_data_kind](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_data_kind) | Element data kind |
| [rs_data_type](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_data_type) | Element basic data type |
| [rs_element](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_element) | Handle to an element |
| [rs_sampler](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_sampler) | Handle to a Sampler |
| [rs_sampler_value](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_sampler_value) | Sampler wrap T value |
| [rs_script](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_script) | Handle to a Script |
| [rs_type](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_type) | Handle to a Type |
| [rs_yuv_format](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_yuv_format) | YUV format |

## Conversion Functions

The functions below convert from a numerical vector type to another, or from one color
representation to another.

| Functions ||
|---|---|
| [convert](https://developer.android.com/guide/topics/renderscript/reference/rs_convert#android_rs:convert) | Convert numerical vectors |
| [rsPackColorTo8888](https://developer.android.com/guide/topics/renderscript/reference/rs_convert#android_rs:rsPackColorTo8888) | Create a uchar4 RGBA from floats |
| [rsUnpackColor8888](https://developer.android.com/guide/topics/renderscript/reference/rs_convert#android_rs:rsUnpackColor8888) | Create a float4 RGBA from uchar4 |
| [rsYuvToRGBA](https://developer.android.com/guide/topics/renderscript/reference/rs_convert#android_rs:rsYuvToRGBA) | Convert a YUV value to RGBA |

## Mathematical Constants and Functions

The mathematical functions below can be applied to scalars and vectors. When applied
to vectors, the returned value is a vector of the function applied to each entry of the input.

For example:  
`
float3 a, b;`  
`
// The following call sets`  
`
// a.x to sin(b.x),`  
`
// a.y to sin(b.y), and`  
`
// a.z to sin(b.z).`  
`
a = sin(b);`  
`
`

See [Vector Math Functions](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math) for functions like [distance](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:distance)() and [length](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:length)() that interpret
instead the input as a single vector in n-dimensional space.

The precision of the mathematical operations on 32 bit floats is affected by the pragmas
rs_fp_relaxed and rs_fp_full. Under rs_fp_relaxed, subnormal values may be flushed to zero and
rounding may be done towards zero. In comparison, rs_fp_full requires correct handling of
subnormal values, i.e. smaller than 1.17549435e-38f. rs_fp_rull also requires round to nearest
with ties to even.

Different precision/speed tradeoffs can be achieved by using variants of the common math
functions. Functions with a name starting with

- native_: May have custom hardware implementations with weaker precision. Additionally, subnormal values may be flushed to zero, rounding towards zero may be used, and NaN and infinity input may not be handled correctly.
- half_: May perform internal computations using 16 bit floats. Additionally, subnormal values may be flushed to zero, and rounding towards zero may be used.

<br />

| Constants ||
|---|---|
| [M_1_PI](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_1_PI) | 1 / pi, as a 32 bit float |
| [M_2_PI](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_2_PI) | 2 / pi, as a 32 bit float |
| [M_2_SQRTPI](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_2_SQRTPI) | 2 / sqrt(pi), as a 32 bit float |
| [M_E](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_E) | e, as a 32 bit float |
| [M_LN10](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_LN10) | log_e(10), as a 32 bit float |
| [M_LN2](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_LN2) | log_e(2), as a 32 bit float |
| [M_LOG10E](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_LOG10E) | log_10(e), as a 32 bit float |
| [M_LOG2E](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_LOG2E) | log_2(e), as a 32 bit float |
| [M_PI](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_PI) | pi, as a 32 bit float |
| [M_PI_2](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_PI_2) | pi / 2, as a 32 bit float |
| [M_PI_4](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_PI_4) | pi / 4, as a 32 bit float |
| [M_SQRT1_2](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_SQRT1_2) | 1 / sqrt(2), as a 32 bit float |
| [M_SQRT2](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:M_SQRT2) | sqrt(2), as a 32 bit float |

| Functions ||
|---|---|
| [abs](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:abs) | Absolute value of an integer |
| [acos](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:acos) | Inverse cosine |
| [acosh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:acosh) | Inverse hyperbolic cosine |
| [acospi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:acospi) | Inverse cosine divided by pi |
| [asin](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:asin) | Inverse sine |
| [asinh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:asinh) | Inverse hyperbolic sine |
| [asinpi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:asinpi) | Inverse sine divided by pi |
| [atan](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:atan) | Inverse tangent |
| [atan2](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:atan2) | Inverse tangent of a ratio |
| [atan2pi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:atan2pi) | Inverse tangent of a ratio, divided by pi |
| [atanh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:atanh) | Inverse hyperbolic tangent |
| [atanpi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:atanpi) | Inverse tangent divided by pi |
| [cbrt](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:cbrt) | Cube root |
| [ceil](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:ceil) | Smallest integer not less than a value |
| [clamp](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:clamp) | Restrain a value to a range |
| [clz](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:clz) | Number of leading 0 bits |
| [copysign](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:copysign) | Copies the sign of a number to another |
| [cos](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:cos) | Cosine |
| [cosh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:cosh) | Hypebolic cosine |
| [cospi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:cospi) | Cosine of a number multiplied by pi |
| [degrees](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:degrees) | Converts radians into degrees |
| [erf](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:erf) | Mathematical error function |
| [erfc](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:erfc) | Mathematical complementary error function |
| [exp](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:exp) | e raised to a number |
| [exp10](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:exp10) | 10 raised to a number |
| [exp2](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:exp2) | 2 raised to a number |
| [expm1](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:expm1) | e raised to a number minus one |
| [fabs](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:fabs) | Absolute value of a float |
| [fdim](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:fdim) | Positive difference between two values |
| [floor](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:floor) | Smallest integer not greater than a value |
| [fma](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:fma) | Multiply and add |
| [fmax](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:fmax) | Maximum of two floats |
| [fmin](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:fmin) | Minimum of two floats |
| [fmod](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:fmod) | Modulo |
| [fract](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:fract) | Positive fractional part |
| [frexp](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:frexp) | Binary mantissa and exponent |
| [half_recip](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:half_recip) | Reciprocal computed to 16 bit precision |
| [half_rsqrt](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:half_rsqrt) | Reciprocal of a square root computed to 16 bit precision |
| [half_sqrt](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:half_sqrt) | Square root computed to 16 bit precision |
| [hypot](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:hypot) | Hypotenuse |
| [ilogb](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:ilogb) | Base two exponent |
| [ldexp](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:ldexp) | Creates a floating point from mantissa and exponent |
| [lgamma](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:lgamma) | Natural logarithm of the gamma function |
| [log](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:log) | Natural logarithm |
| [log10](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:log10) | Base 10 logarithm |
| [log1p](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:log1p) | Natural logarithm of a value plus 1 |
| [log2](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:log2) | Base 2 logarithm |
| [logb](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:logb) | Base two exponent |
| [mad](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:mad) | Multiply and add |
| [max](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:max) | Maximum |
| [min](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:min) | Minimum |
| [mix](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:mix) | Mixes two values |
| [modf](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:modf) | Integral and fractional components |
| [nan](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:nan) | Not a Number |
| [nan_half](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:nan_half) | Not a Number |
| [native_acos](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_acos) | Approximate inverse cosine |
| [native_acosh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_acosh) | Approximate inverse hyperbolic cosine |
| [native_acospi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_acospi) | Approximate inverse cosine divided by pi |
| [native_asin](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_asin) | Approximate inverse sine |
| [native_asinh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_asinh) | Approximate inverse hyperbolic sine |
| [native_asinpi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_asinpi) | Approximate inverse sine divided by pi |
| [native_atan](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_atan) | Approximate inverse tangent |
| [native_atan2](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_atan2) | Approximate inverse tangent of a ratio |
| [native_atan2pi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_atan2pi) | Approximate inverse tangent of a ratio, divided by pi |
| [native_atanh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_atanh) | Approximate inverse hyperbolic tangent |
| [native_atanpi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_atanpi) | Approximate inverse tangent divided by pi |
| [native_cbrt](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_cbrt) | Approximate cube root |
| [native_cos](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_cos) | Approximate cosine |
| [native_cosh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_cosh) | Approximate hypebolic cosine |
| [native_cospi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_cospi) | Approximate cosine of a number multiplied by pi |
| [native_divide](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_divide) | Approximate division |
| [native_exp](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_exp) | Approximate e raised to a number |
| [native_exp10](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_exp10) | Approximate 10 raised to a number |
| [native_exp2](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_exp2) | Approximate 2 raised to a number |
| [native_expm1](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_expm1) | Approximate e raised to a number minus one |
| [native_hypot](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_hypot) | Approximate hypotenuse |
| [native_log](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_log) | Approximate natural logarithm |
| [native_log10](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_log10) | Approximate base 10 logarithm |
| [native_log1p](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_log1p) | Approximate natural logarithm of a value plus 1 |
| [native_log2](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_log2) | Approximate base 2 logarithm |
| [native_powr](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_powr) | Approximate positive base raised to an exponent |
| [native_recip](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_recip) | Approximate reciprocal |
| [native_rootn](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_rootn) | Approximate nth root |
| [native_rsqrt](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_rsqrt) | Approximate reciprocal of a square root |
| [native_sin](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_sin) | Approximate sine |
| [native_sincos](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_sincos) | Approximate sine and cosine |
| [native_sinh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_sinh) | Approximate hyperbolic sine |
| [native_sinpi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_sinpi) | Approximate sine of a number multiplied by pi |
| [native_sqrt](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_sqrt) | Approximate square root |
| [native_tan](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_tan) | Approximate tangent |
| [native_tanh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_tanh) | Approximate hyperbolic tangent |
| [native_tanpi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:native_tanpi) | Approximate tangent of a number multiplied by pi |
| [nextafter](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:nextafter) | Next floating point number |
| [pow](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:pow) | Base raised to an exponent |
| [pown](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:pown) | Base raised to an integer exponent |
| [powr](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:powr) | Positive base raised to an exponent |
| [radians](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:radians) | Converts degrees into radians |
| [remainder](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:remainder) | Remainder of a division |
| [remquo](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:remquo) | Remainder and quotient of a division |
| [rint](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:rint) | Round to even |
| [rootn](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:rootn) | Nth root |
| [round](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:round) | Round away from zero |
| [rsRand](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:rsRand) | Pseudo-random number |
| [rsqrt](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:rsqrt) | Reciprocal of a square root |
| [sign](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:sign) | Sign of a value |
| [sin](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:sin) | Sine |
| [sincos](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:sincos) | Sine and cosine |
| [sinh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:sinh) | Hyperbolic sine |
| [sinpi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:sinpi) | Sine of a number multiplied by pi |
| [sqrt](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:sqrt) | Square root |
| [step](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:step) | 0 if less than a value, 0 otherwise |
| [tan](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:tan) | Tangent |
| [tanh](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:tanh) | Hyperbolic tangent |
| [tanpi](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:tanpi) | Tangent of a number multiplied by pi |
| [tgamma](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:tgamma) | Gamma function |
| [trunc](https://developer.android.com/guide/topics/renderscript/reference/rs_math#android_rs:trunc) | Truncates a floating point |

## Vector Math Functions

These functions interpret the input arguments as representation of vectors in
n-dimensional space.

The precision of the mathematical operations on 32 bit floats is affected by the pragmas
rs_fp_relaxed and rs_fp_full. See [Mathematical Constants and Functions](https://developer.android.com/guide/topics/renderscript/reference/rs_math) for details.

Different precision/speed tradeoffs can be achieved by using variants of the common math
functions. Functions with a name starting with

- native_: May have custom hardware implementations with weaker precision. Additionally, subnormal values may be flushed to zero, rounding towards zero may be used, and NaN and infinity input may not be handled correctly.
- fast_: May perform internal computations using 16 bit floats. Additionally, subnormal values may be flushed to zero, and rounding towards zero may be used.

<br />

| Functions ||
|---|---|
| [cross](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:cross) | Cross product of two vectors |
| [distance](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:distance) | Distance between two points |
| [dot](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:dot) | Dot product of two vectors |
| [fast_distance](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:fast_distance) | Approximate distance between two points |
| [fast_length](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:fast_length) | Approximate length of a vector |
| [fast_normalize](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:fast_normalize) | Approximate normalized vector |
| [length](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:length) | Length of a vector |
| [native_distance](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:native_distance) | Approximate distance between two points |
| [native_length](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:native_length) | Approximate length of a vector |
| [native_normalize](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:native_normalize) | Approximately normalize a vector |
| [normalize](https://developer.android.com/guide/topics/renderscript/reference/rs_vector_math#android_rs:normalize) | Normalize a vector |

## Matrix Functions

These functions let you manipulate square matrices of rank 2x2, 3x3, and 4x4.
They are particularly useful for graphical transformations and are compatible
with OpenGL.

We use a zero-based index for rows and columns. E.g. the last element of a
[rs_matrix4x4](https://developer.android.com/guide/topics/renderscript/reference/rs_value_types#android_rs:rs_matrix4x4) is found at (3, 3).

RenderScript uses column-major matrices and column-based vectors. Transforming
a vector is done by postmultiplying the vector, e.g. `(matrix * vector)`,
as provided by [rsMatrixMultiply](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixMultiply)().

To create a transformation matrix that performs two transformations at once,
multiply the two source matrices, with the first transformation as the right
argument. E.g. to create a transformation matrix that applies the
transformation s1 followed by s2, call `rsMatrixLoadMultiply(&combined, &s2, &s1)`.
This derives from `s2 * (s1 * v)`, which is `(s2 * s1) * v`.

We have two style of functions to create transformation matrices:
rsMatrixLoad*Transformation* and rsMatrix*Transformation* . The former
style simply stores the transformation matrix in the first argument. The latter
modifies a pre-existing transformation matrix so that the new transformation
happens first. E.g. if you call [rsMatrixTranslate](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixTranslate)() on a matrix that already
does a scaling, the resulting matrix when applied to a vector will first do the
translation then the scaling.

| Functions ||
|---|---|
| [rsExtractFrustumPlanes](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsExtractFrustumPlanes) | Compute frustum planes |
| [rsIsSphereInFrustum](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsIsSphereInFrustum) | Checks if a sphere is within the frustum planes |
| [rsMatrixGet](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixGet) | Get one element |
| [rsMatrixInverse](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixInverse) | Inverts a matrix in place |
| [rsMatrixInverseTranspose](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixInverseTranspose) | Inverts and transpose a matrix in place |
| [rsMatrixLoad](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixLoad) | Load or copy a matrix |
| [rsMatrixLoadFrustum](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixLoadFrustum) | Load a frustum projection matrix |
| [rsMatrixLoadIdentity](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixLoadIdentity) | Load identity matrix |
| [rsMatrixLoadMultiply](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixLoadMultiply) | Multiply two matrices |
| [rsMatrixLoadOrtho](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixLoadOrtho) | Load an orthographic projection matrix |
| [rsMatrixLoadPerspective](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixLoadPerspective) | Load a perspective projection matrix |
| [rsMatrixLoadRotate](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixLoadRotate) | Load a rotation matrix |
| [rsMatrixLoadScale](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixLoadScale) | Load a scaling matrix |
| [rsMatrixLoadTranslate](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixLoadTranslate) | Load a translation matrix |
| [rsMatrixMultiply](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixMultiply) | Multiply a matrix by a vector or another matrix |
| [rsMatrixRotate](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixRotate) | Apply a rotation to a transformation matrix |
| [rsMatrixScale](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixScale) | Apply a scaling to a transformation matrix |
| [rsMatrixSet](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixSet) | Set one element |
| [rsMatrixTranslate](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixTranslate) | Apply a translation to a transformation matrix |
| [rsMatrixTranspose](https://developer.android.com/guide/topics/renderscript/reference/rs_matrix#android_rs:rsMatrixTranspose) | Transpose a matrix place |

## Quaternion Functions

The following functions manipulate quaternions.

| Functions ||
|---|---|
| [rsQuaternionAdd](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion#android_rs:rsQuaternionAdd) | Add two quaternions |
| [rsQuaternionConjugate](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion#android_rs:rsQuaternionConjugate) | Conjugate a quaternion |
| [rsQuaternionDot](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion#android_rs:rsQuaternionDot) | Dot product of two quaternions |
| [rsQuaternionGetMatrixUnit](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion#android_rs:rsQuaternionGetMatrixUnit) | Get a rotation matrix from a quaternion |
| [rsQuaternionLoadRotate](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion#android_rs:rsQuaternionLoadRotate) | Create a rotation quaternion |
| [rsQuaternionLoadRotateUnit](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion#android_rs:rsQuaternionLoadRotateUnit) | Quaternion that represents a rotation about an arbitrary unit vector |
| [rsQuaternionMultiply](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion#android_rs:rsQuaternionMultiply) | Multiply a quaternion by a scalar or another quaternion |
| [rsQuaternionNormalize](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion#android_rs:rsQuaternionNormalize) | Normalize a quaternion |
| [rsQuaternionSet](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion#android_rs:rsQuaternionSet) | Create a quaternion |
| [rsQuaternionSlerp](https://developer.android.com/guide/topics/renderscript/reference/rs_quaternion#android_rs:rsQuaternionSlerp) | Spherical linear interpolation between two quaternions |

## Atomic Update Functions

To update values shared between multiple threads, use the functions below.
They ensure that the values are atomically updated, i.e. that the memory
reads, the updates, and the memory writes are done in the right order.

These functions are slower than their non-atomic equivalents, so use
them only when synchronization is needed.

Note that in RenderScript, your code is likely to be running in separate
threads even though you did not explicitly create them. The RenderScript
runtime will very often split the execution of one kernel across multiple
threads. Updating globals should be done with atomic functions. If possible,
modify your algorithm to avoid them altogether.

| Functions ||
|---|---|
| [rsAtomicAdd](https://developer.android.com/guide/topics/renderscript/reference/rs_atomic#android_rs:rsAtomicAdd) | Thread-safe addition |
| [rsAtomicAnd](https://developer.android.com/guide/topics/renderscript/reference/rs_atomic#android_rs:rsAtomicAnd) | Thread-safe bitwise and |
| [rsAtomicCas](https://developer.android.com/guide/topics/renderscript/reference/rs_atomic#android_rs:rsAtomicCas) | Thread-safe compare and set |
| [rsAtomicDec](https://developer.android.com/guide/topics/renderscript/reference/rs_atomic#android_rs:rsAtomicDec) | Thread-safe decrement |
| [rsAtomicInc](https://developer.android.com/guide/topics/renderscript/reference/rs_atomic#android_rs:rsAtomicInc) | Thread-safe increment |
| [rsAtomicMax](https://developer.android.com/guide/topics/renderscript/reference/rs_atomic#android_rs:rsAtomicMax) | Thread-safe maximum |
| [rsAtomicMin](https://developer.android.com/guide/topics/renderscript/reference/rs_atomic#android_rs:rsAtomicMin) | Thread-safe minimum |
| [rsAtomicOr](https://developer.android.com/guide/topics/renderscript/reference/rs_atomic#android_rs:rsAtomicOr) | Thread-safe bitwise or |
| [rsAtomicSub](https://developer.android.com/guide/topics/renderscript/reference/rs_atomic#android_rs:rsAtomicSub) | Thread-safe subtraction |
| [rsAtomicXor](https://developer.android.com/guide/topics/renderscript/reference/rs_atomic#android_rs:rsAtomicXor) | Thread-safe bitwise exclusive or |

## Time Functions and Types

The functions below can be used to tell the current clock time and the current
system up time. It is not recommended to call these functions inside of a kernel.

| Types ||
|---|---|
| [rs_time_t](https://developer.android.com/guide/topics/renderscript/reference/rs_time#android_rs:rs_time_t) | Seconds since January 1, 1970 |
| [rs_tm](https://developer.android.com/guide/topics/renderscript/reference/rs_time#android_rs:rs_tm) | Date and time structure |

| Functions ||
|---|---|
| [rsGetDt](https://developer.android.com/guide/topics/renderscript/reference/rs_time#android_rs:rsGetDt) | Elapsed time since last call |
| [rsLocaltime](https://developer.android.com/guide/topics/renderscript/reference/rs_time#android_rs:rsLocaltime) | Convert to local time |
| [rsTime](https://developer.android.com/guide/topics/renderscript/reference/rs_time#android_rs:rsTime) | Seconds since January 1, 1970 |
| [rsUptimeMillis](https://developer.android.com/guide/topics/renderscript/reference/rs_time#android_rs:rsUptimeMillis) | System uptime in milliseconds |
| [rsUptimeNanos](https://developer.android.com/guide/topics/renderscript/reference/rs_time#android_rs:rsUptimeNanos) | System uptime in nanoseconds |

## Allocation Creation Functions

The functions below can be used to create Allocations from a Script.

These functions can be called directly or indirectly from an invokable
function. If some control-flow path can result in a call to these functions
from a RenderScript kernel function, a compiler error will be generated.

| Functions ||
|---|---|
| [rsCreateAllocation](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_create#android_rs:rsCreateAllocation) | Create an rs_allocation object of given Type. |
| [rsCreateElement](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_create#android_rs:rsCreateElement) | Creates an rs_element object of the specified data type |
| [rsCreatePixelElement](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_create#android_rs:rsCreatePixelElement) | Creates an rs_element object of the specified data type and data kind |
| [rsCreateType](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_create#android_rs:rsCreateType) | Creates an rs_type object with the specified Element and shape attributes |
| [rsCreateVectorElement](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_create#android_rs:rsCreateVectorElement) | Creates an rs_element object of the specified data type and vector width |

## Allocation Data Access Functions

The functions below can be used to get and set the cells that comprise
an allocation.

- Individual cells are accessed using the rsGetElementAt\* and [rsSetElementAt](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsSetElementAt) functions.
- Multiple cells can be copied using the rsAllocationCopy\* and rsAllocationV\* functions.
- For getting values through a sampler, use [rsSample](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsSample).

The [rsGetElementAt](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsGetElementAt) and rsSetElement\* functions are somewhat misnamed. They don't get or set elements, which are akin to data types; they get or set cells. Think of them as rsGetCellAt and rsSetCellAt.

<br />

| Functions ||
|---|---|
| [rsAllocationCopy1DRange](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsAllocationCopy1DRange) | Copy consecutive cells between allocations |
| [rsAllocationCopy2DRange](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsAllocationCopy2DRange) | Copy a rectangular region of cells between allocations |
| [rsAllocationVLoadX](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsAllocationVLoadX) | Get a vector from an allocation of scalars |
| [rsAllocationVStoreX](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsAllocationVStoreX) | Store a vector into an allocation of scalars |
| [rsGetElementAt](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsGetElementAt) | Return a cell from an allocation |
| [rsGetElementAtYuv_uchar_U](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsGetElementAtYuv_uchar_U) | Get the U component of an allocation of YUVs |
| [rsGetElementAtYuv_uchar_V](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsGetElementAtYuv_uchar_V) | Get the V component of an allocation of YUVs |
| [rsGetElementAtYuv_uchar_Y](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsGetElementAtYuv_uchar_Y) | Get the Y component of an allocation of YUVs |
| [rsSample](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsSample) | Sample a value from a texture allocation |
| [rsSetElementAt](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsSetElementAt) | Set a cell of an allocation |

## Object Characteristics Functions

The functions below can be used to query the characteristics of an Allocation, Element,
or Sampler object. These objects are created from Java. You can't create them from a
script.

##### Allocations:

<br />

Allocations are the primary method used to pass data to and from RenderScript kernels.

They are a structured collection of cells that can be used to store bitmaps, textures,
arbitrary data points, etc.

This collection of cells may have many dimensions (X, Y, Z, Array0, Array1, Array2, Array3),
faces (for cubemaps), and level of details (for mipmapping).

See the [android.renderscript.Allocation](https://developer.android.com/reference/android/renderscript/Allocation.html) for details on to create Allocations.

##### Elements:

<br />

The term "element" is used a bit ambiguously in RenderScript, as both type information
for the cells of an Allocation and the instantiation of that type. For example:

- [rs_element](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_element) is a handle to a type specification, and
- In functions like [rsGetElementAt](https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data#android_rs:rsGetElementAt)(), "element" means the instantiation of the type, i.e. a cell of an Allocation.

<br />

The functions below let you query the characteristics of the type specification.

An Element can specify a simple data types as found in C, e.g. an integer, float, or
boolean. It can also specify a handle to a RenderScript object. See [rs_data_type](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_data_type) for
a list of basic types.

Elements can specify fixed size vector (of size 2, 3, or 4) versions of the basic types.
Elements can be grouped together into complex Elements, creating the equivalent of
C structure definitions.

Elements can also have a kind, which is semantic information used to interpret pixel
data. See [rs_data_kind](https://developer.android.com/guide/topics/renderscript/reference/rs_object_types#android_rs:rs_data_kind).

When creating Allocations of common elements, you can simply use one of the many predefined
Elements like [F32_2](https://developer.android.com/reference/android/renderscript/Element.html#F32_2(android.renderscript.RenderScript)).

To create complex Elements, use the [Element.Builder](https://developer.android.com/reference/android/renderscript/Element.Builder.html) Java class.

##### Samplers:

<br />

Samplers objects define how Allocations can be read as structure within a kernel.
See [android.renderscript.S](https://developer.android.com/reference/android/renderscript/Sampler.html).

| Functions ||
|---|---|
| [rsAllocationGetDimFaces](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsAllocationGetDimFaces) | Presence of more than one face |
| [rsAllocationGetDimLOD](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsAllocationGetDimLOD) | Presence of levels of detail |
| [rsAllocationGetDimX](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsAllocationGetDimX) | Size of the X dimension |
| [rsAllocationGetDimY](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsAllocationGetDimY) | Size of the Y dimension |
| [rsAllocationGetDimZ](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsAllocationGetDimZ) | Size of the Z dimension |
| [rsAllocationGetElement](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsAllocationGetElement) | Get the object that describes the cell of an Allocation |
| [rsClearObject](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsClearObject) | Release an object |
| [rsElementGetBytesSize](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsElementGetBytesSize) | Size of an Element |
| [rsElementGetDataKind](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsElementGetDataKind) | Kind of an Element |
| [rsElementGetDataType](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsElementGetDataType) | Data type of an Element |
| [rsElementGetSubElement](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsElementGetSubElement) | Sub-element of a complex Element |
| [rsElementGetSubElementArraySize](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsElementGetSubElementArraySize) | Array size of a sub-element of a complex Element |
| [rsElementGetSubElementCount](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsElementGetSubElementCount) | Number of sub-elements |
| [rsElementGetSubElementName](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsElementGetSubElementName) | Name of a sub-element |
| [rsElementGetSubElementNameLength](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsElementGetSubElementNameLength) | Length of the name of a sub-element |
| [rsElementGetSubElementOffsetBytes](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsElementGetSubElementOffsetBytes) | Offset of the instantiated sub-element |
| [rsElementGetVectorSize](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsElementGetVectorSize) | Vector size of the Element |
| [rsIsObject](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsIsObject) | Check for an empty handle |
| [rsSamplerGetAnisotropy](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsSamplerGetAnisotropy) | Anisotropy of the Sampler |
| [rsSamplerGetMagnification](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsSamplerGetMagnification) | Sampler magnification value |
| [rsSamplerGetMinification](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsSamplerGetMinification) | Sampler minification value |
| [rsSamplerGetWrapS](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsSamplerGetWrapS) | Sampler wrap S value |
| [rsSamplerGetWrapT](https://developer.android.com/guide/topics/renderscript/reference/rs_object_info#android_rs:rsSamplerGetWrapT) | Sampler wrap T value |

## Kernel Invocation Functions and Types

The [rsForEach](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsForEach)() function can be used to invoke the root kernel of a script.

The other functions are used to get the characteristics of the invocation of
an executing kernel, like dimensions and current indices. These functions take
a [rs_kernel_context](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rs_kernel_context) as argument.

| Types ||
|---|---|
| [rs_for_each_strategy_t](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rs_for_each_strategy_t) | Suggested cell processing order |
| [rs_kernel](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rs_kernel) | Handle to a kernel function |
| [rs_kernel_context](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rs_kernel_context) | Handle to a kernel invocation context |
| [rs_script_call_t](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rs_script_call_t) | Cell iteration information |

| Functions ||
|---|---|
| [rsForEach](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsForEach) | Launches a kernel |
| [rsForEachInternal](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsForEachInternal) | (Internal API) Launch a kernel in the current Script (with the slot number) |
| [rsForEachWithOptions](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsForEachWithOptions) | Launches a kernel with options |
| [rsGetArray0](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetArray0) | Index in the Array0 dimension for the specified kernel context |
| [rsGetArray1](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetArray1) | Index in the Array1 dimension for the specified kernel context |
| [rsGetArray2](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetArray2) | Index in the Array2 dimension for the specified kernel context |
| [rsGetArray3](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetArray3) | Index in the Array3 dimension for the specified kernel context |
| [rsGetDimArray0](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetDimArray0) | Size of the Array0 dimension for the specified kernel context |
| [rsGetDimArray1](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetDimArray1) | Size of the Array1 dimension for the specified kernel context |
| [rsGetDimArray2](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetDimArray2) | Size of the Array2 dimension for the specified kernel context |
| [rsGetDimArray3](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetDimArray3) | Size of the Array3 dimension for the specified kernel context |
| [rsGetDimHasFaces](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetDimHasFaces) | Presence of more than one face for the specified kernel context |
| [rsGetDimLod](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetDimLod) | Number of levels of detail for the specified kernel context |
| [rsGetDimX](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetDimX) | Size of the X dimension for the specified kernel context |
| [rsGetDimY](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetDimY) | Size of the Y dimension for the specified kernel context |
| [rsGetDimZ](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetDimZ) | Size of the Z dimension for the specified kernel context |
| [rsGetFace](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetFace) | Coordinate of the Face for the specified kernel context |
| [rsGetLod](https://developer.android.com/guide/topics/renderscript/reference/rs_for_each#android_rs:rsGetLod) | Index in the Levels of Detail dimension for the specified kernel context |

## Input/Output Functions

These functions are used to:

- Send information to the Java client, and
- Send the processed allocation or receive the next allocation to process.

<br />

| Functions ||
|---|---|
| [rsAllocationIoReceive](https://developer.android.com/guide/topics/renderscript/reference/rs_io#android_rs:rsAllocationIoReceive) | Receive new content from the queue |
| [rsAllocationIoSend](https://developer.android.com/guide/topics/renderscript/reference/rs_io#android_rs:rsAllocationIoSend) | Send new content to the queue |
| [rsSendToClient](https://developer.android.com/guide/topics/renderscript/reference/rs_io#android_rs:rsSendToClient) | Send a message to the client, non-blocking |
| [rsSendToClientBlocking](https://developer.android.com/guide/topics/renderscript/reference/rs_io#android_rs:rsSendToClientBlocking) | Send a message to the client, blocking |

## Debugging Functions

The functions below are intended to be used during application development.
They should not be used in shipping applications.

| Functions ||
|---|---|
| [rsDebug](https://developer.android.com/guide/topics/renderscript/reference/rs_debug#android_rs:rsDebug) | Log a message and values |

## Graphics Functions and Types

The graphics subsystem of RenderScript was removed at API level 23.