草庐IT

android - 没有 rsDebug,RenderScript 代码无法工作

coder 2023-12-16 原文

我对 RenderScript 完全陌生。我试图获得 Romain Guy 在 http://www.youtube.com/watch?v=5jz0kSuR2j4 中展示的一个简单示例工作。

首先,这是代码。

主要 Activity .java

    package com.example.rsgray;

    import android.app.Activity;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.Bundle;
    import android.renderscript.Allocation;
    import android.renderscript.RenderScript;
    import android.view.Window;
    import android.view.WindowManager;
    import android.widget.ImageView;
    import android.widget.ImageView.ScaleType;

    public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    ImageView iv = new ImageView(this);
    iv.setScaleType(ScaleType.CENTER_CROP);
    setContentView(iv);

    drawGrayScale(iv, R.drawable.tulips);
}

private void drawGrayScale(ImageView iv, int image) {
    Bitmap in = BitmapFactory.decodeResource(getResources(), image);
    Bitmap out = Bitmap.createBitmap(in.getWidth(), in.getHeight(), in.getConfig());

    RenderScript rs = RenderScript.create(MainActivity.this);
    Allocation inAlloc = Allocation.createFromBitmap(rs, in);
    Allocation outAlloc = Allocation.createTyped(rs, inAlloc.getType());

    ScriptC_gray script = new ScriptC_gray(rs, getResources(), R.raw.gray);
    script.set_in(inAlloc);
    script.set_out(outAlloc);
    script.set_script(script);

    script.invoke_filter();

    outAlloc.copyTo(out);
    iv.setImageBitmap(out);
}

灰色.rs

    #pragma version(1)
    #pragma rs java_package_name(com.example.rsgray)
    #pragma rs_fp_relaxed

    rs_allocation in;
    rs_allocation out;
    rs_script script;

    const static float3 gray = { 0.3f, 0.6f, 0.1f };

    void root(const uchar4* v_in, uchar4* v_out, const void* usrData, uint32_t x, uint32_t y) {
        rsDebug("gray.rs", rsUptimeMillis());
        float4 inPixel = rsUnpackColor8888(*v_in);
        float3 result = dot(inPixel.rgb, gray);
        *v_out = rsPackColorTo8888(result);
    }


    void filter() {
        rsForEach(script, in, out);
    }

最后是 AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rsgray"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="16" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.rsgray.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

res/drawable-nodpi 包含 tulips.jpg。您不会在 Romain Guy 的代码中找到我在 gray.rs 中添加的 rsDebug() 语句。

无论如何,无论是否使用 rsDebug(),代码都会编译。但是,当我尝试在设备上运行该应用程序时,问题就出现了。

我尝试在运行 Android 4.4 的 Nexus 4 上运行该应用程序。使用如图所示的代码,它工作正常,我得到了一个灰度图像。但是,如果我注释掉 rsDebug() 行,应用程序将无法运行。我只是黑屏。

