KhronosGroup / KhronosGroup/glslang

Cannot use specialization constants for loop bounds when nonInductiveForLoops = 0

Open
#2,465 0 comments 0 reactions 0 assignees View on GitHub
enhancement GLSL/ESSL
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

When setting nonInductiveForLoops to 0, specialization constants can not be used as a loop bound as they're not considered constant expressions. As I understand it, for targets not supporting non-inductive loops, these constants would be translated as #defines, and would work, as long as valid values are used that could be assigned to the original constants as well.

Replication glsl:

```
#version 330

precision highp float;

layout (constant_id = 0) const int COUNT = 16;

out vec4 fragOut;

void main()
{
float total = 0.0;
float someOther = 1.0;

for (int i = 0; i < COUNT; i++) {
total += someOther;
}

fragOut = vec4(total);
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the GLSL reproduction in the issue and trace how glslang handles specialization constants used as loop bounds when nonInductiveForLoops is 0. Done means the shown shader accepts a valid specialization-constant loop bound and produces the intended translation for targets without non-inductive loops.

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.