【发布时间】:2013-09-21 05:33:15
【问题描述】:
可以使用rsForEach 调用非根 RenderScript 内核吗?
有许多使用rsForEach 从可调用的 RenderScript 函数中调用根内核的示例:
- Documentation for Androids Renderscript advanced rsForEach call
- How to write a convolution multiplication in Android Renderscript?
- Passing Array to rsForEach in Renderscript Compute
这些将脚本本身绑定到 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**向 rsForEach 调用提供额外信息的结构。主要用于限制对分配中单元格子集的调用。
这个问题主要是出于好奇——我希望首选方法是从 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);
...
这些似乎是同步的。如果定义root和gray如下:
void root(...) { rsDebug("root", 0,0); }
void gray(...) { rsDebug("gray", 1,1); }
然后调用forEach_root 然后调用forEach_gray 会导致“root, {0,0}”在开始记录“gray, {1,1}”之前被记录 NxM 次 - 我还没有找到可以保证的文档, 尽管。有人知道那是哪里吗?
【问题讨论】:
标签: android renderscript