2017-08-28 59 views
0

我试图在运行时使用shaderc编译glsl着色器来spir-v。该库在桌面win32应用程序上运行良好,但是当我尝试在使用V​​isual Studio 2017的android上移动它时,如果着色器没有编译错误,它会崩溃。我正在测试NVIDIA屏蔽平板电脑。Shaderc在调用glsl时崩溃android上的spv程序集

这是代码的版本的崩溃之一:

void android_main(struct android_app* state) 
{ 
    shaderc::Compiler compiler; 
    shaderc::CompileOptions options; 
    char test_program[] = "#version 450 \n void main() { gl_Position = vec4(0.0f, 0.0f, 0.0f, 0.0f);}";  
    shaderc::AssemblyCompilationResult assembly = 
     compiler.CompileGlslToSpvAssembly(test_program, strlen(test_program), 
              shaderc_glsl_vertex_shader, "shader", "main", options); 

    if(assembly.GetCompilationStatus() != shaderc_compilation_status_success) 
     LOGI(assembly.GetErrorMessage().c_str()); 

    std::string resultAssembly(assembly.cbegin(), assembly.cend()); 
    for(int i = 0; i < resultAssembly.length(); i++) 
    { 
     int newline = resultAssembly.find_first_of('\n', i); 
     newline = newline != -1 ? newline : resultAssembly.length(); 
     LOGI("%s", resultAssembly.substr(i, newline - i).c_str()); 
     i = newline; 
    } 

    compiler.CompileGlslToSpv(test_program, strlen(test_program), 
           shaderc_glsl_vertex_shader, "shader"); 
} 

有了这个logcat的:

08-28 22:36:38.431 5450 5484 F libc : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x48 in tid 5484 (m.AndroidEngine) 
08-28 22:36:38.432 5450 5458 I art  : Starting a blocking GC Instrumentation 
08-28 22:36:38.434 183 183 W   : debuggerd: handling request: pid=5450 uid=10154 gid=10154 tid=5484 
08-28 22:36:38.548 5487 5487 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 
08-28 22:36:38.550 5487 5487 F DEBUG : Build fingerprint: 'nvidia/wx_un_do/shieldtablet:7.0/NRD90M/1928188_904.2811:user/release-keys' 
08-28 22:36:38.550 5487 5487 F DEBUG : Revision: '0' 
08-28 22:36:38.551 5487 5487 F DEBUG : ABI: 'arm' 
08-28 22:36:38.552 5487 5487 F DEBUG : pid: 5450, tid: 5484, name: m.AndroidEngine >>> com.AndroidEngine <<< 
08-28 22:36:38.553 5487 5487 F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x48 
08-28 22:36:38.553 5487 5487 F DEBUG :  r0 95642fe0 r1 00000002 r2 95ae6428 r3 9564201c 
08-28 22:36:38.554 5487 5487 F DEBUG :  r4 95641f60 r5 95642fe0 r6 00000048 r7 956416e0 
08-28 22:36:38.555 5487 5487 F DEBUG :  r8 00000002 r9 00000000 sl 00000005 fp fffffcb8 
08-28 22:36:38.556 5487 5487 F DEBUG :  ip 0000002e sp 956416c0 lr 95ae63bb pc 00000048 cpsr 200f0010 
08-28 22:36:38.578 5487 5487 F DEBUG : 
08-28 22:36:38.578 5487 5487 F DEBUG : backtrace: 
08-28 22:36:38.579 5487 5487 F DEBUG :  #00 pc 00000048 <unknown> 
08-28 22:36:38.579 5487 5487 F DEBUG :  #01 pc 0017b3b9 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (_ZN8libspirv16DiagnosticStreamD2Ev+84) 
08-28 22:36:38.579 5487 5487 F DEBUG :  #02 pc 00159a2d /data/app/com.AndroidEngine-1/lib/arm/libVkLayer_core_validation.so (spvBinaryParse+5248) 
08-28 22:36:38.580 5487 5487 F DEBUG :  #03 pc 00194065 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (_ZN8libspirv18FriendlyNameMapperC1EPK13spv_context_tPKjj+124) 
08-28 22:36:38.580 5487 5487 F DEBUG :  #04 pc 0017a697 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (spvBinaryToText+174) 
08-28 22:36:38.580 5487 5487 F DEBUG :  #05 pc 0017a463 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (_ZNK8spvtools10SpirvTools11DisassembleEPKjjPSsj+38) 
08-28 22:36:38.581 5487 5487 F DEBUG :  #06 pc 0017a435 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (_ZNK8spvtools10SpirvTools11DisassembleERKSt6vectorIjSaIjEEPSsj+24) 
08-28 22:36:38.581 5487 5487 F DEBUG :  #07 pc 0014d1e9 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (_ZN12shaderc_util21SpirvToolsDisassembleENS_8Compiler9TargetEnvERKSt6vectorIjSaIjEEPSs+96) 
08-28 22:36:38.581 5487 5487 F DEBUG :  #08 pc 0014e013 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (_ZNK12shaderc_util8Compiler7CompileERKNS_12string_pieceE11EShLanguageRKSsPKcRKSt8functionIFS4_PSoS3_EERNS_16CountingIncluderENS0_10OutputTypeESA_PjSI_PNS_18GlslangInitializerE+1246) 
08-28 22:36:38.581 5487 5487 F DEBUG :  #09 pc 000d34bf /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so 
08-28 22:36:38.582 5487 5487 F DEBUG :  #10 pc 000d3793 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (shaderc_compile_into_spv_assembly+22) 
08-28 22:36:38.582 5487 5487 F DEBUG :  #11 pc 000c4167 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (_ZNK7shaderc8Compiler24CompileGlslToSpvAssemblyEPKcj19shaderc_shader_kindS2_S2_RKNS_14CompileOptionsE+42) 
08-28 22:36:38.582 5487 5487 F DEBUG :  #12 pc 000c3ce1 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (android_main+120) 
08-28 22:36:38.582 5487 5487 F DEBUG :  #13 pc 000d1219 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so 
08-28 22:36:38.583 5487 5487 F DEBUG :  #14 pc 000475c3 /system/lib/libc.so (_ZL15__pthread_startPv+22) 
08-28 22:36:38.583 5487 5487 F DEBUG :  #15 pc 0001a115 /system/lib/libc.so (__start_thread+6) 
08-28 22:36:39.012 5487 5487 E   : debuggerd: failed to kill process 5450: No such process 
08-28 22:36:39.014 183 183 W   : debuggerd: resuming target 5450 

目前没有任何崩溃,如果着色器编译错误:程序只是打印编译错误信息。 Visual Studio显示分段错误错误。 如果我编写时没有CompileGlslToSpvAssembly,并尝试使用CompileGlslToSpv,那么在创建vulkan着色器模块时没有logcat中的任何内容会出现分段错误错误。

我试着使用:

  1. 从GitHub库中的最新shaderc代码NDK R13B,R14B,r15b命令行通过NDK,球泡建造(也带有链接在Visual Studio中的参数NDK目录)

  2. shaderc在ndk r13b和r14b的第三方子目录中提供。如在NDK FAQ所示BULDING:

    Ndk_path/NDK-build.cmd”。-B NDK_PROJECT_PATH = APP_BULD_SCRIPT = Android.mk APP_STL = gnustl_static APP_ABI = armeabi-V7A APP_PLATFORM =机器人-24 ANDROID_CPP_FEATURES = “例外” libshaderc_combined

回答

0

它看起来像这里的问题是,福尔康验证层,特别是libVkLayer_core_validation.so是从spirv工具的内部版本出口spvBinaryParse,这与版本冲突是shaderc与建造。

08-28 22:36:38.579 5487 5487 F DEBUG :  #01 pc 0017b3b9 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (_ZN8libspirv16DiagnosticStreamD2Ev+84) 
08-28 22:36:38.579 5487 5487 F DEBUG :  #02 pc 00159a2d /data/app/com.AndroidEngine-1/lib/arm/libVkLayer_core_validation.so (spvBinaryParse+5248) 
08-28 22:36:38.580 5487 5487 F DEBUG :  #03 pc 00194065 /data/app/com.AndroidEngine-1/lib/arm/libAndroidEngine.so (_ZN8libspirv18FriendlyNameMapperC1EPK13spv_context_tPKjj+124) 

解决这个问题的方法是在您的apk中不包含验证图层。但是,这当然意味着你没有得到验证。

看起来这已经在官方存储库中修复了。 https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers

NDK中的二进制文件看起来较旧,但您应该可以从源代码构建新文件。

+0

非常感谢!它现在运作良好。这是否意味着无法使用运行时着色器编译使用验证图层?至少现在呢? –

+0

已更新的答案指向固定的验证图层源。 – awoloszyn