我正在使用renderscript进行实时图像处理(相机预览)。我在Nexus 6 Marshmallow 6.1中遇到问题,其中一些脚本不会运行超过几帧(rs内核运行)。这些相同的脚本在Nexus 4 Lollipop 5.1上完美运行。Renderscript图像处理Nexus 6棉花糖问题
症状: 脚本适用于多次运行(构建)。在第n次运行中,某些脚本停止按预期工作,所有后续运行都会出现上述问题。我一直无法在导致问题的代码中建立一些特定的操作。它看起来完全是随机的,至少从我能收集到的东西来看。
什么iv'e尝试:
- 重启手机,卸载应用程序,清理的项目,无效Android Studio中的缓存产生任何结果。
- 添加
rsDebug()
每这篇文章:
RenderScript code not working without rsDebug 似乎已经解决了这一问题,但经过几次构建问题 又出现了。 - 在代码中添加
rsDebug()
,实际上日志似乎按预期运行了 脚本,但不用说这不是解决方案,因为它会减慢脚本的运行速度。 - 删除
#pragma rs_fp_relaxed
似乎已经修复了这个问题,但 之后出现了几个build的问题。 adb shell setprop debug.rs.default-CPU-driver 1
解决问题, 但使用的renderScript整点是利用 异构计算我使用这个内核签名uchar4 __attribute__((kernel)) filter(uchar4 v_in, uint32_t x, uint32_t y)
,虽然RS_KERNEL
导致同样的问题。
感谢您的任何帮助和想法。
样的影响的代码:(谷歌演示代码从这里:https://android.googlesource.com/platform/frameworks/rs/+/master/java/tests/ImageProcessing2/src/com/android/rs/image/)
static float sr = 0.f;
static float sg = 0.f;
static float sb = 0.f;
void prepareBwFilter(uint32_t rw, uint32_t gw, uint32_t bw) {
sr = rw;
sg = gw;
sb = bw;
float imageMin = min(sg,sb);
imageMin = fmin(sr,imageMin);
float imageMax = max(sg,sb);
imageMax = fmax(sr,imageMax);
float avg = (imageMin + imageMax)/2;
sb /= avg;
sg /= avg;
sr /= avg;
}
void bwFilterKernel(const uchar4 *in, uchar4 *out) {
float r = in->r * sr;
float g = in->g * sg;
float b = in->b * sb;
float localMin, localMax, avg;
localMin = fmin(g,b);
localMin = fmin(r,localMin);
localMax = fmax(g,b);
localMax = fmax(r,localMax);
avg = (localMin+localMax) * 0.5f;
out->r = out->g = out->b = rsClamp(avg, 0, 255);
}
你能发布更多关于你的代码吗?这看起来像一个GPGPU问题(因为setprop修复了一些问题)。我同意setprop不是一个解决方案,但它是奇特的,它解决了它,而其他GPGPU禁用功能不。如果你能进一步隔离事物,我们可以看看到底发生了什么。 –
我尽最大努力查明问题,但收效甚微。我同意这很可能是一个GPU问题。我在这篇文章中发表评论[如何验证Android移动设备是否支持GPU渲染脚本?](http://stackoverflow.com/questions/21150292/how-can- one-verify-a-android-mobile-device-supports-gpu-renderscript-or?rq = 1),但有趣的是这两款手机都使用Adreno GPU(320和420)。不过,我不确定Nexus 4是否提供GPU支持renderscript,尽管我会通过渲染速度来假设。 – Sinisa
你有“localMin = r> localMin?r:localMin;”你的代码中有两次,所以也许算法只是行为不端? –