Renderscript rs.finish(), allocation.syncAll(), copyTo() :等待内核执行完成

Pun*_*ain 1 parallel-processing android gpu sync renderscript

我正在编写 android 渲染脚本代码,它需要背靠背的内核调用(有时一个内核的输出成为另一个内核的输入)。我还有一些全局指针,从 Java 层绑定到内存。每个内核更新这些全局指针并输出一些东西。我必须确保在 kernel2 开始执行之前已完成 kernel1 的执行。

我查看了 android renderscript 文档,但无法很好地理解 syncAll(Usage) 和 finish()。谁能澄清如何实现这种行为?

谢谢

mScript.forEach_kernel1(mColorImageAllocation, tempAlloc);

// make sure kernel1 finishes, from android rs doc, copyTo should block 
tempAlloc.copyTo(testOutputBitmap);

for (short i = 0; i < NUM_DIST; i++) {
            mScript.set_gCurrentDistanceIndex(i);
            mScript.forEach_kernel2(tempAlloc);    
        mRS.finish(); // wait till kernel2 finishes
}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,在 kernel1 的输出上使用不同的全局参数调用相同的 kernel2。

R. *_*ams 5

对于此代码,您也不需要。RS 是一种管道模型,因此任何可能影响后续命令结果的工作都必须首先由驱动程序完成。

syncAll() 用于同步内存空间而不是执行。例如,将更改从脚本内存传播到图形内存。