What is renderscript?

satya - Wed Jul 25 2012 16:00:40 GMT-0400 (Eastern Daylight Time)

android renderscript

android renderscript

Search for: android renderscript

satya - Wed Jul 25 2012 16:01:50 GMT-0400 (Eastern Daylight Time)

here is renderscript overview from android

here is renderscript overview from android

satya - Wed Jul 25 2012 16:03:16 GMT-0400 (Eastern Daylight Time)

What is renderscript?

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.

satya - Wed Jul 25 2012 16:03:52 GMT-0400 (Eastern Daylight Time)

Is it limited to image processing only? No!

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.

satya - Wed Jul 25 2012 16:04:45 GMT-0400 (Eastern Daylight Time)

because it is in 'c' does it need compilation for each processor?

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.

satya - Wed Jul 25 2012 16:06:08 GMT-0400 (Eastern Daylight Time)

Renderscript is platform independent

Renderscript is platform independent

satya - Wed Jul 25 2012 16:09:17 GMT-0400 (Eastern Daylight Time)

The Android build tools automatically generate the classes to talk to the Renderscript code

much like stubs in EJBs

satya - Wed Jul 25 2012 16:09:41 GMT-0400 (Eastern Daylight Time)

high level view

satya - Wed Jul 25 2012 16:10:36 GMT-0400 (Eastern Daylight Time)

Pros


Fast
Portable
Ease of use (No JNI)

satya - Wed Jul 25 2012 16:11:21 GMT-0400 (Eastern Daylight Time)

Cons


another api to learn
debugging due to client/server architecture

satya - Wed Jul 25 2012 16:15:08 GMT-0400 (Eastern Daylight Time)

Sample renderscript code


#pragma version(1)
#pragma rs java_package_name(com.example.android.rs.hellocompute)

//multipliers to convert a RGB colors to black and white
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};

void root(const uchar4 *v_in, uchar4 *v_out) {
  //unpack a color to a float4
  float4 f4 = rsUnpackColor8888(*v_in);
  //take the dot product of the color and the multiplier
  float3 mono = dot(f4.rgb, gMonoMult);
  //repack the float to a color
  *v_out = rsPackColorTo8888(mono);
}

satya - Wed Jul 25 2012 16:20:29 GMT-0400 (Eastern Daylight Time)

Here is how to use this


private void createScript() {
      mRS = RenderScript.create(this);
      mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
          Allocation.MipmapControl.MIPMAP_NONE,
          Allocation.USAGE_SCRIPT);
      mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
      mScript = new ScriptC_mono(mRS, getResources(), R.raw.mono);
      mScript.forEach_root(mInAllocation, mOutAllocation);
      mOutAllocation.copyTo(mBitmapOut);
  }

satya - Wed Jul 25 2012 16:21:31 GMT-0400 (Eastern Daylight Time)

See the android link above for full sample code

The class ScriptC_mono is a generated class that has the function forEach_root

satya - Wed Jul 25 2012 16:23:47 GMT-0400 (Eastern Daylight Time)

Some key features

  1. Memory allocation request features
  2. A large collection of math functions with both scalar and vector typed overloaded versions of many common routines. Operations such as adding, multiplying, dot product, and cross product are available as well as atomic arithmetic and comparison functions.
  3. Conversion routines for primitive data types and vectors, matrix routines, and date and time routines
  4. Data types and structures to support the Renderscript system such as Vector types for defining two-, three-, or four-vectors.
  5. Logging functions

satya - Sun Sep 02 2012 12:02:43 GMT-0400 (Eastern Daylight Time)

Another article on Renderscript

Another article on Renderscript