Returning a Renderscript struct from a Renderscript kernel

帅比萌擦擦* 提交于 2019-11-28 09:39:55

问题


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.

Any help at all appreciated

Edit for clarification:

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

I then call my renderscript function after populating bodys

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

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;
 }

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.


回答1:


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.




回答2:


Actually you should use the copy1DRangeToUnchecked method of the Allocation class. You can copy it into your own ByteBuffer and deserialize it yourself.



来源:https://stackoverflow.com/questions/19418416/returning-a-renderscript-struct-from-a-renderscript-kernel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!