From 864090eeaa5241f9fcf17420a3d0123c95052b96 Mon Sep 17 00:00:00 2001 From: Robert Ly Date: Sun, 17 Jun 2012 18:22:17 -0700 Subject: [PATCH] docs: remove graphics rs docs and restructure existing docs Change-Id: I8603c827095143327053e8eba855177ec466a948 --- docs/html/guide/guide_toc.cs | 28 ++-- .../index.jd => renderscript/advanced.jd} | 122 +++----------- .../topics/{graphics => }/renderscript/compute.jd | 185 +++++++++++++++------ docs/html/guide/topics/renderscript/index.jd | 31 ++++ .../{graphics => }/renderscript/reference.jd | 3 + 5 files changed, 208 insertions(+), 161 deletions(-) rename docs/html/guide/topics/{graphics/renderscript/index.jd => renderscript/advanced.jd} (84%) rename docs/html/guide/topics/{graphics => }/renderscript/compute.jd (52%) create mode 100644 docs/html/guide/topics/renderscript/index.jd rename docs/html/guide/topics/{graphics => }/renderscript/reference.jd (91%) diff --git a/docs/html/guide/guide_toc.cs b/docs/html/guide/guide_toc.cs index fee1f3580ccb..8e3fea60e7c0 100644 --- a/docs/html/guide/guide_toc.cs +++ b/docs/html/guide/guide_toc.cs @@ -311,26 +311,26 @@
  • Hardware Acceleration
  • - + + - - - - +
  • A static nested class, Item, allows you to create an instance of the @@ -665,23 +592,22 @@ appropriate layer.

    intPointer, and a pointer to a struct, touchPoints. It also binds the memory to the Renderscript:

    -private RenderScriptGL glRenderer;
    +private RenderScript myRenderscript;
     private ScriptC_example script;
     private Resources resources;
     
    -public void init(RenderScriptGL rs, Resources res) {
    -    //get the rendering context and resources from the calling method
    -    glRenderer = rs;
    +public void init(RenderScript rs, Resources res) {
    +    myRenderscript = rs;
         resources = res;
     
         //allocate memory for the struct pointer, calling the constructor
    -    ScriptField_Point touchPoints = new ScriptField_Point(glRenderer, 2);
    +    ScriptField_Point touchPoints = new ScriptField_Point(myRenderscript, 2);
     
         //Create an element manually and allocate memory for the int pointer
    -    intPointer = Allocation.createSized(glRenderer, Element.I32(glRenderer), 2);
    +    intPointer = Allocation.createSized(myRenderscript, Element.I32(myRenderscript), 2);
     
         //create an instance of the Renderscript, pointing it to the bytecode resource
    -    mScript = new ScriptC_example(glRenderer, resources, R.raw.example);
    +    mScript = new ScriptC_example(myRenderscript, resources, R.raw.example);
     
         //bind the struct and int pointers to the Renderscript
         mScript.bind_touchPoints(touchPoints);
    diff --git a/docs/html/guide/topics/graphics/renderscript/compute.jd b/docs/html/guide/topics/renderscript/compute.jd
    similarity index 52%
    rename from docs/html/guide/topics/graphics/renderscript/compute.jd
    rename to docs/html/guide/topics/renderscript/compute.jd
    index e827f003f97d..d464c90a52fe 100644
    --- a/docs/html/guide/topics/graphics/renderscript/compute.jd
    +++ b/docs/html/guide/topics/renderscript/compute.jd
    @@ -1,5 +1,5 @@
    -page.title=Compute
    -parent.title=Renderscript
    +page.title=Renderscript Computation 
    +parent.title=Computation
     parent.link=index.html
     
     @jd:body
    @@ -9,11 +9,12 @@ parent.link=index.html
         

    In this document

      +
    1. Renderscript System Overview
    2. - Creating a Compute Renderscript + Creating a Computation Renderscript
        -
      1. Creating the Renderscript file
      2. +
      3. Creating the Renderscript file
      4. Calling the Renderscript code
      @@ -25,47 +26,122 @@ parent.link=index.html
      1. Hello Compute
      2. - -
      3. Balls
      -

      Renderscript exposes a set of compute APIs that you can use to do intensive computational -operations. You can use the compute APIs in the context of a graphics Renderscript such as -calculating the positions of many objects in a scene. You can also create standalone compute -Renderscripts such as one that does image processing for a photo editor application.

      - -

      Compute Renderscripts scale to the amount of +

      Renderscript offers a high performance computation API at the native +level that you write in C (C99 standard). Renderscript gives your apps the ability to run +operations with automatic parallelization across all available processor cores. +It also supports different types of processors such as the CPU, GPU or DSP. Renderscript +is useful for apps that do image processing, mathematical modeling, or any operations +that require lots of mathematical computation.

      + +

      In addition, you have access to all of these features without having to write code to +support different architectures or a different amount of processing cores. You also +do not need to recompile your application for different processor types, because Renderscript +code is compiled on the device at runtime.

      + +

      Deprecation Notice: Earlier versions of Renderscript included + an experimental graphics engine component. This component +is now deprecated as of Android 4.1 (most of the APIs in rs_graphics.rsh +and the corresponding APIs in {@link android.renderscript}). +If you have apps that render graphics with Renderscript, we highly +recommend you convert your code to another Android graphics rendering option.

      + +

      Renderscript System Overview

      +

      The Renderscript runtime operates at the native level and still needs to communicate +with the Android VM, so the way a Renderscript application is set up is different from a pure VM +application. An application that uses Renderscript is still a traditional Android application that +runs in the VM, but you write Renderscript code for the parts of your program that require +it. No matter what you use it for, Renderscript remains platform +independent, so you do not have to target multiple architectures (for example, +ARM v5, ARM v7, x86).

      + +

      The Renderscript system adopts a control and slave architecture where the low-level Renderscript runtime +code is controlled by the higher level Android system that runs in a virtual machine (VM). The +Android VM still retains all control of memory management and binds memory that it allocates to +the Renderscript runtime, so the Renderscript code can access it. The Android framework makes +asynchronous calls to Renderscript, and the calls are placed in a message queue and processed +as soon as possible. Figure 1 shows how the Renderscript system is structured.

      + + +

      Figure 1. Renderscript system overview

      + +

      When using Renderscript, there are three layers of APIs that enable communication between the + Renderscript runtime and Android framework code:

      + +
        +
      • The Renderscript runtime APIs allow you to do the computation + that is required by your application.
      • + +
      • The reflected layer APIs are a set of classes that are reflected from your Renderscript +runtime code. It is basically a wrapper around the Renderscript code that allows the Android +framework to interact with the Renderscript runtime. The Android build tools automatically generate the +classes for this layer during the build process. These classes eliminate the need to write JNI glue +code, like with the NDK.
      • + +
      • The Android framework layer calls the reflected layer to access the Renderscript + runtime.
      • +
      + +

      Because of the way Renderscript is structured, the main advantages are:

      +
        +
      • Portability: Renderscript is designed to run on many types of devices with different + processor (CPU, GPU, and DSP for instance) architectures. It supports all of these architectures without + having to target each device, because the code is compiled and cached on the device + at runtime.
      • + +
      • Performance: Renderscript provides a high performance computation API with seamless parallelization + across the amount of cores on the device.
      • + +
      • Usability: Renderscript simplifies development when possible, such as eliminating JNI glue code.
      • +
      + +

      The main disadvantages are:

      + +
        +
      • Development complexity: Renderscript introduces a new set of APIs that you have to learn.
      • + +
      • Debugging visibility: Renderscript can potentially execute (planned feature for later releases) + on processors other than the main CPU (such as the GPU), so if this occurs, debugging becomes more difficult. +
      • +
      + +

      For a more detailed explanation of how all of these layers work together, see + Advanced Renderscript.

      + + +

      Creating a Renderscript

      + +

      Renderscripts scale to the amount of processing cores available on the device. This is enabled through a function named rsForEach() (or the forEach_root() method at the Android framework level). that automatically partitions work across available processing cores on the device. -For now, compute Renderscripts can only take advantage of CPU +For now, Renderscript can only take advantage of CPU cores, but in the future, they can potentially run on other types of processors such as GPUs and DSPs.

      -

      Creating a Compute Renderscript

      - -

      Implementing a compute Renderscript creating a .rs file that contains +

      Implementing a Renderscript involves creating a .rs file that contains your Renderscript code and calling it at the Android framework level with the forEach_root() or at the Renderscript runtime level with the -rsForEach() function. The following diagram describes how a typical compute +rsForEach() function. The following diagram describes how a typical Renderscript is set up:

      -

      Figure 1. Compute Renderscript overview

      +

      Figure 1. Renderscript overview

      -

      The following sections describe how to create a simple compute Renderscript and use it in an +

      The following sections describe how to create a simple Renderscript and use it in an Android application. This example uses the HelloCompute Renderscript sample that is provided in the SDK as a guide (some code has been modified from its original form for simplicity).

      -

      Creating the Renderscript file

      +

      Creating the Renderscript file

      Your Renderscript code resides in .rs and .rsh files in the -<project_root>/src/ directory. This code contains the compute logic +<project_root>/src/ directory. This code contains the computation logic and declares all necessary variables and pointers. -Every compute .rs file generally contains the following items:

      +Every .rs file generally contains the following items:

      • A pragma declaration (#pragma rs java_package_name(package.name)) @@ -74,13 +150,13 @@ Every compute .rs file generally contains the following items:

      • A pragma declaration (#pragma version(1)) that declares the version of Renderscript that you are using (1 is the only value for now).
      • -
      • A root() function that is the main worker function. The root function is +
      • A root() function that is the main worker function. The root function is called by the rsForEach function, which allows the Renderscript code to be called and executed on multiple cores if they are available. The root() function must return - void and accept the following arguments: + void and accept the following arguments:

          -
        • Pointers to memory allocations that are used for the input and output of the compute +
        • Pointers to memory allocations that are used for the input and output of the Renderscript. Both of these pointers are required for Android 3.2 (API level 13) platform versions or older. Android 4.0 (API level 14) and later requires one or both of these allocations.
        • @@ -129,28 +205,19 @@ void root(const uchar4 *v_in, uchar4 *v_out) {

          Calling the Renderscript code

          -

          You can do Renderscript to Renderscript calls with rsForEach in situations -such as when a graphics Renderscript needs to do a lot of computational operations. The Renderscript -Balls sample shows how -this is setup. The balls.rs -graphics Renderscript calls the balls_physics.rs -compute Renderscript to calculate the location of the balls that are rendered to the screen.

          - -

          Another way to use a compute Renderscript is to call it from your Android framework code by +

          You can call the Renderscript from your Android framework code by creating a Renderscript object by instantiating the (ScriptC_script_name) class. This class contains a method, forEach_root(), that lets you invoke rsForEach. You give it the same parameters that you would if you were invoking it at the Renderscript runtime level. This technique allows your Android application to offload intensive mathematical calculations to Renderscript. See the HelloCompute sample to see -how a simple Android application can utilize a compute Renderscript.

          +how a simple Android application can utilize Renderscript.

          -

          To call a compute Renderscript at the Android framework level:

          +

          To call Renderscript at the Android framework level:

            -
          1. Allocate memory that is needed by the compute Renderscript in your Android framework code. +
          2. Allocate memory that is needed by the Renderscript in your Android framework code. You need an input and output {@link android.renderscript.Allocation} for Android 3.2 (API level 13) platform versions and older. The Android 4.0 (API level 14) platform version requires only one or both {@link android.renderscript.Allocation}s.
          3. @@ -159,13 +226,13 @@ how a simple Android application can utilize a compute Renderscript.

          4. Call forEach_root(), passing in the allocations, the Renderscript, and any optional user-defined data. The output allocation will contain the output - of the compute Renderscript.
          5. + of the Renderscript.
          -

          In the following example, taken from the The following example, taken from the HelloCompute sample, processes a bitmap and outputs a black and white version of it. The -createScript() method carries out the steps described previously. This method the compute +createScript() method carries out the steps described previously. This method calls the Renderscript, mono.rs, passing in memory allocations that store the bitmap to be processed as well as the eventual output bitmap. It then displays the processed bitmap onto the screen:

          @@ -224,19 +291,17 @@ public class HelloCompute extends Activity {
           }
           
          -

          To call a compute Renderscript from another Renderscript file:

          +

          To call Renderscript from another Renderscript file:

            -
          1. Allocate memory that is needed by the compute Renderscript in your Android framework code. +
          2. Allocate memory that is needed by the Renderscript in your Android framework code. You need an input and output {@link android.renderscript.Allocation} for Android 3.2 (API level 13) platform versions and older. The Android 4.0 (API level 14) platform version requires only one or both {@link android.renderscript.Allocation}s.
          3. Call rsForEach(), passing in the allocations and any optional user-defined data. - The output allocation will contain the output of the compute Renderscript.
          4. + The output allocation will contain the output of the Renderscript.
          -

          The following example, taken from the Renderscript -Balls sample, demonstrates how to do make a script to script call:

          +
           rs_script script;
           rs_allocation in_allocation;
          @@ -245,9 +310,31 @@ UserData_t data;
           ...
           rsForEach(script, in_allocation, out_allocation, &data, sizeof(data));
           
          - +

          In this example, assume that the script and memory allocations have already been allocated and bound at the Android framework level and that UserData_t is a struct declared previously. Passing a pointer to a struct and the size of the struct to rsForEach -is optional, but useful if your compute Renderscript requires additional information other than +is optional, but useful if your Renderscript requires additional information other than the necessary memory allocations.

          + +

          Setting floating point precision

          +

          You can define the floating point precision required by your compute algorithms. This is useful if you + require less precision than the IEEE 754-2008 standard (used by default). You can define +the floating-point precision level of your script with the following pragmas:

          + +
            +
          • #pragma rs_fp_full (default if nothing is specified): For apps that + require floating point precision as outlined by the IEEE 754-2008 standard. +
          • +
          • #pragma rs_fp_relaxed - For apps that don’t require + strict IEEE 754-2008 compliance and can tolerate less precision. This mode enables + flush-to-zero for denorms and round-towards-zero. +
          • +
          • #pragma rs_fp_imprecise - For apps that don’t have stringent precision requirements. This mode enables + everything in rs_fp_relaxed along with the following: +
              +
            • Operations resulting in -0.0 can return +0.0 instead.
            • +
            • Operations on INF and NAN are undefined.
            • +
            +
          • +
          \ No newline at end of file diff --git a/docs/html/guide/topics/renderscript/index.jd b/docs/html/guide/topics/renderscript/index.jd new file mode 100644 index 000000000000..b6758bc832f9 --- /dev/null +++ b/docs/html/guide/topics/renderscript/index.jd @@ -0,0 +1,31 @@ +page.title=Computation +@jd:body + +

          Renderscript provides a platform-independent computation engine that operates at the native level. + Use it to accelerate your apps that require extensive computational horsepower.

          + + \ No newline at end of file diff --git a/docs/html/guide/topics/graphics/renderscript/reference.jd b/docs/html/guide/topics/renderscript/reference.jd similarity index 91% rename from docs/html/guide/topics/graphics/renderscript/reference.jd rename to docs/html/guide/topics/renderscript/reference.jd index a0a9df2df8ab..a9d780ad00a2 100644 --- a/docs/html/guide/topics/graphics/renderscript/reference.jd +++ b/docs/html/guide/topics/renderscript/reference.jd @@ -1,4 +1,7 @@ page.title=Runtime API Reference +parent.title=Computation +parent.link=index.html + @jd:body