Skip to content

Most visited

Recently visited

navigation

RenderScript Kernel Invocation Functions and Types

Overview

The 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 as argument.

Summary

Types
rs_for_each_strategy_t Suggested cell processing order
rs_kernel_context Handle to a kernel invocation context
rs_script_call_t Cell iteration information
Functions
rsForEach Invoke the root kernel of a script
rsGetArray0 Index in the Array0 dimension for the specified kernel context
rsGetArray1 Index in the Array1 dimension for the specified kernel context
rsGetArray2 Index in the Array2 dimension for the specified kernel context
rsGetArray3 Index in the Array3 dimension for the specified kernel context
rsGetDimArray0 Size of the Array0 dimension for the specified kernel context
rsGetDimArray1 Size of the Array1 dimension for the specified kernel context
rsGetDimArray2 Size of the Array2 dimension for the specified kernel context
rsGetDimArray3 Size of the Array3 dimension for the specified kernel context
rsGetDimHasFaces Presence of more than one face for the specified kernel context
rsGetDimLod Number of levels of detail for the specified kernel context
rsGetDimX Size of the X dimension for the specified kernel context
rsGetDimY Size of the Y dimension for the specified kernel context
rsGetDimZ Size of the Z dimension for the specified kernel context
rsGetFace Coordinate of the Face for the specified kernel context
rsGetLod Index in the Levels of Detail dimension for the specified kernel context

Types

rs_for_each_strategy_t : Suggested cell processing order

An enum with the following values:     

RS_FOR_EACH_STRATEGY_SERIAL = 0Prefer contiguous memory regions.
RS_FOR_EACH_STRATEGY_DONT_CARE = 1No prefrences.
RS_FOR_EACH_STRATEGY_DST_LINEAR = 2Prefer DST.
RS_FOR_EACH_STRATEGY_TILE_SMALL = 3Prefer processing small rectangular regions.
RS_FOR_EACH_STRATEGY_TILE_MEDIUM = 4Prefer processing medium rectangular regions.
RS_FOR_EACH_STRATEGY_TILE_LARGE = 5Prefer processing large rectangular regions.

This type is used to suggest how the invoked kernel should iterate over the cells of the allocations. This is a hint only. Implementations may not follow the suggestion.

This specification can help the caching behavior of the running kernel, e.g. the cache locality when the processing is distributed over multiple cores.

rs_kernel_context : Handle to a kernel invocation context

A typedef of: const struct rs_kernel_context_t *     Added in API level 23

The kernel context contains common characteristics of the allocations being iterated over, like dimensions. It also contains rarely used indices of the currently processed cell, like the Array0 index or the current level of detail.

You can access the kernel context by adding a special parameter named "context" of type rs_kernel_context to your kernel function. See rsGetDimX() and rsGetArray0() for examples.

rs_script_call_t : Cell iteration information

A structure with the following fields:     

rs_for_each_strategy_t strategyCurrently ignored. In the future, will be suggested cell iteration strategy.
uint32_t xStartStarting index in the X dimension.
uint32_t xEndEnding index (exclusive) in the X dimension.
uint32_t yStartStarting index in the Y dimension.
uint32_t yEndEnding index (exclusive) in the Y dimension.
uint32_t zStartStarting index in the Z dimension.
uint32_t zEndEnding index (exclusive) in the Z dimension.
uint32_t arrayStartStarting index in the Array0 dimension.
uint32_t arrayEndEnding index (exclusive) in the Array0 dimension.
uint32_t array1StartStarting index in the Array1 dimension.
uint32_t array1EndEnding index (exclusive) in the Array1 dimension.
uint32_t array2StartStarting index in the Array2 dimension.
uint32_t array2EndEnding index (exclusive) in the Array2 dimension.
uint32_t array3StartStarting index in the Array3 dimension.
uint32_t array3EndEnding index (exclusive) in the Array3 dimension.

This structure is used to provide iteration information to a rsForEach call. It is currently used to restrict processing to a subset of cells. In future versions, it will also be used to provide hint on how to best iterate over the cells.

