简体   繁体   English

Renderscript Image Processign Nexus 6棉花糖问题

[英]Renderscript image processign Nexus 6 Marshmallow issue

I am using renderscript for live image processing (camera preview). 我正在使用renderscript进行实时图像处理(相机预览)。 I am having an issue on Nexus 6 Marshmallow 6.1 where some of my scripts won't run for more than a couple of frames (rs kernel runs). 我在Nexus 6棉花糖6.1上遇到问题,我的某些脚本无法运行超过两帧(rs内核运行)。 Those same scripts work flawlessly on Nexus 4 Lollipop 5.1. 这些相同的脚本可以在Nexus 4 Lollipop 5.1上完美运行。

Symptoms: Script works for several runs (builds). 症状:脚本可以运行几次(构建)。 On an nth run some script ceases to work as expected and all subsequent runs exhibit the above issue. 在第n次运行中,某些脚本会按预期停止运行,并且所有后续运行均出现上述问题。 I haven't been able to establish some particular operation in code which causes the issue. 我无法在导致问题的代码中建立某些特定的操作。 It appears completely random, at least from what I can gather. 看来是完全随机的,至少从我的收集中可以看出。

What iv'e tried: 我尝试过的是:

  • Rebooting phone, uninstalling app, cleaning the projects, invalidating caches in Android Studio produce no results. 重新启动手机,卸载应用程序,清理项目,使Android Studio中的缓存无效均不会产生任何结果。
  • Adding rsDebug() per this post: 每个帖子添加rsDebug()
    RenderScript code not working without rsDebug seemed to have fixed the problem, but after a few builds problem reappeared. RenderScript代码在没有rsDebug的情况下无法正常工作,似乎已解决了该问题,但是经过几次构建后,问题再次出现。
  • Adding rsDebug() in code and actually logging appears to run the script as intended, but needless to say this is no solution since it slows the scripts down to a halt. 在代码中添加rsDebug()并实际记录日志似乎可以按预期运行脚本,但是不用说,这不是解决方案,因为它会使脚本减速到停止状态。
  • Removing #pragma rs_fp_relaxed seemed to have fixed the problem, but after a few builds problem reappeared. 删除#pragma rs_fp_relaxed似乎已解决了该问题,但经过几次构建后,问题再次出现。
  • adb shell setprop debug.rs.default-CPU-driver 1 fixes the problem, but the whole point of using renderscript was to utilize heterogeneous computing adb shell setprop debug.rs.default-CPU-driver 1解决了该问题,但是使用renderscript的全部目的是利用异构计算

I am using this kernel signature uchar4 __attribute__((kernel)) filter(uchar4 v_in, uint32_t x, uint32_t y) , although RS_KERNEL causes the same issue. 我正在使用此内核签名uchar4 __attribute__((kernel)) filter(uchar4 v_in, uint32_t x, uint32_t y) ,尽管RS_KERNEL会引起相同的问题。

Thanks for any help and ideas. 感谢您的帮助和想法。

Sample of affected code: (Google demo code from here: https://android.googlesource.com/platform/frameworks/rs/+/master/java/tests/ImageProcessing2/src/com/android/rs/image/ ) 受影响的代码示例:(来自此处的Google演示代码: 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);
}

Can you double check the image you are writing to is not looking at the alpha channel or try to set it explicitly. 您能否再次检查正在写入的图像而不是在Alpha通道中查看或尝试对其进行显式设置。 (This is more of a comment, but I don't have enough points) (这更多是评论,但我的观点不够多)

After quite a bit of research I decided that this is most probably a GPU driver issue. 经过大量研究,我认为这很可能是GPU驱动程序问题。 Having said that, I mentioned above that I tried removing #pragma rs_fp_relaxed which appeared to have solved the problem temporarily. 话虽如此,我在上面提到我尝试删除似乎暂时解决了该问题的#pragma rs_fp_relaxed I now believe that it was a gamble with the choice of fp precision RS was using and that that was the reason it sometimes worked and sometimes not. 我现在认为,选择RS使用fp precision是一场赌博,这就是它有时起作用而有时不起作用的原因。 I came to this conclusion when i explicitly set #pragma rs_fp_full which seems to have fixed the issue permanently since it, along with native functions, should be a hardware backed calculation (so far works for all scripts that caused problems on Nexus 6). 当我显式设置#pragma rs_fp_full时,我得出了这个结论,由于它与native函数一起应该是硬件支持的计算,因此似乎永久地解决了该问题(到目前为止,所有在Nexus 6上引起问题的脚本都可以使用)。

I found a few cases on the web with people solving RS issues by flashing new drivers, but this is unacceptable for me. 我在网上发现了一些案例,人们通过刷新新驱动程序解决了RS问题,但这对我来说是不可接受的。

To recap: I explicitly set #pragma rs_fp_full . 回顾一下:我显式设置了#pragma rs_fp_full

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM