简体   繁体   English

从Renderscript内核返回Renderscript结构

[英]Returning a Renderscript struct from a Renderscript kernel

I'm looking to return an array of struct from my renderscript kernel. 我想从我的renderscript内核返回一个结构数组。 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. 我的问题是,尽管我可以使用生成的代码在Java中创建结构的数组,并通过获取由此生成的数组的分配将其传递给我的root方法,但我无法将数组返回到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. Renderscript文档说要使用copyTo方法从分配中复制出来,以确保renderscript已完成对其的操作。 However this method only supports float, int, byte, bitmap. 但是,此方法仅支持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. 即使在访问数组以确保渲染脚本完成之前等待了几秒钟之后,out分配中的数据也根本没有发生变化,所以我想知道我是否正在解决此错误。

Any help at all appreciated 任何帮助都表示赞赏

Edit for clarification: 编辑以澄清:

I Create a array of my struct in java with the following 我用以下代码在Java中创建结构数组

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

I then call my renderscript function after populating bodys 然后,我在填充主体之后调用我的renderscript函数

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

My renderscript should simply copy bodys to outBodys 我的渲染脚本应该只是将正文复制到outBodys

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

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). 回到Java中,我现在想访问outBodies,(从调试代码中我知道我的renderscript函数可以读取数据并将其复制良好)。 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. 但是,我不能在outBodys.getllocation()函数上使用标准的copyTo,因为它只能接受float,int,字节和位图,outBodies对象也不能从分配中自动更新。 Note that NBody_t is a struct I defined in the renderscript file. 请注意,NBody_t是我在renderscript文件中定义的结构。

RenderScript currently doesn't reflect a method to copy back the values from a user-defined struct to Java. 目前,RenderScript尚无法反映将值从用户定义的结构复制回Java的方法。 We indeed only have methods that operate on primitive Java and vector types. 实际上,我们只有在原始Java和向量类型上运行的方法。 The Allocation is still usable by other kernels or Script-side functions. 其他内核或脚本端功能仍然可以使用该分配。

Actually you should use the copy1DRangeToUnchecked method of the Allocation class. 实际上,您应该使用Allocation类的copy1DRangeToUnchecked方法。 You can copy it into your own ByteBuffer and deserialize it yourself. 您可以将其复制到自己的ByteBuffer中,然后自行反序列化。

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

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