glslang icon indicating copy to clipboard operation
glslang copied to clipboard

Automatic source code addition

Open ubitux opened this issue 2 years ago • 0 comments

I was trying to build SPIRV bytecode with symbols using the C API:

    const glslang_input_t glslc_input = {
        .language                          = GLSLANG_SOURCE_GLSL,
        .stage                             = stages[stage],
        .client                            = GLSLANG_CLIENT_VULKAN,
        .client_version                    = GLSLANG_TARGET_VULKAN_1_1,
        .target_language_version           = GLSLANG_TARGET_SPV_1_3,
        .target_language                   = GLSLANG_TARGET_SPV,
        .code                              = src,
        .default_version                   = 450,
        .default_profile                   = GLSLANG_NO_PROFILE,
        .force_default_version_and_profile = false,
        .forward_compatible                = false,
        .messages                          = GLSLANG_MSG_DEFAULT_BIT,
        .resource                          = glslang_default_resource(),
    };

    glslang_shader_t *shader = glslang_shader_create(&glslc_input);
    if (!shader)
        return NGL_ERROR_MEMORY;

    /* ... */

    glslang_spv_options_t options = { // XXX why not const?
        .generate_debug_info = true,
        .strip_debug_info = false,
        .disable_optimizer = true,
        .optimize_size = false,
        .disassemble = false,
        .validate = true,
        .emit_nonsemantic_shader_debug_info = true,
        .emit_nonsemantic_shader_debug_source = true,
    };
    glslang_program_SPIRV_generate_with_options(program, glslc_input.stage, &options);

But to make this work, I also had to add the following before generating the SPIRV:

glslang_program_add_source_text(program, glslc_input.stage, glslc_input.code, strlen(glslc_input.code))

This shouldn't be necessary:

  1. We already specified the code in glslang_shader_create()
  2. We used 4 different explicit options saying we wanted the debug inside the SPIRV:
    • generate_debug_info = true
    • strip_debug_info = false
    • emit_nonsemantic_shader_debug_info = true
    • emit_nonsemantic_shader_debug_source = true

glslang should have enough information to include the code already; I don't see why anyone would not want the symbols in this situation.

ubitux avatar Jul 01 '23 10:07 ubitux