Skip to content

Commit 0fe6feb

Browse files
Robert LyAndroid Git Automerger
authored andcommitted
am b03ce7e: Merge "docs: add fs to rs" into jb-mr1-dev
* commit 'b03ce7eb9fd23f614583cb1f48e7b5194e24602b': docs: add fs to rs
2 parents d60c7a9 + b03ce7e commit 0fe6feb

File tree

1 file changed

+91
-32
lines changed

1 file changed

+91
-32
lines changed

docs/html/guide/topics/renderscript/compute.jd

Lines changed: 91 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ parent.link=index.html
1010

1111
<ol>
1212
<li><a href="#overview">Renderscript System Overview</a></li>
13+
<li><a href="#filterscript">Filterscript</a></li>
1314
<li>
1415
<a href="#creating-renderscript">Creating a Computation Renderscript</a>
15-
1616
<ol>
1717
<li><a href="#creating-rs-file">Creating the Renderscript file</a></li>
18-
1918
<li><a href="#calling">Calling the Renderscript code</a></li>
2019
</ol>
2120
</li>
@@ -111,16 +110,34 @@ code, like with the NDK.</li>
111110
<p>For a more detailed explanation of how all of these layers work together, see
112111
<a href="{@docRoot}guide/topics/renderscript/advanced.html">Advanced Renderscript</a>.<p>
113112

113+
<h2 id="filterscript">Filterscript</h2>
114+
115+
<p>Introduced in Android 4.2 (API Level 17), Filterscript defines a subset of Renderscript
116+
that focuses on image processing operations, such as those
117+
that you would typically write with an OpenGL ES fragment shader. You still write your scripts
118+
using the standard Renderscript runtime APIs, but within stricter
119+
constraints that ensure wider compatibility and improved optimization across
120+
CPUs, GPUs, and DSPs. At compile time, the precompiler evaluates Filterscript files and
121+
applies a more stringent set of warnings and errors than
122+
it does for standard Renderscript files. The following list describes the major constraints
123+
of Filterscript when compared to Renderscript:</p>
124+
125+
<ul>
126+
<li>Inputs and return values of root functions cannot contain pointers. The default root function
127+
signature contains pointers, so you must use the <code>__attribute__((kernel))</code> attribute to declare a custom
128+
root function when using Filterscript.</li>
129+
<li>Built-in types cannot exceed 32-bits.</li>
130+
<li>Filterscript must always use relaxed floating point precision by using the
131+
<code>rs_fp_relaxed</code> pragma.</li>
132+
<li>Filterscript files must end with an <code>.fs</code> extension, instead of an <code>.rs</code> extension.</li>
133+
</ul>
114134

115135
<h2 id="creating-renderscript">Creating a Renderscript</h2>
116136

117-
<p>Renderscripts scale to the amount of
137+
<p>Renderscript scales to the amount of
118138
processing cores available on the device. This is enabled through a function named
119139
<code>rsForEach()</code> (or the <code>forEach_root()</code> method at the Android framework level).
120-
that automatically partitions work across available processing cores on the device.
121-
For now, Renderscript can only take advantage of CPU
122-
cores, but in the future, they can potentially run on other types of processors such as GPUs and
123-
DSPs.</p>
140+
that automatically partitions work across available processing cores on the device.</p>
124141

125142
<p>Implementing a Renderscript involves creating a <code>.rs</code> file that contains
126143
your Renderscript code and calling it at the Android framework level with the
@@ -149,10 +166,9 @@ Every <code>.rs</code> file generally contains the following items:</p>
149166

150167
<li>A pragma declaration (<code>#pragma version(1)</code>) that declares the version of
151168
Renderscript that you are using (1 is the only value for now).</li>
152-
153-
<li><p>A <code>root()</code> function that is the main worker function. The root function is
154-
called by the <code>rsForEach</code> function, which allows the Renderscript code to be called and
155-
executed on multiple cores if they are available. The <code>root()</code> function must return
169+
170+
<li><p>A root function (or kernel) that is the main entry point to your Renderscript.
171+
The default <code>root()</code> function must return
156172
<code>void</code> and accept the following arguments:</p>
157173

158174
<ul>
@@ -172,10 +188,22 @@ Every <code>.rs</code> file generally contains the following items:</p>
172188

173189
<li>The size of the user-defined data.</li>
174190
</ul>
191+
192+
<p>Starting in Android 4.1 (API Level 16), you can choose to define your own root function arguments
193+
without adhering to the default root function signature described previously. In addition,
194+
you can declare multiple root functions in the same Renderscript. To do this, use the <code>__attribute__((kernel))</code>
195+
attribute to define a custom root function. For example, here's a root function
196+
that returns a <code>uchar4</code> and accepts two <code>uint32_t</code> types: </p>
197+
198+
<pre>
199+
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
200+
...
201+
}
202+
</pre>
175203
</li>
176204

