0

I want to create a renderscript in android where an array is passed to the .rs file. On these values some calculation is done and sent back to the user.

I have very little understanding of renderscript, so what I have written might be completely wrong also. Please help me with it.

Android activity public class RenderTemp extends Activity {

    private RenderScript mRS;
    private ScriptC_snow mScript;
    int[] indices;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.render);
        indices = new int[2];
        indices[0] = 1;
        indices[1] = 2;
        createScript();
    }

    private void createScript() {
        mRS = RenderScript.create(this);
        Allocation mIN = Allocation.createSized(mRS, Element.I32(mRS), indices.length);
        mIN.copyFrom(indices);
        mScript = new ScriptC_snow(mRS);
        mScript.forEach_root(mIN);
        mIN.copyTo(indices);
    }
}

snow.rs

#pragma version(1)
#pragma rs java_package_name(#package name)


int32_t *mIN;

void __attribute__((kernel)) root(int32_t in)
{
    in = in + 2;
}
Viraj Talaty
  • 15
  • 2
  • 6

1 Answers1

1

Modifying "in" inside your kernel won't cause anything to get updated. You can change it such that your root() function has a return value of int32_t as well. Then do "return in + 2;". Finally, you can pass mIN for both input and output to the forEach (so "mScript.forEach_root(mIn, mIn);"). Even though this will work for you, I would strongly advocate that you separate the input and output Allocations for any real work, as aliasing input/output like this can prevent compiler optimizations for more complex code.

Stephen Hines
  • 2,612
  • 1
  • 13
  • 12