Android RenderScript Matrix_2x2 元素数据类型

Android RenderScript Matrix_2x2 Element Data Type

我对 Android RenderScript 框架中的 MATRIX_2X2 元素有疑问:

RenderScript myRS = RenderScript.create(this);
Element myElement = Element.MATRIX_2X2(myRS);

我不知道这个矩阵的条目的数据类型是什么,即int16、int32、float32等

换句话说,我不知道如何使用所需数据类型的条目创建 MATRIX_2X2 元素。

我在 Android 开发者网站上找不到关于这个问题的任何文档,如果有人帮助我解决这个问题,我将不胜感激。

编辑:

既然我们知道数据类型是float32,我写了一个简单的测试代码。 这是内核代码(Test.rs):

rs_allocation in;

rs_matrix4x4 __attribute__((kernel)) root(uint32_t x)
{
    rs_matrix4x4* a = (rs_matrix4x4*) rsGetElementAt(in, x);
    rs_matrix4x4 out;

    for (int i = 0; i < 16; ++i)
        out.m[i] = a->m[i] + 1;
    return out;
}

我特意将'in'定义为全局变量。

这是java测试代码:

float[] in_1d = new float[32];
for (int i = 0; i < 32; ++i)
    in_1d[i] = (float) i;

RenderScript myRS = RenderScript.create(this);

Allocation inAllocation;
Allocation outAllocation;

Type myType = Type.createX(myRS, Element.MATRIX_4X4(myRS), 2);

inAllocation = Allocation.createTyped(myRS, myType);
outAllocation = Allocation.createTyped(myRS, myType);

inAllocation.copyFromUnchecked(in_1d);

ScriptC_Test myScript = new ScriptC_Test(myRS);

myScript.set_in(inAllocation);

myScript.forEach_root(outAllocation);

float[] out_1d = new float[32];
outAllocation.copyTo(out_1d);

inAllocation.destroy();
outAllocation.destroy();
myType.destroy();
myRS.destroy();

但是当我运行应用程序时,在这一行:

outAllocation.copyTo(out_1d);

抛出异常:

android.renderscript.RSIllegalArgumentException: 32 bit float source does not match allocation type MATRIX_4X4

如果我使用:

inAllocation.copyFrom(in_1d);

而不是:

inAllocation.copyFromUnchecked(in_1d);

我会得到相同的输入分配异常。但是没有这样的 'copyToUnchecked' 方法可以用来代替 'copyTo'.

我该如何解决这个问题?

rs_matrix 类 只包含浮点数。您不能为任何其他类型创建它们。