可以重载一个RenderScript内核吗?

时间:2013-10-24 19:06:00

标签: overloading renderscript

我想重载一个RenderScript内核:

/* donothing.rs */

uchar4 __attribute__((kernel, overloadable)) root (uchar4 in) {
  return in;
}

float4 __attribute__((kernel, overloadable)) root (float4 in) {
  return in;
}

但是,这会生成名称相同的Java方法:

// ScriptC_donothing.java:95
public void forEach_root(Allocation ain, Allocation aout, Script.LaunchOptions sc) {
    // check ain
    if (!ain.getType().getElement().isCompatible(__U8_4)) {
        throw new RSRuntimeException("Type mismatch with U8_4!");
    }
    ...

// ScriptC_donothing.java:225
public void forEach_root(Allocation ain, Allocation aout, Script.LaunchOptions sc) {
    // check ain
    if (!ain.getType().getElement().isCompatible(__F32_4)) {
        throw new RSRuntimeException("Type mismatch with F32_4!");
    }
    ...

有没有办法编写内核以便重载?我期望的用法是:

// DoNothingActivity.java

mInAllocation = Allocation.createFromBitmap(mRS, ...
mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());

mScript = new ScriptC_donothing(mRS);
mScript.forEach_root(mInAllocation, mOutAllocation);
// calls uchar4 kernel

1 个答案:

答案 0 :(得分:4)

现在无法重载内核名称。不过,我们正在投资一些方法将更多类型信息与未来的分配联系起来;我们会记住这个用例。