Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

android - Returning a Renderscript struct from a Renderscript kernel

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...