这是 logcat 输出。

  1. 使用 rsDebug() :

    11-26 16:22:41.563: D/dalvikvm(21523): GC_FOR_ALLOC freed 69K, 2% free 9046K/9148K, paused 16ms, total 16ms
    11-26 16:22:41.573: I/dalvikvm-heap(21523): Grow heap (frag case) to 11.862MB for 3145744-byte allocation
    11-26 16:22:41.603: D/dalvikvm(21523): GC_FOR_ALLOC freed <1K, 1% free 12118K/12224K, paused 30ms, total 30ms
    11-26 16:22:41.683: D/dalvikvm(21523): GC_FOR_ALLOC freed <1K, 1% free 12117K/12224K, paused 11ms, total 11ms
    11-26 16:22:41.693: I/dalvikvm-heap(21523): Grow heap (frag case) to 14.862MB for 3145744-byte allocation
    11-26 16:22:41.703: D/dalvikvm(21523): GC_FOR_ALLOC freed 0K, 1% free 15189K/15300K, paused 14ms, total 14ms
    11-26 16:22:41.753: V/RenderScript(21523): 0x74ed5020 Launching thread(s), CPUs 4
    11-26 16:22:41.753: W/Adreno-RS(21523): <rsdVendorAllocationDestroyQCOM:194>: rsdVendorAllocationDestroy: No context!
    11-26 16:22:41.753: E/RenderScript(21523): Successfully loaded runtime: libRSDriver_adreno.so
    11-26 16:22:41.783: D/dalvikvm(21523): GC_FOR_ALLOC freed <1K, 1% free 15201K/15300K, paused 11ms, total 11ms
    11-26 16:22:41.803: D/dalvikvm(21523): GC_FOR_ALLOC freed <1K, 1% free 15202K/15300K, paused 11ms, total 12ms
    11-26 16:22:41.813: W/Adreno-RS(21523): <rsdCompileBitcode:289>: Header check (bitcode_SHA1) failed for /data/data/com.example.rsgray/cache/com.android.renderscript.cache/gray-adreno.meta
    11-26 16:22:41.813: W/Adreno-RS(21523): <rsdDumpCompileLog:499>: Build log for gray: RS code uses long(i64) data type
    11-26 16:22:41.813: W/Adreno-RS(21523): RS bitcode does not contain an invokable compute root
    11-26 16:22:41.813: W/Adreno-RS(21523): <rsdVendorScriptInitQCOM:610>: ERROR: __BuildProgram returned -11
    11-26 16:22:41.813: D/RenderScript(21523): long gray.rs 18142906  0x114d6ba
    11-26 16:22:41.813: D/RenderScript(21523): long gray.rs 18142906  0x114d6ba
    11-26 16:22:41.813: D/RenderScript(21523): long gray.rs 18142906  0x114d6ba
    11-26 16:22:41.813: D/RenderScript(21523): long gray.rs 18142906  0x114d6ba
    .
    . a million more such lines
    .
    11-26 16:22:44.686: D/RenderScript(21523): long gray.rs 18145771  0x114e1eb
    11-26 16:22:44.686: D/RenderScript(21523): long gray.rs 18145771  0x114e1eb
    11-26 16:22:44.686: D/RenderScript(21523): long gray.rs 18145771  0x114e1eb
    11-26 16:22:44.686: D/RenderScript(21523): long gray.rs 18145771  0x114e1eb
    11-26 16:22:44.717: I/Adreno-EGL(21523): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM build:  (CL3776187)
    11-26 16:22:44.717: I/Adreno-EGL(21523): OpenGL ES Shader Compiler Version: 
    11-26 16:22:44.717: I/Adreno-EGL(21523): Build Date: 10/15/13 Tue
    11-26 16:22:44.717: I/Adreno-EGL(21523): Local Branch: 
    11-26 16:22:44.717: I/Adreno-EGL(21523): Remote Branch: partner/upstream
    11-26 16:22:44.717: I/Adreno-EGL(21523): Local Patches: 
    11-26 16:22:44.717: I/Adreno-EGL(21523): Reconstruct Branch: 
    11-26 16:22:44.747: D/OpenGLRenderer(21523): Enabling debug mode 0
    
  2. 没有 rsDebug() :

    11-26 16:23:41.327: D/dalvikvm(21902): GC_FOR_ALLOC freed 56K, 1% free 9046K/9136K, paused 18ms, total 18ms
    11-26 16:23:41.337: I/dalvikvm-heap(21902): Grow heap (frag case) to 11.862MB for 3145744-byte allocation
    11-26 16:23:41.367: D/dalvikvm(21902): GC_FOR_ALLOC freed <1K, 1% free 12118K/12212K, paused 27ms, total 27ms
    11-26 16:23:41.427: D/dalvikvm(21902): GC_FOR_ALLOC freed <1K, 1% free 12117K/12212K, paused 11ms, total 11ms
    11-26 16:23:41.437: I/dalvikvm-heap(21902): Grow heap (frag case) to 14.862MB for 3145744-byte allocation
    11-26 16:23:41.447: D/dalvikvm(21902): GC_FOR_ALLOC freed 0K, 1% free 15189K/15288K, paused 12ms, total 12ms
    11-26 16:23:41.477: V/RenderScript(21902): 0x74ed4f18 Launching thread(s), CPUs 4
    11-26 16:23:41.477: W/Adreno-RS(21902): <rsdVendorAllocationDestroyQCOM:194>: rsdVendorAllocationDestroy: No context!
    11-26 16:23:41.477: E/RenderScript(21902): Successfully loaded runtime: libRSDriver_adreno.so
    11-26 16:23:41.507: D/dalvikvm(21902): GC_FOR_ALLOC freed <1K, 1% free 15201K/15288K, paused 12ms, total 13ms
    11-26 16:23:41.527: D/dalvikvm(21902): GC_FOR_ALLOC freed <1K, 1% free 15202K/15288K, paused 12ms, total 12ms
    11-26 16:23:41.537: D/bcc(21902): Cache /data/data/com.example.rsgray/cache/com.android.renderscript.cache/gray.o.info is dirty due to the source it dependends on has been changed:
    11-26 16:23:43.419: I/Adreno-EGL(21902): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM build:  (CL3776187)
    11-26 16:23:43.419: I/Adreno-EGL(21902): OpenGL ES Shader Compiler Version: 
    11-26 16:23:43.419: I/Adreno-EGL(21902): Build Date: 10/15/13 Tue
    11-26 16:23:43.419: I/Adreno-EGL(21902): Local Branch: 
    11-26 16:23:43.419: I/Adreno-EGL(21902): Remote Branch: partner/upstream
    11-26 16:23:43.419: I/Adreno-EGL(21902): Local Patches: 
    11-26 16:23:43.419: I/Adreno-EGL(21902): Reconstruct Branch: 
    11-26 16:23:43.449: D/OpenGLRenderer(21902): Enabling debug mode 0
    

我无法理解调试语句如何影响应用程序的运行方式。任何关于我为什么会遇到这个问题的帮助将不胜感激。

这就是我的问题的第一部分。

