Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken version check for support of sampler arrays in GLSL ES leads to incorrect error #154

Open
ghost opened this issue May 14, 2021 · 0 comments

Comments

@ghost
Copy link

ghost commented May 14, 2021

bug.glsl

#version 100
#define SAMPLER_COUNT 2
uniform sampler2D samplers[SAMPLER_COUNT];
void main() {
  vec4 sum = vec4(0.0);
  for(int i = 0; i < SAMPLER_COUNT; i++) {
    sum += samplers[i];
  }
  gl_FragColor = sum;
}

$ glslopt -2 -f bug.glsl
Failed to compile bug.glsl:

(7,9): error: sampler arrays indexed with non-constant expressions is forbidden in GLSL 1.30 and later
(7,2): error: operands to arithmetic operators must be numeric

However, according to the GLSL ES 2.0 spec Page 109 (115 in PDF): https://www.khronos.org/registry/OpenGL/specs/es/2.0/GLSL_ES_Specification_1.00.pdf:

5 Indexing of Arrays, Vectors and Matrices

[...]
The following are constant-index-expressions:

  • Constant expressions
  • Loop indices as defined in section 4
  • [...]

Samplers

GLSL ES 1.00 supports both arrays of samplers and arrays of structures which contain samplers. In both these cases, for ES 2.0, support for indexing with a constant-index-expression is mandated but support for indexing with other values is not mandated.

So this is a bug, because I'm using a constant-index-expressions, for which support is mandated by the GLSL spec.

I did look into it, and the broken check is here:

if (array->type->element_type()->is_sampler()) {
if (!state->is_version(130, 100)) {
if (state->es_shader) {
_mesa_glsl_warning(&loc, state,
"sampler arrays indexed with non-constant "
"expressions is optional in %s",
state->get_version_string());
} else {
_mesa_glsl_warning(&loc, state,
"sampler arrays indexed with non-constant "
"expressions will be forbidden in GLSL 1.30 "
"and later");
}
} else if (!state->is_version(400, 0) && !state->ARB_gpu_shader5_enable) {
_mesa_glsl_error(&loc, state,
"sampler arrays indexed with non-constant "
"expressions is forbidden in GLSL 1.30 and "
"later");
}
}
}

This bug does not exist in a rebased fork with a more recent mesa: https://github.com/jamienicol/glsl-optimizer/
The fixed check is here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants