KhronosGroup / KhronosGroup/glslang

Automatic source code addition

Open
#3,252 0 comments 3 reactions 0 assignees View on GitHub
enhancement SPIR-V
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

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

```c
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:
```c
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.

Contributor guide

Open the contributing guide

Research direction

Start with the C API path from glslang_shader_create() through glslang_program_SPIRV_generate_with_options(), comparing it with glslang_program_add_source_text(). Determine whether source text supplied at shader creation is retained for debug-source emission, and verify that enabled debug options produce the source without the extra call using an existing SPIR-V generation test or a focused regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.