第二部分:当我尝试在运行 Android 4.1.2 的 Galaxy Note 10.1 N8013 和另一台同样运行 Android 4.1.2 的 APQ8064 硬件上运行完全相同的代码时,应用程序无法运行。

这是我的硬件的 logcat 输出:

    01-02 00:00:51.043: E/Trace(1684): error opening trace file: No such file or directory (2)
    01-02 00:00:51.043: D/ActivityThread(1684): setTargetHeapUtilization:0.25
    01-02 00:00:51.043: D/ActivityThread(1684): setTargetHeapIdealFree:8388608
    01-02 00:00:51.053: D/ActivityThread(1684): setTargetHeapConcurrentStart:2097152
    01-02 00:00:51.183: V/RenderScript(1684): rsContextCreate dev=0x7276fdd0
    01-02 00:00:51.183: V/RenderScript(1684): 0x616350e0 Launching thread(s), CPUs 4
    01-02 00:00:51.203: V/ScriptC(1684): Create script for resource = gray
    01-02 00:00:51.203: E/bcc(1684): CPU is krait2
    01-02 00:00:51.274: W/bcc(1684): Unable to open /data/data/com.example.rsgray/cache/com.android.renderscript.cache/gray.o in read mode.  (reason: No such file or directory)
    01-02 00:00:51.404: A/libc(1684): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 1701 (.example.rsgray)

最后,这是三星平板电脑的 logcat 输出:

    01-02 10:34:47.470: D/dalvikvm(19022): GC_FOR_ALLOC freed 48K, 11% free 7046K/7875K, paused 13ms, total 13ms
    01-02 10:34:47.475: I/dalvikvm-heap(19022): Grow heap (frag case) to 10.495MB for 3145744-byte allocation
    01-02 10:34:47.495: D/dalvikvm(19022): GC_CONCURRENT freed <1K, 9% free 10117K/11015K, paused 11ms+1ms, total 18ms
    01-02 10:34:47.585: D/dalvikvm(19022): GC_FOR_ALLOC freed <1K, 9% free 10117K/11015K, paused 10ms, total 10ms
    01-02 10:34:47.590: I/dalvikvm-heap(19022): Grow heap (frag case) to 13.494MB for 3145744-byte allocation
    01-02 10:34:47.610: D/dalvikvm(19022): GC_CONCURRENT freed <1K, 7% free 13189K/14151K, paused 11ms+3ms, total 23ms
    01-02 10:34:47.610: D/dalvikvm(19022): WAIT_FOR_CONCURRENT_GC blocked 12ms
    01-02 10:34:47.610: V/RenderScript(19022): rsContextCreate dev=0x40e3b288
    01-02 10:34:47.615: V/RenderScript(19022): 0x411e3008 Launching thread(s), CPUs 3
    01-02 10:34:47.625: V/ScriptC(19022): Create script for resource = gray
    01-02 10:34:47.625: I/bcc(19022): LIBBCC build time: 2013/01/09 23:19:52
    01-02 10:34:47.625: I/bcc(19022): LIBBCC build revision: Unknown (not git)
    01-02 10:34:47.645: D/StopWatch(19022): StopWatch calcFileSHA1 time (us): 17719 
    01-02 10:34:47.650: D/StopWatch(19022): StopWatch calcFileSHA1 time (us): 3031 
    01-02 10:34:47.650: W/bcc(19022): Unable to open file in read mode.  (reason: No such file or directory)
    01-02 10:34:47.750: A/libc(19022): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 19053 (.example.rsgray)

就是这样。如果有人知道如何解释这一点,请告诉我。

谢谢!

最佳答案

我刚遇到同样的问题。当 rsDebug 位于同一函数的某处时,它似乎已修复。这为我修好了:

if(x > 0) {
    if(x < 0) {
        rsDebug("Workaround for renderscript bug", 0.0f);
    }

    /* Code */
}

使用它,rsDebug 从未真正被调用,所以它不会输出任何东西。

注意这不起作用:

if(0) {
    rsDebug("Workaround for renderscript bug", 0.0f);
}

这可能被优化掉了。

关于android - 没有 rsDebug,RenderScript 代码无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20216172/

有关android - 没有 rsDebug,RenderScript 代码无法工作的更多相关文章

  1. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  2. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  3. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  4. ruby - 难道Lua没有和Ruby的method_missing相媲美的东西吗? - 2

    我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/

  5. ruby-on-rails - Rails 源代码 : initialize hash in a weird way? - 2

    在rails源中:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb可以看到以下内容@load_hooks=Hash.new{|h,k|h[k]=[]}在IRB中,它只是初始化一个空哈希。和做有什么区别@load_hooks=Hash.new 最佳答案 查看rubydocumentationforHashnew→new_hashclicktotogglesourcenew(obj)→new_has

  6. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  7. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  8. ruby-on-rails - rails 目前在重启后没有安装 - 2

    我有一个奇怪的问题:我在rvm上安装了ruby​​onrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(

  9. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  10. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

随机推荐