Skip to content

glslc segfaults on simple GL_EXT_descriptor_heap compute shader #1559

Description

@simonask

Simple compute shader (adapted from Slang's GLSL output to use GL_EXT_descriptor_heap causes 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:

#version 460
#extension GL_EXT_descriptor_heap : require
#extension GL_EXT_nonuniform_qualifier : require

layout(row_major) uniform;
layout(row_major) buffer;

struct Output_0
{
    int z_0;
};

layout(descriptor_heap) buffer StructuredBuffer_Output_t_0 {
    Output_0 _data[];
} _slang_resource_heap_0[];

struct Input_0
{
    int x_0;
    int y_0;
};

layout(descriptor_heap) readonly buffer StructuredBuffer_Input_t_0 {
    Input_0 _data[];
} _slang_resource_heap_1[];

struct EntryPointParams_0
{
    uvec2 input_buffer_0;
    uvec2 output_buffer_0;
};

layout(push_constant)
layout(std430) uniform block_EntryPointParams_0
{
    uvec2 input_buffer_0;
    uvec2 output_buffer_0;
} entryPointParams_0;

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main()
{
    Input_0 input_0 = _slang_resource_heap_1[entryPointParams_0.input_buffer_0.x]._data[uint(0)];
    Output_0 output_0;
    output_0.z_0 = input_0.x_0 + input_0.y_0;
    _slang_resource_heap_0[entryPointParams_0.output_buffer_0.x]._data[uint(0)] = output_0;
    return;
}

Compile with:

$ glslc readback.comp -o readback.spv --target-env=vulkan1.4

Running the same command under GDB yields the following output:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions