我试图在运行时使用shaderc将glsl着色器编译成spir。这个库在桌面win32应用程序上运行良好,但是当我尝试使用VisualStudio2017在android上移动它时,如果着色器没有编译错误,它就会崩溃。我在NVIDIA屏蔽平板电脑上测试。
这是崩溃代码的一个版本:
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" );
}用这个逻辑猫:
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显示分段错误。如果我在没有CompileGlslToSpvAssembly的情况下编写并尝试使用CompileGlslToSpv,那么在创建vulkan着色器模块时就会出现分割错误错误,而不需要任何logcat中的任何内容。
我试着用:
发布于 2017-08-29 15:36:59
这里的问题似乎是,Vulkan验证层,特别是libVkLayer_core_validation.so,正在从其内部版本的螺旋工具导出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中的二进制文件似乎比较旧,但是您应该能够从源构建新的二进制文件。
https://stackoverflow.com/questions/45924342
复制相似问题