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);
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.
Thank you in advance for your help.
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
}
Since I was receiving an error message:
Error from rsdSetupInputOutputAttributes -30
I gave for granted that the kernel wasn't working, but it works correctly, the special attribute z is available and correctly populated.
On top of it, I tried the same app on a different device with the same OS version (Huawei P9) and it doesn't give any error. It seems that this official OS update for the LG G4, rolled out by TIM operator in late 2016, has a partially flawed RenderScript implementation.