问题描述
可以在一个调用使用非root RenderScript内核 rsForEach
?
有使用的许多例子 rsForEach
从一个可调用RenderScript函数中调用根内核:
- rsForEach
这些脚本本身绑定到RenderScript上下文变量,然后从内RenderScript调用根内核。例如,在活动
类:
...
mScript =新ScriptC_gradient(MRS);
//绑定分配和mScript在RenderScript环境变量:
mScript.set_gIn(mImageAllocation);
mScript.set_gOut(mGradientAllocation);
mScript.set_gScript(mScript);
//调用功能梯度:
mScript.invoke_gradient();
...
而在 gradient.rs
:
的#pragma版(1)
RS的#pragma java_package_name(com.example.android.rs.hellocompute)rs_allocation痛风;
rs_allocation GIN;
rs_script版gscript;空隙梯度(){
rsForEach(版gscript,杜松子酒,痛风);
}
无效根(常量uchar4 * V_IN,uchar4 * V_OUT,...
但是,如果我有另一个内核灰色
我可以调用它后根
,里面的梯度
?
//我认为这将是这样的:
空隙梯度(){
rsForEach(版gscript,杜松子酒,痛风);
rsForEach(版gscript,杜松子酒,痛风,NULL,NULL,gExportForEachIdx_gray);
}
// 要么:
空隙梯度(){
rsForEach(版gscript,杜松子酒,痛风);
rsSetMainKernel(安培;版gscript,灰色);
rsForEach(版gscript,杜松子酒,痛风);
}
但是,为 rsForEach
的文件似乎表明,它不支持这样的事。也许这可以通过设置在 rs_script_call_t
,而商务部是相当简洁有关此类型:(2013 9月20日检索)
This question is mostly out of curiosity- I expect the preferred method is to call them from 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);
...
These seem to be synchronized. If one defines root
and gray
as follows:
void root(...) { rsDebug("root", 0,0); }
void gray(...) { rsDebug("gray", 1,1); }
then calling forEach_root
then forEach_gray
causes "root, {0,0}" to be logged NxM times before it starts logging "gray, {1,1}" - I haven't found documentation that guarantees that, though. Anybody know where that is?
Unfortunately we don't currrently have a way to invoke a non-root RenderScript kernel using rsForEach() from the script. You will have to call into it from Java directly. You could also put the second kernel in another Script as root() and then bind that rs_script as well (e.g. you can have gScriptGradient and gScriptGray and execute them sequentially from a single invoke in your primary Script).
I initially missed your second question about synchronization between parallel kernels. They are indeed ordered. Although kernels are launched asynchronously, the second kernel will not run until the first kernel is complete.
这篇关于我们可以使用RenderScript的rsForEach在非根内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!