AILien
AILien

Reputation: 842

Is GLSL 1.30 always supported in OpenGL 3.x / 4.x

Edit 2 It's been pointed out that a question I'm really asking is: "Is the upward compatibility (regarding core profiles) stated in the spec transitive or not?" I would indeed be happy to get an answer to this question. And if it is indeed transitive, how does does one explain the apparent contradiction?

Edit: This is not a duplicate of Which GLSL versions to use for maximum compatibility

It's not a duplicate because : That question was about what versions of GLSL to use in general. This question is about the very specific case of contradictions in the spec about when GLSL 1.30 is supported. I've changed the title as well to clarify.


It seems like all versions of OpenGL from 3.1 onwards are backwards compatible. From the specs:

The OpenGL 4.2 compatibility and core profiles are upward compatible with the OpenGL 4.1 compatibility and core profiles, respectively

The OpenGL 4.1 compatibility and core profiles are upward compatible with the OpenGL 4.0 compatibility and core profiles, respectively

The OpenGL 4.0 compatibility and core profiles are upward compatible with the OpenGL 3.3 compatibility and core profiles, respectively

The OpenGL 3.3 compatibility and core profiles are upward compatible with the OpenGL 3.2 compatibility and core profiles, respectively

The OpenGL 3.2 core profile is upward compatible with OpenGL 3.1, but not with earlier versions

Great, so I can write code against OpenGL 3.1 and it will work on an OpenGL 4.2 implementation.

But the 4.2 core spec also says:

The core profile of OpenGL 4.2 is also guaranteed to support all previous versions of the OpenGL Shading Language back to version 1.40.

And the 3.1 spec says:

OpenGL 3.1 implementations are guaranteed to support at least version 1.30 of the shading language.

So how can OpenGL 4.2 claim to be upward compatible with OpenGL 3.1 when it might not support GLSL 1.30, which was supported by OpenGL 3.1?

Upvotes: 4

Views: 1109

Answers (1)

gkv311
gkv311

Reputation: 2982

I've been puzzled by found inconsistency in specifications and tried to make some research. My personal conclusion is that indeed, OpenGL specifications uses ambiguous/bad wording in this aspect, which has been introduced since OpenGL 3.2+ (the fragment quoted from OpenGL 4.2 Core was first introduced in OpenGL 3.2 Core and remained unchanged).

OpenGL 3.2 demands implementations to support only GLSL 1.40 (OpenGL 3.1) and GLSL 1.50 (OpenGL 3.2) and at the same time specifies that it is compatible with OpenGL 3.1 without removed deprecated functionality.

OpenGL 3.2 implementations are guaranteed to support versions 1.40 and 1.50 of the OpenGL Shading Language. All references to sections of that specification refer to version 1.50.
...
The core profile of OpenGL 4.6 is also guaranteed to support all previous versions of the OpenGL Shading Language back to version 1.40
...
The OpenGL 3.2 core profile is upward compatible with OpenGL 3.1, but not with earlier versions.

At the same time, OpenGL 3.0 and 3.1 explicitly marked GLSL 1.10 (OpenGL 2.0) and GLSL 1.20 (OpenGL 2.1) as deprecated (and removed in OpenGL 3.1):

OpenGL 3.1 implementations are guaranteed to support at least version 1.30 of the shading language.
...
The features deprecated in OpenGL 3.0: ... OpenGL Shading Language versions 1.10 and 1.20. These versions of the shading language depend on many API features that have also been deprecated.

But specs doesn't mention GLSL 1.30 (OpenGL 3.0) in deprecation context, so that there is no obvious reason to consider GLSL 1.30 being deprecated (as dedicated GLSL 1.30 specification itself elaborates deprecated functionality).

One may also note, that OpenGL 3.1 doesn't require GLSL 1.40 to be supported (although it was introduced by this specs)! So stating OpenGL 3.2 being "upward-compatible" to OpenGL 3.1 without GLSL 1.30 support (the only version mandatory to be supported by OpenGL 3.1 specs) looks at bare minimum confusing to me.

I guess that OpenGL specs authors in "upward-compatible" section implicitly referred to non-GLSL functionality, and designed dedicated section "implementations are guaranteed ... shading language" to clarify requirements upon GLSL versions, so that the latter dominates over the first one.

I've tried to check OpenGL implementations at hand to see what they will tell for different GLSL versions (110, 120, 130, 140, 150) within Core Profile, GLSL compilation warnings logged and Debug context enabled:

  • NVIDIA (456.71), Intel and Mesa (20.2.6)
    • GLSL 1.10+ - say not a word for any known GLSL versions;
  • AMD
    • GLSL 1.10/GLSL 1.20 - shader compiler generates a warning
      WARNING: warning(#271) Explicit version number 120 not supported by GL3 forward compatible context;
    • GLSL 1.30+ - no warnings;
  • Apple (Metal 71.0.7)
    • GLSL 1.10/1.20/1.30 - generates a shader compilation error
      ERROR: 0:1: '' : version '130' is not supported
    • GLSL 1.40+ - no issues.

So, it seems that OpenGL vendors are inconclusive on reading this portion of specifications.

NVIDIA just doesn't care (their GLSL -> Cg translator is known to skip most of GLSL validation), Intel too (but their OpenGL driver was never good), as well as Mesa. But this is NOT a violation of OpenGL specs, as they say that OpenGL implementations may support any other GLSL versions in addition to mandatory ones.

AMD is known to have a good GLSL validator, and apparrently their engineers read the portions of the spec stating "OpenGL 3.2 Core Profile should support the same as OpenGL 3.1 except deprecated functionality". But does it softly - without compilation errors, as only shader compilation log suggests that GLSL 1.20 should not be used (but GLSL 1.30 is OK!).

Apple is known to be paranoid in following OpenGL specs and usually generates errors on every deviation from it. And here we see that Apple engineers read the other portion of OpenGL 3.2 specification listing supported GLSL versions as 1.40 and 1.50 - so that it does not accept GLSL 1.30.

It should be noted, that most vendors implemented OpenGL 3.2 after implementing OpenGL 3.0 and 3.1, so that it is really not a big deal for them to support all GLSL versions starting from 1.10.

In contrast, Apple never has OpenGL 3.0/3.1 and implemented OpenGL 3.2 Core Profile straight ahead (without any interest in implementing Compatible Profiles). That's why, I guess, they preferred to read specs that GLSL 1.30 (OpenGL 3.1) is not supported.

The general wording in OpenGL specifications states that the range of supported GLSL versions may be wider and suggests querying GL_SHADING_LANGUAGE_VERSION, but apparently, this query is useless to retrieve a minimal GLSL version or complete list of supported versions, and no other API provided for that purpose. So that one may only "probe" shader compiler to see if particular version is supported or not (outside the list of mandatory ones).

From the other side, separate GLSL versioning independent from OpenGL looks redundant, as newer GLSL revisions are also compatible with earlier ones (save deprecated functionality) - so that there is no much reason to not force GLSL 4.20 while using OpenGL 4.2, as long as you are not just trying to verify GLSL compatibility with older OpenGL versions.

Practically speaking, OpenGL 3.2 and it's GLSL 1.50 looks like a more reasonable baseline for development, as I don't really know up-to-date implementations supporting OpenGL 3.1 but not OpenGL 3.2 Core Profile.

Upvotes: 3

Related Questions