简体   繁体   English

RenderScript ScriptGroups-在第二个内核中从脚本全局获取输出

[英]RenderScript ScriptGroups - getting Output from script global in second Kernel

I want to combine two Renderscript scripts into a scriptGroup. 我想将两个Renderscript脚本合并到一个scriptGroup中。 The first one is the ScriptIntrinsicBlur. 第一个是ScriptIntrinsicBlur。 Based on the blurred U8 allocation as input the second script calculates two things: gradient and gradient-direction. 根据输入的模糊U8分配,第二个脚本计算两件事:渐变和渐变方向。 The latter is the formal out-Allocation of the second kernel. 后者是第二个内核的正式Out-Allocation。 The first one is a global allocation filled via rsSetElementAt_float(). 第一个是通过rsSetElementAt_float()填充的全局分配。 Now, I find this second allocation is returned empty after execution of the scriptGroup. 现在,我发现第二个分配在执行scriptGroup之后返回为空。

Question: Is my assumption correct that with a scriptGroup you cannot use script globals - or at least not change them via rsSetElementAt_(...)? 问题:我的假设是否正确,即使用scriptGroup不能使用脚本全局变量-或至少不能通过rsSetElementAt _(...)更改它们?

UPDATE: I realized that the performance gain by using U8 both as output of the ScriptIntrinsicBlur and as input of the proprietary kernel is already more than satisfactory, even in a simple sequential set-up of both scripts. 更新:我意识到通过使用U8作为ScriptIntrinsicBlur的输出和作为专有内核的输入的性能提升已经令人满意,即使在两个脚本的简单顺序设置中也是如此。 This is primarily because it avoids to copyTo the ScriptIntrinsicBlur's out-Allocation first into a Java-array before passing it as a separate input-allocation to the 2nd kernel. 这主要是因为它避免了先将CopyIn ScriptIntrinsicBlur的外分配复制到Java数组中,然后再将其作为单独的输入分配传递给第二个内核。

Before, I used U8_4 (ie Bitmap equivalent) as output of ScriptIntrinsicBlur, and then converted it to a one-dimensional greyscale int[] array, before passing it as in-Allocation to the proprietary kernel... Now I convert to greyscale byte[] (ie U8) already before entering the allocation into ScriptIntrinsicBlur and use U8 also as input for the 2nd kernel. 以前,我使用U8_4(即等效于位图)作为ScriptIntrinsicBlur的输出,然后将其转换为一维灰度int []数组,然后将其作为in-Allocation传递给专有内核...现在,我转换为灰度字节[](即U8)在将分配输入到ScriptIntrinsicBlur之前已经使用,并且也将U8用作第二个内核的输入。

This is what I realize again and again when working with RS: it is really worth to simplify data flows to the extent possible, the speed gains are fantastic. 这是我在使用RS时一次又一次地意识到的:尽可能简化数据流确实是值得的,速度的提高是惊人的。 (maybe I will check the Scriptgroup question at a later stage, as for now I am happy with the result). (也许稍后我会检查脚本组问题,因为现在我对结果感到满意)。

There should be no issue with using a script global like this. 使用这样的全局脚本应该没有问题。 It's not as efficient as the output allocation, but is possible. 它不如输出分配有效,但有可能。 You mentioned the out allocation is empty, what are you seeing in the script global? 您提到out分配为空,您在全局脚本中看到了什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM