android - 可以在非根内核上使用 RenderScript 的 rsForEach 吗?

标签 android renderscript

可以使用 rsForEach 调用非根 RenderScript 内核吗? 有许多使用 rsForEach 从可调用 RenderScript 函数中调用根内核的示例:

这些将脚本本身绑定(bind)到 RenderScript 上下文中的变量,然后从 RenderScript 中调用根内核。例如,在 Activity 类中:

...
mScript = new ScriptC_gradient(mRS);
// bind Allocations and mScript to variables in the RenderScript context:
mScript.set_gIn(mImageAllocation);
mScript.set_gOut(mGradientAllocation);
mScript.set_gScript(mScript);
// invoke gradient function:
mScript.invoke_gradient();
...

gradient.rs 中:

#pragma version(1)
#pragma rs java_package_name(com.example.android.rs.hellocompute)

rs_allocation gOut;
rs_allocation gIn;
rs_script gScript;

void gradient() {
  rsForEach(gScript, gIn, gOut);
}
void root(const uchar4 *v_in, uchar4 *v_out, ...

但是如果我有另一个内核 gray,我可以在 root 之后,在 gradient 中调用它吗?

// I thought it would look like this:
void gradient() {
  rsForEach(gScript, gIn, gOut);
  rsForEach(gScript, gIn, gOut, NULL, NULL, gExportForEachIdx_gray);
}
// Or:
void gradient() {
  rsForEach(gScript, gIn, gOut);
  rsSetMainKernel(&gScript, "gray");
  rsForEach(gScript, gIn, gOut);
}

但是the documentation for rsForEach似乎表明它不支持这样的东西。也许可以通过在 rs_script_call_t 中设置一些内容来实现,但是 the doc对那种类型相当简洁:(2013 年 9 月 20 日检索)

typedef struct rs_script_call rs_script_call_t**

Structure to provide extra information to a rsForEach call. Primarly used to restrict the call to a subset of cells in the allocation.

这个问题主要是出于好奇——我希望首选方法是从 Java 中调用它们:

...
mScript = new ScriptC_gradient(mRS);
// bind Allocations and mScript to variables in the RenderScript context:
mScript.forEach_root(mImageAllocation, mGradientAllocation);
mScript.forEach_gray(mGradientAllocation, mGrayGradientAllocation);
...

这些似乎是同步的。如果定义 rootgray 如下:

void root(...) { rsDebug("root", 0,0);  }
void gray(...) { rsDebug("gray", 1,1);  }

然后调用 forEach_root 然后调用 forEach_gray 导致“root, {0,0}”在开始记录“gray, {1,1}”之前被记录 NxM 次- 不过,我还没有找到保证这一点的文件。有人知道那是哪里吗?

最佳答案

不幸的是,我们目前没有办法从脚本中使用 rsForEach() 来调用非根 RenderScript 内核。您必须直接从 Java 调用它。您还可以将第二个内核作为 root() 放入另一个脚本中,然后也绑定(bind)该 rs_script(例如,您可以拥有 gScriptGradient 和 gScriptGray,并从主脚本中的单个调用中按顺序执行它们)。

我最初错过了你关于并行内核之间同步的第二个问题。他们确实是有序的。尽管内核是异步启动的,但第二个内核要等到第一个内核完成后才会运行。

关于android - 可以在非根内核上使用 RenderScript 的 rsForEach 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18924176/

相关文章:

android - 如何使用具有多个输入分配的 RenderScript?

java - 如何使具有一定RGB范围的像素点透明

android - 添加按钮时android opencv崩溃

android - 拖放 RecyclerView - 限制对特定 View 持有者的触摸

Android - 创建新的 View 属性并传递给 XML 复合 View 组件中的子级 - 布局中的数据绑定(bind)

android - RenderScript 错误地操作内核的输出

Android API 与 renderscript.type 类不一致

java - Renderscript 支持库的问题

android - 有没有办法直接从 Android 应用程序访问 MSSQL 数据库?

android - 连接到 ros master