It is unclear whether this is a bug in glslc or in SPIRV-Tools. The crash is an assertion failure inside of SPIRV-Tools, but I don't know if it is due to a bug in SPIRV-Tools or due to invalid usage of the SPIRV-Tools API.
$ glslc readback.comp -o readback.spv --target-env=vulkan1.4
glslc: /home/simon/code/shaderc/third_party/glslang/SPIRV/SpvBuilder.cpp:1728: spv::Id spv::Builder::getContainedTypeId(spv::Id, int) const: Assertion `0' failed.
Program received signal SIGABRT, Aborted.
Downloading 4.48 K source file /usr/src/debug/glibc/glibc/nptl/pthread_kill.c
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44 return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
(gdb) bt
#0 __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1 0x00007ffff789a363 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:89
#2 0x00007ffff783e7d0 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3 0x00007ffff7825681 in __GI_abort () at abort.c:77
#4 0x00007ffff7826700 in __libc_message_impl (vma_name=vma_name@entry=0x7ffff79b4883 "glibc: assert", fmt=<optimized out>)
at ../sysdeps/posix/libc_fatal.c:138
#5 0x00007ffff7836532 in __libc_message_wrapper (vmaname=0x7ffff79b4883 "glibc: assert", fmt=<optimized out>) at ../include/stdio.h:203
#6 __assert_fail (assertion=0x555555ddce19 "0", file=0x555555ddc570 "/home/simon/code/shaderc/third_party/glslang/SPIRV/SpvBuilder.cpp",
line=<optimized out>, function=<optimized out>) at assert.c:37
#7 0x0000555555787f02 in spv::Builder::getContainedTypeId (this=0x7fffffffb258, typeId=27, member=0)
at /home/simon/code/shaderc/third_party/glslang/SPIRV/SpvBuilder.cpp:1728
#8 0x00005555557880e9 in spv::Builder::getContainedTypeId (this=0x7fffffffb258, typeId=27)
at /home/simon/code/shaderc/third_party/glslang/SPIRV/SpvBuilder.cpp:1756
#9 0x00005555557363d3 in (anonymous namespace)::TGlslangToSpvTraverser::multiTypeStore (this=0x7fffffffb1f0, type=..., rValue=55)
at /home/simon/code/shaderc/third_party/glslang/SPIRV/GlslangToSpv.cpp:6654
#10 0x000055555571e4bf in (anonymous namespace)::TGlslangToSpvTraverser::visitBinary (this=0x7fffffffb1f0, node=0x55555642c960)
at /home/simon/code/shaderc/third_party/glslang/SPIRV/GlslangToSpv.cpp:2429
#11 0x0000555555805434 in glslang::TIntermBinary::traverse (this=0x55555642c960, it=0x7fffffffb1f0)
at /home/simon/code/shaderc/third_party/glslang/glslang/MachineIndependent/IntermTraverse.cpp:92
#12 0x0000555555805895 in glslang::TIntermAggregate::traverse (this=0x5555564290c0, it=0x7fffffffb1f0)
at /home/simon/code/shaderc/third_party/glslang/glslang/MachineIndependent/IntermTraverse.cpp:175
#13 0x0000555555805895 in glslang::TIntermAggregate::traverse (this=0x55555642cb80, it=0x7fffffffb1f0)
at /home/simon/code/shaderc/third_party/glslang/glslang/MachineIndependent/IntermTraverse.cpp:175
#14 0x0000555555738140 in (anonymous namespace)::TGlslangToSpvTraverser::visitFunctions (this=0x7fffffffb1f0, glslFunctions=...)
at /home/simon/code/shaderc/third_party/glslang/SPIRV/GlslangToSpv.cpp:7098
#15 0x0000555555724453 in (anonymous namespace)::TGlslangToSpvTraverser::visitAggregate (this=0x7fffffffb1f0, visit=glslang::EvPreVisit,
node=0x55555642cea0) at /home/simon/code/shaderc/third_party/glslang/SPIRV/GlslangToSpv.cpp:3347
#16 0x0000555555805734 in glslang::TIntermAggregate::traverse (this=0x55555642cea0, it=0x7fffffffb1f0)
at /home/simon/code/shaderc/third_party/glslang/glslang/MachineIndependent/IntermTraverse.cpp:159
#17 0x000055555574d5ab in glslang::GlslangToSpv (intermediate=..., spirv=std::vector of length 0, capacity 0, logger=0x7fffffffc160,
options=0x7fffffffc2d0) at /home/simon/code/shaderc/third_party/glslang/SPIRV/GlslangToSpv.cpp:12059
#18 0x000055555574d465 in glslang::GlslangToSpv (intermediate=..., spirv=std::vector of length 0, capacity 0, options=0x7fffffffc2d0)
at /home/simon/code/shaderc/third_party/glslang/SPIRV/GlslangToSpv.cpp:12041
#19 0x00005555555fe6d5 in shaderc_util::Compiler::Compile (this=0x555556242978, input_source_string=..., forced_shader_stage=EShLangCount,
error_tag="readback.comp", entry_point_name=0x555556242ea8 "main", stage_callback=..., includer=...,
output_type=shaderc_util::Compiler::OutputType::SpirvBinary, error_stream=0x7fffffffc8a0, total_warnings=0x7fffffffc750, total_errors=0x7fffffffc758)
at /home/simon/code/shaderc/libshaderc_util/src/compiler.cc:363
#20 0x00005555556124e9 in (anonymous namespace)::CompileToSpecifiedOutputType (compiler=0x5555562428e0,
source_text=0x555556245750 "#version 460\n#extension GL_EXT_descriptor_heap : require\n#extension GL_EXT_nonuniform_qualifier : require\n\nlayout(row_major) uniform;\nlayout(row_major) buffer;\n\nstruct Output_0\n{\n int z_0;\n};\n\nlayo"..., source_text_size=1059,
shader_kind=shaderc_glsl_default_compute_shader, input_file_name=0x555556242e80 "readback.comp", entry_point_name=0x555556242ea8 "main",
additional_options=0x555556242970, output_type=shaderc_util::Compiler::OutputType::SpirvBinary)
at /home/simon/code/shaderc/libshaderc/src/shaderc.cc:638
#21 0x00005555556128e8 in shaderc_compile_into_spv (compiler=0x5555562428e0,
source_text=0x555556245750 "#version 460\n#extension GL_EXT_descriptor_heap : require\n#extension GL_EXT_nonuniform_qualifier : require\n\nlayout(row_major) uniform;\nlayout(row_major) buffer;\n\nstruct Output_0\n{\n int z_0;\n};\n\nlayo"..., source_text_size=1059,
shader_kind=shaderc_glsl_default_compute_shader, input_file_name=0x555556242e80 "readback.comp", entry_point_name=0x555556242ea8 "main",
additional_options=0x555556242970) at /home/simon/code/shaderc/libshaderc/src/shaderc.cc:685
#22 0x00005555555f2026 in shaderc::Compiler::CompileGlslToSpv (this=0x7fffffffd350,
source_text=0x555556245750 "#version 460\n#extension GL_EXT_descriptor_heap : require\n#extension GL_EXT_nonuniform_qualifier : require\n\nlayout(row_major) uniform;\nlayout(row_major) buffer;\n\nstruct Output_0\n{\n int z_0;\n};\n\nlayo"..., source_text_size=1059,
shader_kind=shaderc_glsl_default_compute_shader, input_file_name=0x555556242e80 "readback.comp", entry_point_name=0x555556242ea8 "main", options=...)
at /home/simon/code/shaderc/libshaderc/include/shaderc/shaderc.hpp:432
#23 0x00005555555f0ba8 in glslc::FileCompiler::CompileShaderFile (this=0x7fffffffd350, input_file=...)
at /home/simon/code/shaderc/glslc/src/file_compiler.cc:119
#24 0x00005555555ebc14 in main (argc=5, argv=0x7fffffffda28) at /home/simon/code/shaderc/glslc/src/main.cc:706
Simple compute shader (adapted from Slang's GLSL output to use
GL_EXT_descriptor_heapcauses a glslc to segfault in release mode, and to hit an assertion in debug builds.It is unclear whether this is a bug in glslc or in SPIRV-Tools. The crash is an assertion failure inside of SPIRV-Tools, but I don't know if it is due to a bug in SPIRV-Tools or due to invalid usage of the SPIRV-Tools API.
Reproduction
readback.comp:
Compile with:
Running the same command under GDB yields the following output: