Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 1 | page.title=RenderScript |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 2 | parent.title=Computation |
| 3 | parent.link=index.html |
| 4 | |
| 5 | @jd:body |
| 6 | |
| 7 | <div id="qv-wrapper"> |
| 8 | <div id="qv"> |
| 9 | <h2>In this document</h2> |
| 10 | |
| 11 | <ol> |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 12 | <li><a href="#writing-an-rs-kernel">Writing a RenderScript Kernel</a></li> |
Joe Fernandez | 38f8b73 | 2013-09-18 11:54:48 -0700 | [diff] [blame] | 13 | <li><a href="#access-rs-apis">Accessing RenderScript APIs</a> |
Joe Fernandez | 0edad69 | 2013-09-13 12:40:56 -0700 | [diff] [blame] | 14 | <ol> |
| 15 | <li><a href="#ide-setup">Setting Up Your Development Environment</a></li> |
| 16 | </ol> |
| 17 | </li> |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 18 | <li><a href="#using-rs-from-java">Using RenderScript from Java Code</a></li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 19 | </ol> |
| 20 | |
| 21 | <h2>Related Samples</h2> |
| 22 | |
| 23 | <ol> |
| 24 | <li><a href="{@docRoot}resources/samples/RenderScript/HelloCompute/index.html">Hello |
| 25 | Compute</a></li> |
| 26 | </ol> |
| 27 | </div> |
| 28 | </div> |
| 29 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 30 | <p>RenderScript is a framework for running computationally intensive tasks at high performance on |
| 31 | Android. RenderScript is primarily oriented for use with data-parallel computation, although serial |
| 32 | computationally intensive workloads can benefit as well. The RenderScript runtime will parallelize |
| 33 | work across all processors available on a device, such as multi-core CPUs, GPUs, or DSPs, allowing |
| 34 | you to focus on expressing algorithms rather than scheduling work or load balancing. RenderScript is |
| 35 | especially useful for applications performing image processing, computational photography, or |
| 36 | computer vision.</p> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 37 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 38 | <p>To begin with RenderScript, there are two main concepts you should understand:</p> |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 39 | <ul> |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 40 | |
| 41 | <li>High-performance compute kernels are written in a C99-derived language.</li> |
| 42 | |
| 43 | <li>A Java API is used for managing the lifetime of RenderScript resources and controlling kernel |
| 44 | execution.</li> |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 45 | </ul> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 46 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 47 | <h2 id="writing-an-rs-kernel">Writing a RenderScript Kernel</h2> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 48 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 49 | <p>A RenderScript kernel typically resides in a <code>.rs</code> file in the |
| 50 | <code><project_root>/src/</code> directory; each <code>.rs</code> file is called a |
| 51 | script. Every script contains its own set of kernels, functions, and variables. A script can |
| 52 | contain:</p> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 53 | |
| 54 | <ul> |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 55 | <li>A pragma declaration (<code>#pragma version(1)</code>) that declares the version of the |
| 56 | RenderScript kernel language used in this script. Currently, 1 is the only valid value.</li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 57 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 58 | <li>A pragma declaration (<code>#pragma rs java_package_name(com.example.app)</code>) that |
Stephen Hines | 7f75eaa | 2014-01-30 19:43:20 -0800 | [diff] [blame] | 59 | declares the package name of the Java classes reflected from this script. |
| 60 | Note that your .rs file must be part of your application package, and not in a |
| 61 | library project.</li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 62 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 63 | <li>Some number of invokable functions. An invokable function is a single-threaded RenderScript |
| 64 | function that you can call from your Java code with arbitrary arguments. These are often useful for |
| 65 | initial setup or serial computations within a larger processing pipeline.</li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 66 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 67 | <li>Some number of script globals. A script global is equivalent to a global variable in C. You can |
| 68 | access script globals from Java code, and these are often used for parameter passing to RenderScript |
| 69 | kernels.</li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 70 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 71 | <li>Some number of compute kernels. A kernel is a parallel function that executes across every |
| 72 | {@link android.renderscript.Element} within an {@link android.renderscript.Allocation}. |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 73 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 74 | <p>A simple kernel may look like the following:</p> |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 75 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 76 | <pre>uchar4 __attribute__((kernel)) invert(uchar4 in, uint32_t x, uint32_t y) { |
| 77 | uchar4 out = in; |
| 78 | out.r = 255 - in.r; |
| 79 | out.g = 255 - in.g; |
| 80 | out.b = 255 - in.b; |
| 81 | return out; |
| 82 | }</pre> |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 83 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 84 | <p>In most respects, this is identical to a standard C function. The first notable feature is the |
| 85 | <code>__attribute__((kernel))</code> applied to the function prototype. This denotes that the |
| 86 | function is a RenderScript kernel instead of an invokable function. The next feature is the |
| 87 | <code>in</code> argument and its type. In a RenderScript kernel, this is a special argument that is |
| 88 | automatically filled in based on the input {@link android.renderscript.Allocation} passed to the |
| 89 | kernel launch. By default, the kernel is run across an entire {@link |
| 90 | android.renderscript.Allocation}, with one execution of the kernel body per {@link |
| 91 | android.renderscript.Element} in the {@link android.renderscript.Allocation}. The third notable |
| 92 | feature is the return type of the kernel. The value returned from the kernel is automatically |
| 93 | written to the appropriate location in the output {@link android.renderscript.Allocation}. The |
| 94 | RenderScript runtime checks to ensure that the {@link android.renderscript.Element} types of the |
| 95 | input and output Allocations match the kernel's prototype; if they do not match, an exception is |
| 96 | thrown.</p> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 97 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 98 | <p>A kernel may have an input {@link android.renderscript.Allocation}, an output {@link |
| 99 | android.renderscript.Allocation}, or both. A kernel may not have more than one input or one output |
| 100 | {@link android.renderscript.Allocation}. If more than one input or output is required, those objects |
| 101 | should be bound to <code>rs_allocation</code> script globals and accessed from a kernel or invokable |
| 102 | function via <code>rsGetElementAt_<em>type</em>()</code> or |
| 103 | <code>rsSetElementAt_<em>type</em>()</code>.</p> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 104 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 105 | <p>A kernel may access the coordinates of the current execution using the <code>x</code>, |
| 106 | <code>y</code>, and <code>z</code> arguments. These arguments are optional, but the type of the |
| 107 | coordinate arguments must be <code>uint32_t</code>.</p></li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 108 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 109 | <li>An optional <code>init()</code> function. An <code>init()</code> function is a special type of |
| 110 | invokable function that is run when the script is first instantiated. This allows for some |
| 111 | computation to occur automatically at script creation.</li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 112 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 113 | <li>Some number of static script globals and functions. A static script global is equivalent to a |
| 114 | script global except that it cannot be set from Java code. A static function is a standard C |
| 115 | function that can be called from any kernel or invokable function in the script but is not exposed |
| 116 | to the Java API. If a script global or function does not need to be called from Java code, it is |
| 117 | highly recommended that those be declared <code>static</code>.</li> </ul> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 118 | |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 119 | <h4>Setting floating point precision</h4> |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 120 | |
| 121 | <p>You can control the required level of floating point precision in a script. This is useful if |
| 122 | full IEEE 754-2008 standard (used by default) is not required. The following pragmas can set a |
| 123 | different level of floating point precision:</p> |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 124 | |
| 125 | <ul> |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 126 | |
| 127 | <li><code>#pragma rs_fp_full</code> (default if nothing is specified): For apps that require |
| 128 | floating point precision as outlined by the IEEE 754-2008 standard. |
| 129 | |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 130 | </li> |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 131 | |
| 132 | <li><code>#pragma rs_fp_relaxed</code> - For apps that don’t require strict IEEE 754-2008 |
| 133 | compliance and can tolerate less precision. This mode enables flush-to-zero for denorms and |
| 134 | round-towards-zero. |
| 135 | |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 136 | </li> |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 137 | |
| 138 | <li><code>#pragma rs_fp_imprecise</code> - For apps that don’t have stringent precision |
| 139 | requirements. This mode enables everything in <code>rs_fp_relaxed</code> along with the |
| 140 | following: |
| 141 | |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 142 | <ul> |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 143 | |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 144 | <li>Operations resulting in -0.0 can return +0.0 instead.</li> |
| 145 | <li>Operations on INF and NAN are undefined.</li> |
| 146 | </ul> |
| 147 | </li> |
| 148 | </ul> |
| 149 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 150 | <p>Most applications can use <code>rs_fp_relaxed</code> without any side effects. This may be very |
| 151 | beneficial on some architectures due to additional optimizations only available with relaxed |
| 152 | precision (such as SIMD CPU instructions).</p> |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 153 | |
Joe Fernandez | 0edad69 | 2013-09-13 12:40:56 -0700 | [diff] [blame] | 154 | |
Joe Fernandez | 38f8b73 | 2013-09-18 11:54:48 -0700 | [diff] [blame] | 155 | <h2 id="access-rs-apis">Accessing RenderScript APIs</h2> |
Joe Fernandez | 0edad69 | 2013-09-13 12:40:56 -0700 | [diff] [blame] | 156 | |
Joe Fernandez | 38f8b73 | 2013-09-18 11:54:48 -0700 | [diff] [blame] | 157 | <p>When developing an Android application that uses RenderScript, you can access its API in |
| 158 | one of two ways:</p> |
| 159 | |
| 160 | <ul> |
| 161 | <li><strong>{@link android.renderscript}</strong> - The APIs in this class package are |
| 162 | available on devices running Android 3.0 (API level 11) and higher. These are the original APIs |
| 163 | for RenderScript and are not currently being updated.</li> |
| 164 | <li><strong>{@link android.support.v8.renderscript}</strong> - The APIs in this package are |
| 165 | available through a <a href="{@docRoot}tools/support-library/features.html#v8">Support |
| 166 | Library</a>, which allows you to use them on devices running Android 2.2 (API level 8) and |
| 167 | higher.</li> |
| 168 | </ul> |
Joe Fernandez | 0edad69 | 2013-09-13 12:40:56 -0700 | [diff] [blame] | 169 | |
| 170 | <p>We strongly recommend using the Support Library APIs for accessing RenderScript because they |
| 171 | include the latest improvements to the RenderScript compute framework and provide a wider range |
Joe Fernandez | 38f8b73 | 2013-09-18 11:54:48 -0700 | [diff] [blame] | 172 | of device compatibility.</p> |
Joe Fernandez | 0edad69 | 2013-09-13 12:40:56 -0700 | [diff] [blame] | 173 | |
| 174 | |
| 175 | <h3 id="ide-setup">Using the RenderScript Support Library APIs</h3> |
| 176 | |
| 177 | <p>In order to use the Support Library RenderScript APIs, you must configure your development |
| 178 | environment to be able to access them. The following Android SDK tools are required for using |
| 179 | these APIs:</p> |
| 180 | |
| 181 | <ul> |
| 182 | <li>Android SDK Tools revision 22.2 or higher</li> |
| 183 | <li>Android SDK Build-tools revision 18.1.0 or higher</li> |
| 184 | </ul> |
| 185 | |
| 186 | <p>You can check and update the installed version of these tools in the |
| 187 | <a href="{@docRoot}tools/help/sdk-manager.html">Android SDK Manager</a>.</p> |
| 188 | |
| 189 | <p class="note"> |
| 190 | <strong>Note:</strong> Use of Support Library RenderScript APIs is not currently supported with |
| 191 | Android Studio or Gradle-based builds. |
| 192 | </p> |
| 193 | |
| 194 | <p>To use the Support Library RenderScript APIs in Eclipse:</p> |
| 195 | |
| 196 | <ol> |
| 197 | <li>Make sure you have the required Android SDK version and Build Tools version installed.</li> |
| 198 | <li>Open the {@code project.properties} file in the root folder of your application project.</li> |
| 199 | <li>Add the following lines to the file: |
| 200 | <pre> |
| 201 | renderscript.target=18 |
| 202 | renderscript.support.mode=true |
| 203 | sdk.buildtools=18.1.0 |
| 204 | </pre> |
| 205 | </li> |
| 206 | <li>In your application classes that use RenderScript, add an import for the Support Library |
| 207 | classes: |
| 208 | <pre> |
| 209 | import android.support.v8.renderscript.*; |
| 210 | </pre> |
| 211 | </li> |
| 212 | </ol> |
| 213 | |
| 214 | <p>The {@code project.properties} settings listed above control specific behavior in the Android |
| 215 | build process:</p> |
| 216 | |
| 217 | <ul> |
| 218 | <li>{@code renderscript.target} - Specifies the bytecode version to be generated. We |
| 219 | recommend you set this value the highest available API level and set {@code |
| 220 | renderscript.support.mode} to {@code true}. Valid values for this setting are any integer value |
| 221 | from 11 to the most recently released API level. If your minimum SDK version specified in your |
| 222 | application manifest is set to a higher value, this value is ignored and the target value is set |
| 223 | to the minimum SDK version.</li> |
| 224 | <li>{@code renderscript.support.mode} - Specifies that the generated bytecode should fall |
| 225 | back to a compatible version if the device it is running on does not support the target version. |
| 226 | </li> |
| 227 | <li>{@code sdk.buildtools} - The version of the Android SDK build tools to use. This value |
Joe Fernandez | 38f8b73 | 2013-09-18 11:54:48 -0700 | [diff] [blame] | 228 | should be set to {@code 18.1.0} or higher. If this option is not specified, the highest |
| 229 | installed build tools version is used. You should always set this value to ensure the |
| 230 | consistency of builds across development machines with different configurations.</li> |
Joe Fernandez | 0edad69 | 2013-09-13 12:40:56 -0700 | [diff] [blame] | 231 | </ul> |
| 232 | |
| 233 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 234 | <h2 id="using-rs-from-java">Using RenderScript from Java Code</h2> |
| 235 | |
Joe Fernandez | 0edad69 | 2013-09-13 12:40:56 -0700 | [diff] [blame] | 236 | <p>Using RenderScript from Java code relies on the API classes located in the |
| 237 | {@link android.renderscript} or the {@link android.support.v8.renderscript} package. Most |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 238 | applications follow the same basic usage patterns:</p> |
| 239 | |
| 240 | <ol> |
| 241 | |
| 242 | <li><strong>Initialize a RenderScript context.</strong> The {@link |
| 243 | android.renderscript.RenderScript} context, created with {@link |
| 244 | android.renderscript.RenderScript#create}, ensures that RenderScript can be used and provides an |
| 245 | object to control the lifetime of all subsequent RenderScript objects. You should consider context |
| 246 | creation to be a potentially long-running operation, since it may create resources on different |
| 247 | pieces of hardware; it should not be in an application's critical path if at all |
| 248 | possible. Typically, an application will have only a single RenderScript context at a time.</li> |
| 249 | |
| 250 | <li><strong>Create at least one {@link android.renderscript.Allocation} to be passed to a |
| 251 | script.</strong> An {@link android.renderscript.Allocation} is a RenderScript object that provides |
| 252 | storage for a fixed amount of data. Kernels in scripts take {@link android.renderscript.Allocation} |
| 253 | objects as their input and output, and {@link android.renderscript.Allocation} objects can be |
| 254 | accessed in kernels using <code>rsGetElementAt_<em>type</em>()</code> and |
| 255 | <code>rsSetElementAt_<em>type</em>()</code> when bound as script globals. {@link |
| 256 | android.renderscript.Allocation} objects allow arrays to be passed from Java code to RenderScript |
| 257 | code and vice-versa. {@link android.renderscript.Allocation} objects are typically created using |
| 258 | {@link android.renderscript.Allocation#createTyped} or {@link |
| 259 | android.renderscript.Allocation#createFromBitmap}.</li> |
| 260 | |
| 261 | <li><strong>Create whatever scripts are necessary.</strong> There are two types of scripts available |
| 262 | to you when using RenderScript: |
| 263 | |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 264 | <ul> |
Robert Ly | 3419e07 | 2012-11-12 19:42:52 -0800 | [diff] [blame] | 265 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 266 | <li><strong>ScriptC</strong>: These are the user-defined scripts as described in <a |
| 267 | href="#writing-an-rs-kernel">Writing a RenderScript Kernel</a> above. Every script has a Java class |
| 268 | reflected by the RenderScript compiler in order to make it easy to access the script from Java code; |
| 269 | this class will have the name <code>ScriptC_<em>filename</em></code>. For example, if the kernel |
| 270 | above was located in <code>invert.rs</code> and a RenderScript context was already located in |
| 271 | <code>mRS</code>, the Java code to instantiate the script would be: |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 272 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 273 | <pre>ScriptC_invert invert = new ScriptC_invert(mRenderScript);</pre></li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 274 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 275 | <li><strong>ScriptIntrinsic</strong>: These are built-in RenderScript kernels for common operations, |
| 276 | such as Gaussian blur, convolution, and image blending. For more information, see the subclasses of |
| 277 | {@link android.renderscript.ScriptIntrinsic}.</li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 278 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 279 | </ul></li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 280 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 281 | <li><strong>Populate Allocations with data.</strong> Except for Allocations created with {@link |
| 282 | android.renderscript#createFromBitmap}, an Allocation will be populated with empty data when it is |
| 283 | first created. To populate an Allocation, use one of the <code>copy</code> methods in {@link |
| 284 | android.renderscript.Allocation}.</li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 285 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 286 | <li><strong>Set any necessary script globals.</strong> Globals may be set using methods in the same |
| 287 | <code>ScriptC_<em>filename</em></code> class with methods named |
| 288 | <code>set_<em>globalname</em></code>. For example, in order to set an <code>int</code> named |
| 289 | <code>elements</code>, use the Java method <code>set_elements(int)</code>. RenderScript objects can |
| 290 | also be set in kernels; for example, the <code>rs_allocation</code> variable named |
| 291 | <code>lookup</code> can be set with the method <code>set_lookup(Allocation)</code>.</li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 292 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 293 | <li><strong>Launch the appropriate kernels.</strong> Methods to launch a given kernel will be |
| 294 | reflected in the same <code>ScriptC_<em>filename</em></code> class with methods named |
| 295 | <code>forEach_<em>kernelname</em>()</code>. These launches are asynchronous, and launches will be |
| 296 | serialized in the order in which they are launched. Depending on the arguments to the kernel, the |
| 297 | method will take either one or two Allocations. By default, a kernel will execute over the entire |
| 298 | input or output Allocation; to execute over a subset of that Allocation, pass an appropriate {@link |
| 299 | android.renderscript.Script.LaunchOptions} as the last argument to the <code>forEach</code> method. |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 300 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 301 | <p>Invoked functions can be launched using the <code>invoke_<em>functionname</em></code> methods |
| 302 | reflected in the same <code>ScriptC_<em>filename</em></code> class.</p></li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 303 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 304 | <li><strong>Copy data out of {@link android.renderscript.Allocation} objects.</strong> In order to |
| 305 | access data from an {@link android.renderscript.Allocation} from Java code, that data must be copied |
| 306 | back to Java buffers using one of the <code>copy</code> methods in {@link |
| 307 | android.renderscript.Allocation}. These functions will synchronize with asynchronous kernel and |
| 308 | function launches as necessary.</li> |
Robert Ly | 864090e | 2012-06-17 18:22:17 -0700 | [diff] [blame] | 309 | |
Tim Murray | 015d268 | 2013-05-30 12:34:40 -0700 | [diff] [blame] | 310 | <li><strong>Tear down the RenderScript context.</strong> The RenderScript context can be destroyed |
| 311 | with {@link android.renderscript.RenderScript#destroy} or by allowing the RenderScript context |
| 312 | object to be garbage collected. This will cause any further use of any object belonging to that |
Stephen Hines | 7f75eaa | 2014-01-30 19:43:20 -0800 | [diff] [blame] | 313 | context to throw an exception.</li> </ol> |