177205
<li>An optional <code>init()</code> function. This allows you to do any initialization
178-
before the <code>root()</code> function runs, such as initializing variables. This
206+
before the root function runs, such as initializing variables. This
179207
function runs once and is called automatically when the Renderscript starts, before anything
180208
else in your Renderscript.</li>
181209

@@ -203,6 +231,46 @@ void root(const uchar4 *v_in, uchar4 *v_out) {
203231
}
204232
</pre>
205233

234+
<h4>Setting floating point precision</h4>
235+
<p>You can define the floating point precision required by your compute algorithms. This is useful if you
236+
require less precision than the IEEE 754-2008 standard (used by default). You can define
237+
the floating-point precision level of your script with the following pragmas:</p>
238+
239+
<ul>
240+
<li><code>#pragma rs_fp_full</code> (default if nothing is specified): For apps that
241+
require floating point precision as outlined by the IEEE 754-2008 standard.
242+
</li>
243+
<li><code>#pragma rs_fp_relaxed</code> - For apps that don’t require
244+
strict IEEE 754-2008 compliance and can tolerate less precision. This mode enables
245+
flush-to-zero for denorms and round-towards-zero.
246+
</li>
247+
<li><code>#pragma rs_fp_imprecise</code> - For apps that don’t have stringent precision requirements. This mode enables
248+
everything in <code>rs_fp_relaxed</code> along with the following:
249+
<ul>
250+
<li>Operations resulting in -0.0 can return +0.0 instead.</li>
251+
<li>Operations on INF and NAN are undefined.</li>
252+
</ul>
253+
</li>
254+
</ul>
255+
256+
<h4>Script intrinsics</h4>
257+
<p>Renderscript adds support for a set of script intrinsics, which are pre-implemented
258+
filtering primitives that reduce the amount of
259+
code that you need to write. They also are implemented to ensure that your app gets the
260+
maximum performance gain possible.</p>
261+
262+
<p>
263+
Intrinsics are available for the following:
264+
<ul>
265+
<li>{@link android.renderscript.ScriptIntrinsicBlend Blends}</li>
266+
<li>{@link android.renderscript.ScriptIntrinsicBlur Blur}</li>
267+
<li>{@link android.renderscript.ScriptIntrinsicColorMatrix Color matrix}</li>
268+
<li>{@link android.renderscript.ScriptIntrinsicConvolve3x3 3x3 convolve}</li>
269+
<li>{@link android.renderscript.ScriptIntrinsicConvolve5x5 5x5 convolve}</li>
270+
<li>{@link android.renderscript.ScriptIntrinsicLUT Per-channel lookup table}</li>
271+
<li>{@link android.renderscript.ScriptIntrinsicYuvToRGB Converting an Android YUV buffer to RGB}</li>
272+
</ul>
273+
206274
<h3 id="calling">Calling the Renderscript code</h3>
207275

208276
<p>You can call the Renderscript from your Android framework code by
@@ -317,24 +385,15 @@ declared previously. Passing a pointer to a struct and the size of the struct to
317385
is optional, but useful if your Renderscript requires additional information other than
318386
the necessary memory allocations.</p>
319387

320-
<h3>Setting floating point precision</h3>
321-
<p>You can define the floating point precision required by your compute algorithms. This is useful if you
322-
require less precision than the IEEE 754-2008 standard (used by default). You can define
323-
the floating-point precision level of your script with the following pragmas:</p>
324388

325-
<ul>
326-
<li><code>#pragma rs_fp_full</code> (default if nothing is specified): For apps that
327-
require floating point precision as outlined by the IEEE 754-2008 standard.
328-
</li>
329-
<li><code>#pragma rs_fp_relaxed</code> - For apps that don’t require
330-
strict IEEE 754-2008 compliance and can tolerate less precision. This mode enables
331-
flush-to-zero for denorms and round-towards-zero.
332-
</li>
333-
<li><code>#pragma rs_fp_imprecise</code> - For apps that don’t have stringent precision requirements. This mode enables
334-
everything in <code>rs_fp_relaxed</code> along with the following:
335-
<ul>
336-
<li>Operations resulting in -0.0 can return +0.0 instead.</li>
337-
<li>Operations on INF and NAN are undefined.</li>
338-
</ul>
339-
</li>
340-
</ul>
389+
<h4>Script groups</h4>
390+
391+
<p>You can group Renderscript scripts together and execute them all with a single call as though
392+
they were part of a single script. This allows Renderscript to optimize execution of the scripts
393+
in ways that it could not do if the scripts were executed individually.</p>
394+
395+
<p>To build a script groupm, use the {@link android.renderscript.ScriptGroup.Builder} class to create a {@link android.renderscript.ScriptGroup}
396+
defining the operations. At execution time, Renderscript optimizes the run order and the connections between these
397+
operations for best performance.
398+
399+
<p class="note"><strong>Important:</strong> The script group must be a direct acyclic graph for this feature to work.</p>

0 commit comments

Comments
 (0)