KhronosGroup / KhronosGroup/glslang
SpvBuilder creating debug instructions with invalid operand (ID 0)
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
I wanted to start a discussion about how the SpvBuilder should handle incomplete data when emitting debug info.
The [createDebugGlobalVariable](https://github.com/KhronosGroup/glslang/blob/6fd3b43060cb9a6f477a7c17729381e6150ffee5/SPIRV/SpvBuilder.cpp#L1524) function assumes that the type ID is nonzero.
However, if the debug support for a type is not implemented yet, the type argument will be 0. For example:
```
#version 450
#extension GL_NV_cooperative_matrix2 : enable
tensorLayoutNV<2> x;
void main() {}
```
In this case the code that [lowers the tensorLayoutNV type](https://github.com/KhronosGroup/glslang/blob/6fd3b43060cb9a6f477a7c17729381e6150ffee5/SPIRV/GlslangToSpv.cpp#L6121) to SPIR-V didn't emit a debug type.
From a user's perspective this is a pretty bad experience, they'll try to debug a shader that was perfectly valid as a non-debug build and find that the debug build may crash the debugger or driver. So I think the builder should do one of two things:
1. Exit with an error if the result would be an invalid SPIR-V module,
2. or replace the bad operand with DebugInfoNone.
Either of those would be better than the current behavior, and should be easy to implement since we're basically just upgrading the asserts that the builder already has.
I think this is a fairly important decision because it seems like debug support for language features invariably lags behind the implementation, so it's very likely that at any given time, someone could hit a case like this for some feature.
Contributor guide
Research direction
Read SPIRV/SpvBuilder.cpp at createDebugGlobalVariable and SPIRV/GlslangToSpv.cpp at the tensorLayoutNV lowering path. Reproduce the provided shader with and without debug information, then determine how invalid type ID 0 should be handled. Done means the debug build no longer emits an invalid operand, using either an explicit error or DebugInfoNone, with the behavior verified on this case.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100