KhronosGroup / KhronosGroup/glslang

DebugTypeArray emitted with OpSpecConstantOp dimension violates NonSemantic.Shader.DebugInfo.100 spec

Open
#4,186 3 comments 0 reactions 1 assignee Claimed by @dnovillo View on GitHub
ShaderDebugInfo Specification
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

**glslang version:** 16.2.0
**SPIR-V target:** 1.6 / Vulkan 1.4

### Description

When a GLSL shader declares a shared (or other) array whose size is a specialization constant expression, and `SpvOptions::emitNonSemanticShaderDebugInfo = true`, glslang emits a `DebugTypeArray` instruction whose component-count operand is the result of a presumably `OpSpecConstantOp` rather than an `OpConstant` (it's the result of arithmetic on spec constants, I am not fluently in SPRIV).

The `NonSemantic.Shader.DebugInfo.100` specification requires the component count to be:
> an `OpConstant` with a 32- or 64-bits integer scalar type, **or** a `DebugGlobalVariable` / `DebugLocalVariable` with a 32- or 64-bits unsigned integer scalar type

### Minimal reproducer

```glsl
#version 460
#extension GL_KHR_shader_subgroup_arithmetic : enable

layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z = 1) in;
layout(constant_id = 2) const int SUBGROUP_SIZE = 32;

shared float subgroup_sums[
(gl_WorkGroupSize.x * gl_WorkGroupSize.y + SUBGROUP_SIZE - 1) / SUBGROUP_SIZE
];

void main() {}
```

Compile with emitNonSemanticShaderDebugInfo enabled, then validate:

### Error

```
NonSemantic.Shader.DebugInfo.100 DebugTypeArray: Component Count must be OpConstant
with a 32- or 64-bits integer scalar type or DebugGlobalVariable or DebugLocalVariable
with a 32- or 64-bits unsigned integer scalar type
%97 = OpExtInst %void %1 DebugTypeArray %39 %95
```

### Expected behaviour

glslang should either:
- Use the spec constant's default value as a plain `OpConstant` for the `DebugTypeArray` dimension, or
- Emit a `DebugGlobalVariable` / `DebugLocalVariable` reference as the dimension, or
- Omit the `DebugTypeArray` for arrays whose size cannot be expressed as a plain constant

### Note
I reproduced it with https://github.com/LDAP/merian-example-sum at commit ef51b2b58db222db226bebe57b93657c40f679ef with glslang lib installed. I am not very familiar with SPIRV, some of the above are my assumptions on how this works.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.