Background
I am trying to use RenderScript to perform some actions on a 3D Allocation.
Here I create the Allocation:
Type.Builder analyzer3DType = new Type.Builder(rsAnalyzer, Element.U8(rsAnalyzer))
.setX(allocationSize.getWidth() - allocationPadding * 2)
.setY(allocationSize.getHeight() - allocationPadding * 2)
.setZ(framesNumber);
analyzer3DAllocation = Allocation.createTyped(rsAnalyzer, analyzer3DType.create(), Allocation.USAGE_SCRIPT);
then setup the Java side and launch the kernel:
ScriptC_analyze rsAnalyze = new ScriptC_analyze(rsAnalyzer);
rsAnalyze.forEach_root(analyzer3DAllocation);
and this is how the kernel looks like:
void RS_KERNEL root(uchar in, uint32_t x, uint32_t y, uint32_t z) {
// Do something.
}
Note that I need two different RenderScript contexts for parallel execution, thus this is how I create the RenderScript object:
rsAnalyzer = RenderScript.createMultiContext(context, RenderScript.ContextType.NORMAL, RenderScript.CREATE_FLAG_NONE, 23);
Problem
I get this runtime error:
W/Adreno-RS: rsdSetupInputOutputAttributes:2051: Incorrect number of input args, expected: 2 actual 1
W/Adreno-RS: rsdScriptInvokeForEach:2511: Error from rsdSetupInputOutputAttributes -30
The problem disappears if I don't insert the z attribute in the root kernel. It seems like the z attribute is not recognized as a special attribute.
I am targeting API 23 and this special attribute should be supported. From the docs:
A mapping kernel function or a reduction kernel accumulator function may access the coordinates of the current execution using the special arguments x, y, and z, which must be of type int or uint32_t. These arguments are optional.
In What are the available kernel-functions that you can create on Renderscript? on Oct 7 2015 Stephen Hines writes:
The only auto-filled parameters are x, y, (and maybe z in Android M).
I am not completely sure that the z attribute is supported in API level 23 but at least Android Studio thinks so.
Questions
- Am I doing something wrong? Is there a way to use the z attribute in a kernel in API level 23?
- If not, what could be the best way to implement this if I need to iterate over elements not only in x and y axis but also along z?
Thank you in advance for your help.
Additional information
This is part of my Application build.gradle:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 23
targetSdkVersion 23
renderscriptTargetApi 23
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}