我试图将所有分配单元格复制到renderscript中的其他分配。从android开发人员api参考我得到了这个方法 rsAllocationCopy1DRange ,其签名是
void rsAllocationCopy1DRange(rs_allocation dstAlloc,uint32_t dstOff,uint32_t dstMip,uint32_t count,rs_allocation srcAlloc,uint32_t srcOff,uint32_t srcMip);
。
方法的Google参考链接为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)
答案 0 :(得分:2)
这个bug在logcat中是正确的。您不能在RenderScript内核中进行此类调用。您只能在可调用函数内进行此调用。或者,您可以使用Java API从这一方面执行此复制。