我们可以使用RenderScript的rsForEach在非根内核? [英] Can one use RenderScript's rsForEach on a non-root kernel?

查看:395
本文介绍了我们可以使用RenderScript的rsForEach在非根内核?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在一个调用使用非root RenderScript内核 rsForEach
有使用的许多例子 rsForEach 从一个可调用RenderScript函数中调用根内核:

这些脚本本身绑定到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,杜松子酒,痛风);
}

但是,<一个href=\"http://developer.android.com/reference/renderscript/rs__core_8rsh.html#a64271d266928b06ebd82ec90b756eb23\"相对=nofollow>为 rsForEach 的文件似乎表明,它不支持这样的事。也许这可以通过设置在 rs_script_call_t ,而<东西来完成href=\"http://developer.android.com/reference/renderscript/rs__core_8rsh.html#ae8756b32e23445f287960b9d0ffb449c\"相对=nofollow>商务部是相当简洁有关此类型:(2013 9月20日检索)


  typedef结构rs_script_call rs_script_call_t **


  
  

结构,以提供额外的信息,一个电话rsForEach。 Primarly用来限制呼叫到在分配单元的一个子集


此问题是大多是出于curiosity-我希望preferred的方法是从Java调用它们:

...
mScript =新ScriptC_gradient(MRS);
//绑定分配和mScript在RenderScript环境变量:
mScript.forEach_root(mImageAllocation,mGradientAllocation);
mScript.forEach_gray(mGradientAllocation,mGrayGradientAllocation);
...

这些似乎是同步的。如果你需要定义一个灰色如下:

无效根(...){rsDebug(根,0,0); }
虚空灰色(...){rsDebug(灰色,1,1); }

然后调用 forEach_root 在此之前 forEach_gray 的原因根,{0,0}将被记录N×M的时代它开始记录灰,{1,1} - 我还没有找到文档保证,虽然。任何人都知道那是什么?


解决方案

不幸的是我们没有currrently有一种方法来调用使用rsForEach()从脚本非root RenderScript内核。你将不得不从Java直接调用它。你也可以把第二个内核的另一个脚本作为root(),然后将绑定rs_script以及(例如,你可以有gScriptGradient和gScriptGray并从单一援引主脚本按顺序执行它们)。

我最初错过了你的有关并行内核之间的同步的第二个问题。他们确实是有序的。虽然内核是异步启动,第二个内核将不会运行,直到第一个内核是完整的。

Can one invoke a non-root RenderScript kernel using rsForEach? There are many examples of using rsForEach to call the root kernel from within an invokable RenderScript function:

These bind the script itself to a variable in the RenderScript context, then invoke the root kernel from within RenderScript. For example, in the Activity class:

...
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();
...

And in 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, ...

But if I have another kernel gray could I invoke it after root, inside 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);
}

But the documentation for rsForEach seems to indicate that it doesn't support anything like this. Perhaps it can be accomplished by setting something in a rs_script_call_t, but the doc is rather terse about that type: (Retrieved 20 September 2013)

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.

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在非根内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