使用 3D RenderScript 分配,z 属性不可用

Working on a 3D RenderScript Allocation, z attribute unavailable

背景

我正在尝试使用 RenderScript 对 3D 分配执行一些操作。

这里我创建分配:

 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);

然后设置 Java 端并启动内核:

ScriptC_analyze rsAnalyze = new ScriptC_analyze(rsAnalyzer);
rsAnalyze.forEach_root(analyzer3DAllocation);

这就是内核的样子:

void RS_KERNEL root(uchar in, uint32_t x, uint32_t y, uint32_t z) {
   // Do something.
}

请注意,我需要两个不同的 RenderScript 上下文来并行执行,因此这就是我创建 RenderScript 对象的方式:

rsAnalyzer = RenderScript.createMultiContext(context, RenderScript.ContextType.NORMAL, RenderScript.CREATE_FLAG_NONE, 23);

问题

我收到这个运行时错误:

W/Adreno-RS: rsdSetupInputOutputAttributes:2051: Incorrect number of input args, expected: 2 actual 1

W/Adreno-RS: rsdScriptInvokeForEach:2511: Error from rsdSetupInputOutputAttributes -30

如果我不在根内核中插入 z 属性,问题就会消失。 z 属性似乎没有被识别为特殊属性。

我的目标是 API 23,应该支持这个特殊属性。来自文档:

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.

在 2015 年 10 月 7 日的 What are the available kernel-functions that you can create on Renderscript? 中,Stephen Hines 写道:

The only auto-filled parameters are x, y, (and maybe z in Android M).

我不完全确定 API 级别 23 是否支持 z 属性,但至少 Android Studio 是这么认为的。

问题

  1. 我做错了什么吗?有没有办法在 API 级别 23 的内核中使用 z 属性?
  2. 如果不是,如果我不仅需要在 x 轴和 y 轴上迭代元素,而且还需要沿 z 轴迭代元素,那么最好的实现方法是什么?

预先感谢您的帮助。

附加信息

这是我申请的一部分 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
}

因为我收到一条错误消息:

Error from rsdSetupInputOutputAttributes -30

我理所当然地认为内核没有工作,但它工作正常,特殊属性 z 可用并正确填充。

最重要的是,我在具有相同 OS 版本(华为 P9)的不同设备上尝试了相同的应用程序,它没有给出任何错误。由 TIM 运营商于 2016 年底推出的 LG G4 官方 OS 更新似乎存在部分缺陷的 RenderScript 实现。