我试图将分配的所有单元格复制到渲染脚本中的其他分配。从android开发者api参考我得到了这个方法rsAllocationCopy1DRange,它的签名是
void rsAllocationCopy1DRange(rs_allocation dstAlloc,uint32_t dstOff,uint32_t dstMip,uint32_t 计数,rs_allocation srcAlloc,uint32_t srcOff,uint32_t srcMip);
.
方法的谷歌参考链接是https://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data.html
但是当我运行脚本时,它会在 android.support.v8.renderscript错误中显示调用不支持的方法 rsAllocationCopy1DRange
我的 rs 脚本在下面
#pragma version(1)
#pragma rs java_package_name(com.ravikant.rs)
#pragma rs_fp_relaxed
int width;
int height;
rs_allocation stateArr;
rs_allocation stateNextArr;
void __attribute__((kernel)) _copy(int32_t in)
{
int len=width*height;
rsAllocationCopy1DRange(stateArr,0,0,len,stateNextArr,0,0);
}
和java代码是
float[] sideArr=new float[width*height};
Arrays.fill(sideArr,1);
Allocation stateArrAlloc = Allocation.createSized(rs, Element.F32(rs), sideArr.length);
Allocation stateNextArrAlloc = Allocation.createSized(rs, Element.F32(rs), sideArr.length);
stateArrAlloc.copyFrom(sideArr);
stateNextArrAlloc.copyFrom(sideArr);
scriptC_copycells.set_width(width);
scriptC_copycells.set_height(height);
scriptC_copycells.set_stateArr(stateArrAlloc);
scriptC_copycells.set_stateNextArr(stateNextArrAlloc);
scriptC_copycells.forEach__copy(stateArrAlloc);
错误的 Logcat 输出是
E/AndroidRuntime: FATAL EXCEPTION: RSMessageThread
Process: com.ravikant.rs, PID: 2321
android.support.v8.renderscript.RSRuntimeException: Fatal error 4097,
details: Error: Call to unsupported function rsAllocationCopy1DRange in kernel at android.support.v8.renderscript.RenderScript$MessageThread.run(RenderScript.java:1313)