The Start fields are inclusive and the End fields are exclusive. E.g. to iterate over cells 4, 5, 6, and 7 in the X dimension, set xStart to 4 and xEnd to 8.

Functions

rsForEach : Invoke the root kernel of a script

void rsForEach(rs_script script, rs_allocation input, rs_allocation output); Added in API level 14
void rsForEach(rs_script script, rs_allocation input, rs_allocation output, const void* usrData); Removed from API level 14 and higher
void rsForEach(rs_script script, rs_allocation input, rs_allocation output, const void* usrData, const rs_script_call_t* sc); Removed from API level 14 and higher
void rsForEach(rs_script script, rs_allocation input, rs_allocation output, const void* usrData, size_t usrDataLen); API level 14 - 20
void rsForEach(rs_script script, rs_allocation input, rs_allocation output, const void* usrData, size_t usrDataLen, const rs_script_call_t* sc); API level 14 - 20
Parameters
scriptScript to call.
inputAllocation to source data from.
outputAllocation to write date into.
usrDataUser defined data to pass to the script. May be NULL.
scExtra control information used to select a sub-region of the allocation to be processed or suggest a walking strategy. May be NULL.
usrDataLenSize of the userData structure. This will be used to perform a shallow copy of the data if necessary.

Invoke the kernel named "root" of the specified script. Like other kernels, this root() function will be invoked repeatedly over the cells of the specificed allocation, filling the output allocation with the results.

When rsForEach is called, the root script is launched immediately. rsForEach returns only when the script has completed and the output allocation is ready to use.

The rs_script argument is typically initialized using a global variable set from Java.

The kernel can be invoked with just an input allocation or just an output allocation. This can be done by defining an rs_allocation variable and not initializing it. E.g.
rs_script gCustomScript;
void specializedProcessing(rs_allocation in) {
  rs_allocation ignoredOut;
  rsForEach(gCustomScript, in, ignoredOut);
}

If both input and output allocations are specified, they must have the same dimensions.

rsGetArray0 : Index in the Array0 dimension for the specified kernel context

uint32_t rsGetArray0(rs_kernel_context context); Added in API level 23

Returns the index in the Array0 dimension of the cell being processed, as specified by the supplied kernel context.

The kernel context contains common characteristics of the allocations being iterated over and rarely used indices, like the Array0 index.

You can access the kernel context by adding a special parameter named "context" of type rs_kernel_context to your kernel function. E.g.
short RS_KERNEL myKernel(short value, uint32_t x, rs_kernel_context context) {
  // The current index in the common x, y, z dimensions are accessed by
  // adding these variables as arguments. For the more rarely used indices
  // to the other dimensions, extract them from the kernel context:
  uint32_t index_a0 = rsGetArray0(context);
  //...
}

This function returns 0 if the Array0 dimension is not present.

rsGetArray1 : Index in the Array1 dimension for the specified kernel context

uint32_t rsGetArray1(rs_kernel_context context); Added in API level 23

Returns the index in the Array1 dimension of the cell being processed, as specified by the supplied kernel context. See rsGetArray0() for an explanation of the context.

Returns 0 if the Array1 dimension is not present.

rsGetArray2 : Index in the Array2 dimension for the specified kernel context

uint32_t rsGetArray2(rs_kernel_context context); Added in API level 23

Returns the index in the Array2 dimension of the cell being processed, as specified by the supplied kernel context. See rsGetArray0() for an explanation of the context.

Returns 0 if the Array2 dimension is not present.

rsGetArray3 : Index in the Array3 dimension for the specified kernel context

uint32_t rsGetArray3(rs_kernel_context context); Added in API level 23

Returns the index in the Array3 dimension of the cell being processed, as specified by the supplied kernel context. See rsGetArray0() for an explanation of the context.

Returns 0 if the Array3 dimension is not present.

rsGetDimArray0 : Size of the Array0 dimension for the specified kernel context

