从Renderscript内核返回Renderscript结构 [英] Returning a Renderscript struct from a Renderscript kernel

查看:112
本文介绍了从Renderscript内核返回Renderscript结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的renderscript内核返回一个结构数组.我的问题是,尽管我可以使用生成的代码在Java中创建结构的数组,并通过获取由此生成的数组的分配将其传递给我的root方法,但我无法将数组返回到Java中. Renderscript文档说要使用copyTo方法从分配中复制出来,以确保renderscript已完成对其的操作.但是,此方法仅支持float,int,byte,bitmap.即使在访问数组以确保渲染脚本完成输出之前等待了几秒钟之后,输出分配中的数据也不会出现任何变化,所以我想知道我是否正在解决此错误.

I'm looking to return an array of struct from my renderscript kernel. My problem is that although I can create an array of the struct in java using the generated code and pass this to my root method by getting the allocation of the array generated from this, I cant get the array back into java. The Renderscript documentation says to use the copyTo method to copy out of the allocation which ensures that the renderscript has finished operating on it. However this method only supports float, int, byte, bitmap. Even after waiting several seconds before accessing the array to ensure that the renderscript has finished the data in the out allocation doesn't appear changed at all so I wonder if i am approaching this wrong.

感谢所有帮助

为澄清起见进行

我使用以下代码在Java中创建我的结构的数组

I Create a array of my struct in java with the following

    ScriptField_NBody bodys = ScriptField_NBody.create1D(mRS, size, Allocation.USAGE_SCRIPT);
    ScriptField_NBody outBodys = new ScriptField_NBody(mRS, 1);

然后在填充正文之后调用我的renderscript函数

I then call my renderscript function after populating bodys

    nBodyScript.forEach_root(bodys.getAllocation(), outBodys.getAllocation())

我的渲染脚本应该简单地将正文复制到outBodys

My renderscript should simply copy bodys to outBodys

 void root(const NBody_t *v_in, NBody_t *v_out, uint32_t x) {
*v_out = *v_in;
 }

回到java,我现在想访问outBodies,(从调试代码中我知道我的renderscript函数可以读取数据并将其复制良好).但是我不能在outBodys.getllocation()函数上使用标准的copyTo,因为它只能获取floats,int,bytes和bitmap,而outBodies对象也无法从分配中自动更新.请注意,NBody_t是我在renderscript文件中定义的结构.

Back in java I now want to access outBodies, (from debug code I know that my renderscript function reads the data and copies it fine). However I cant use the standard copyTo on the outBodys.getllocation() function as this only can take floats, int, bytes and bitmaps, nor does outBodies object update from the allocation on its own. Note that NBody_t is a struct I defined in the renderscript file.

推荐答案

RenderScript当前无法反映将值从用户定义的结构复制回Java的方法.实际上,我们只有在原始Java和向量类型上运行的方法.该分配仍可用于其他内核或脚本端功能.

RenderScript currently doesn't reflect a method to copy back the values from a user-defined struct to Java. We indeed only have methods that operate on primitive Java and vector types. The Allocation is still usable by other kernels or Script-side functions.

这篇关于从Renderscript内核返回Renderscript结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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