KhronosGroup / KhronosGroup/glslang

-gVS drops DebugSource for included files when the include contributes only macros or otherwise unused code

Open
#4,219 1 comment 0 reactions 0 assignees View on GitHub
ShaderDebugInfo
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

### Description
When compiling with `-gVS`, include files can be omitted from `NonSemantic.Shader.DebugInfo.100` source records if they are not referenced by any DebugLine or variable/type declaration. This happens with headers that contain only macros or helper functions that are never used by the main shader. This is not an issue when compiling with `-g`, where every include file has an `OpSource` regardless of usage.

### Motivation
I am trying to use non semantic debug info to re-compile shaders. This fails when the source for some include files is missing.

### Expected Behavior
I would expect a `DebugSource` record to be emitted for each non-empty included file known to the compiler.

### Simple Repro
test.frag:
```
#version 450
#extension GL_GOOGLE_include_directive : enable

#include "utils.glsl"

layout(location = 0) out vec4 fragColor;

void main() {
fragColor = vec4(COLOR_R, COLOR_G, 0, 0);
}
```
utils.glsl:
```
#include "constants.h"

float unused_luminance(in vec3 color)
{
return dot(color, vec3(LUMINANCE_R, LUMINANCE_G, LUMINANCE_B));
}
```
constants.h:
```
#define COLOR_R 0.0
#define COLOR_G 1.0

#define LUMINANCE_R 0.299
#define LUMINANCE_G 0.587
#define LUMINANCE_B 0.114
```
Compile with:
`glslang -V -gVS -o test.spv test.frag`

Observe that only `test.frag` has `DebugSource`. Change `-gVS` to `-g` and observe that every file now has `OpSource`.

### Possible Approach
Looking at `SpvBuilder.cpp`, I can see that `Builder::dumpSourceInstructions` loops through all include files and emits source records for the `-g` case. However, in the `-gVS` case, `Builder::makeDebugCompilationUnit` and `Builder::makeDebugSource` lazily emit debug source records only when a debug record refers to that file. Since `makeDebugSource` already guards against duplicates, it seems like a loop over all the include in the non semantic case could work.

Contributor guide

Open the contributing guide

Research direction

Start in SpvBuilder.cpp, comparing dumpSourceInstructions with the lazy makeDebugCompilationUnit and makeDebugSource paths used for -gVS. Run the provided test.frag, utils.glsl, and constants.h reproduction with -gVS and -g, then inspect the generated source records. Done means every non-empty included file receives a DebugSource record under -gVS, including unused macro-only or helper-code files.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.