uint32_t rsGetDimArray0(rs_kernel_context context); Added in API level 23

Returns the size of the Array0 dimension for the specified kernel context. See rsGetDimX() for an explanation of the context.

Returns 0 if the Array0 dimension is not present.

rsGetDimArray1 : Size of the Array1 dimension for the specified kernel context

uint32_t rsGetDimArray1(rs_kernel_context context); Added in API level 23

Returns the size of the Array1 dimension for the specified kernel context. See rsGetDimX() for an explanation of the context.

Returns 0 if the Array1 dimension is not present.

rsGetDimArray2 : Size of the Array2 dimension for the specified kernel context

uint32_t rsGetDimArray2(rs_kernel_context context); Added in API level 23

Returns the size of the Array2 dimension for the specified kernel context. See rsGetDimX() for an explanation of the context.

Returns 0 if the Array2 dimension is not present.

rsGetDimArray3 : Size of the Array3 dimension for the specified kernel context

uint32_t rsGetDimArray3(rs_kernel_context context); Added in API level 23

Returns the size of the Array3 dimension for the specified kernel context. See rsGetDimX() for an explanation of the context.

Returns 0 if the Array3 dimension is not present.

rsGetDimHasFaces : Presence of more than one face for the specified kernel context

bool rsGetDimHasFaces(rs_kernel_context context); Added in API level 23
Returns
Returns true if more than one face is present, false otherwise.

If the kernel is iterating over a cubemap, this function returns true if there's more than one face present. In all other cases, it returns false. See rsGetDimX() for an explanation of the context.

rsAllocationGetDimFaces() is similar but returns 0 or 1 instead of a bool.

rsGetDimLod : Number of levels of detail for the specified kernel context

uint32_t rsGetDimLod(rs_kernel_context context); Added in API level 23

Returns the number of levels of detail for the specified kernel context. This is useful for mipmaps. See rsGetDimX() for an explanation of the context.

Returns 0 if Level of Detail is not used.

rsAllocationGetDimLOD() is similar but returns 0 or 1 instead the actual number of levels.

rsGetDimX : Size of the X dimension for the specified kernel context

uint32_t rsGetDimX(rs_kernel_context context); Added in API level 23

Returns the size of the X dimension for the specified kernel context.

The kernel context contains common characteristics of the allocations being iterated over and rarely used indices, like the Array0 index.

You can access it by adding a special parameter named "context" of type rs_kernel_context to your kernel function. E.g.
int4 RS_KERNEL myKernel(int4 value, rs_kernel_context context) {
  uint32_t size = rsGetDimX(context); //...

To get the dimension of specific allocation, use rsAllocationGetDimX().

rsGetDimY : Size of the Y dimension for the specified kernel context

uint32_t rsGetDimY(rs_kernel_context context); Added in API level 23

Returns the size of the X dimension for the specified kernel context. See rsGetDimX() for an explanation of the context.

Returns 0 if the Y dimension is not present.

To get the dimension of specific allocation, use rsAllocationGetDimY().

rsGetDimZ : Size of the Z dimension for the specified kernel context

uint32_t rsGetDimZ(rs_kernel_context context); Added in API level 23

Returns the size of the Z dimension for the specified kernel context. See rsGetDimX() for an explanation of the context.

Returns 0 if the Z dimension is not present.

To get the dimension of specific allocation, use rsAllocationGetDimZ().

rsGetFace : Coordinate of the Face for the specified kernel context

Returns the face on which the cell being processed is found, as specified by the supplied kernel context. See rsGetArray0() for an explanation of the context.

Returns RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X if the face dimension is not present.

rsGetLod : Index in the Levels of Detail dimension for the specified kernel context

uint32_t rsGetLod(rs_kernel_context context); Added in API level 23

Returns the index in the Levels of Detail dimension of the cell being processed, as specified by the supplied kernel context. See rsGetArray0() for an explanation of the context.

Returns 0 if the Levels of Detail dimension is not present.

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.