简体   繁体   English

OpenGL 3.x / 4.x 是否始终支持 GLSL 1.30

[英]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?"编辑 2有人指出,我真正要问的一个问题是:“规范中所述的向上兼容性(关于核心配置文件)是否具有可传递性?” 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编辑:这不是使用哪些 GLSL 版本以获得最大兼容性的副本

It's not a duplicate because : That question was about what versions of GLSL to use in general.这不是重复的,因为:这个问题是关于一般使用什么版本的 GLSL。 This question is about the very specific case of contradictions in the spec about when GLSL 1.30 is supported.这个问题是关于规范中关于何时支持 GLSL 1.30 的矛盾的非常具体的情况。 I've changed the title as well to clarify.我也更改了标题以进行澄清。


It seems like all versions of OpenGL from 3.1 onwards are backwards compatible.似乎从 3.1 开始的所有 OpenGL 版本都是向后兼容的。 From the specs:从规格:

The OpenGL 4.2 compatibility and core profiles are upward compatible with the OpenGL 4.1 compatibility and core profiles, respectively OpenGL 4.2 兼容性和核心配置文件分别向上兼容 OpenGL 4.1 兼容性和核心配置文件

The OpenGL 4.1 compatibility and core profiles are upward compatible with the OpenGL 4.0 compatibility and core profiles, respectively OpenGL 4.1 兼容性和核心配置文件分别向上兼容 OpenGL 4.0 兼容性和核心配置文件

The OpenGL 4.0 compatibility and core profiles are upward compatible with the OpenGL 3.3 compatibility and core profiles, respectively OpenGL 4.0 兼容性和核心配置文件分别向上兼容 OpenGL 3.3 兼容性和核心配置文件

The OpenGL 3.3 compatibility and core profiles are upward compatible with the OpenGL 3.2 compatibility and core profiles, respectively OpenGL 3.3 兼容性和核心配置文件分别向上兼容 OpenGL 3.2 兼容性和核心配置文件

The OpenGL 3.2 core profile is upward compatible with OpenGL 3.1, but not with earlier versions OpenGL 3.2 核心配置文件向上兼容 OpenGL 3.1,但不兼容早期版本

Great, so I can write code against OpenGL 3.1 and it will work on an OpenGL 4.2 implementation.太好了,所以我可以针对 OpenGL 3.1 编写代码,并且可以在 OpenGL 4.2 实现上运行。

But the 4.2 core spec also says:但是 4.2 核心规范也说:

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. OpenGL 4.2 的核心配置文件也保证支持所有以前版本的 OpenGL 着色语言回到 1.40 版。

And the 3.1 spec says: 3.1 规范说:

OpenGL 3.1 implementations are guaranteed to support at least version 1.30 of the shading language. OpenGL 3.1 实现保证至少支持 1.30 版的着色语言。

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?因此,如何能的OpenGL 4.2声称自己是用OpenGL 3.1向上兼容时,它可能不支持GLSL 1.30,这由OpenGL的3.1支持?

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 规范在这方面使用了歧义/不好的措辞,这是从 OpenGL 3.2+ 开始引入的(从 OpenGL 4.2 Core 引用的片段首先在 OpenGL 3.2 Core 中引入并保持不变)。

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 要求实现仅支持 GLSL 1.40 (OpenGL 3.1) 和 GLSL 1.50 (OpenGL 3.2),同时指定它与 OpenGL 3.1 兼容,但不删除已弃用的功能。

OpenGL 3.2 implementations are guaranteed to support versions 1.40 and 1.50 of the OpenGL Shading Language. OpenGL 3.2实现保证支持 OpenGL 着色语言的 1.40 和 1.50 版。 All references to sections of that specification refer to version 1.50.对该规范部分的所有引用均指版本 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 OpenGL 4.6的核心配置文件也保证支持所有以前版本的 OpenGL 着色语言回到 1.40 版
... ...
The OpenGL 3.2 core profile is upward compatible with OpenGL 3.1, but not with earlier versions. OpenGL 3.2 核心配置文件与 OpenGL 3.1 向上兼容,但与早期版本不兼容。

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.0 和 3.1 明确将 GLSL 1.10 (OpenGL 2.0) 和 GLSL 1.20 (OpenGL 2.1) 标记为已弃用(并在 OpenGL 3.1 中删除):

OpenGL 3.1 implementations are guaranteed to support at least version 1.30 of the shading language. OpenGL 3.1实现保证至少支持 1.30 版的着色语言。
... ...
The features deprecated in OpenGL 3.0: ... OpenGL Shading Language versions 1.10 and 1.20. OpenGL 3.0 中弃用的功能: ... OpenGL 着色语言版本 1.10 和 1.20。 These versions of the shading language depend on many API features that have also been deprecated.这些版本的着色语言依赖于许多已被弃用的 API 功能。

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).但是规范在弃用上下文中没有提到 GLSL 1.30 (OpenGL 3.0),因此没有明显的理由认为 GLSL 1.30 被弃用(因为专用的 GLSL 1.30 规范本身阐述了弃用的功能)。

One may also note, that OpenGL 3.1 doesn't require GLSL 1.40 to be supported (although it was introduced by this specs)!人们可能还注意到, OpenGL 3.1 不需要支持GLSL 1.40 (尽管它是由本规范引入的)! 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.因此,声明 OpenGL 3.2 在没有 GLSL 1.30 支持(OpenGL 3.1 规范必须支持的唯一版本)的情况下“向上兼容”到 OpenGL 3.1 对我来说是最低限度的混淆。

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.我猜 OpenGL 规范作者在“向上兼容”部分隐含地提到了非 GLSL 功能,并设计了专门的部分“保证实现......着色语言”以阐明对 GLSL 版本的要求,以便后者主导第一个一。

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:我试图检查手头的 OpenGL 实现,看看它们会在核心配置文件中针对不同的 GLSL 版本(110、120、130、140、150)说明什么,记录了 GLSL 编译警告并启用了调试上下文:

  • NVIDIA (456.71), Intel and Mesa (20.2.6) NVIDIA (456.71)、英特尔Mesa (20.2.6)
    • GLSL 1.10+ - say not a word for any known GLSL versions; GLSL 1.10+ - 对任何已知的 GLSL 版本一言不发
  • AMD AMD
    • GLSL 1.10/GLSL 1.20 - shader compiler generates a warning GLSL 1.10/GLSL 1.20 - 着色器编译器生成警告
      WARNING: warning(#271) Explicit version number 120 not supported by GL3 forward compatible context ; WARNING: warning(#271) Explicit version number 120 not supported by GL3 forward compatible context
    • GLSL 1.30+ - no warnings; GLSL 1.30+ - 没有警告;
  • Apple (Metal 71.0.7)苹果(金属 71.0.7)
    • GLSL 1.10/1.20/1.30 - generates a shader compilation error GLSL 1.10/1.20/1.30 - 生成着色器编译错误
      ERROR: 0:1: '' : version '130' is not supported
    • GLSL 1.40+ - no issues. GLSL 1.40+ - 没问题。

So, it seems that OpenGL vendors are inconclusive on reading this portion of specifications.所以,似乎OpenGL 供应商在阅读这部分规范时没有定论

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. NVIDIA 只是不在乎(他们的 GLSL -> Cg 翻译器已知会跳过大部分 GLSL 验证),英特尔也是(但他们的 OpenGL 驱动程序从来都不是很好),以及 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.但这并不违反 OpenGL 规范,因为他们说 OpenGL 实现可能支持除强制性版本之外的任何其他 GLSL 版本。

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" .众所周知, AMD有一个很好的 GLSL 验证器,显然他们的工程师阅读了规范的部分内容,指出“OpenGL 3.2 核心配置文件应该支持与 OpenGL 3.1 相同的功能,但不推荐使用” 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!).但是它是否轻而易举 - 没有编译错误,因为只有着色器编译日志表明不应使用 GLSL 1.20(但 GLSL 1.30 是可以的!)。

Apple is known to be paranoid in following OpenGL specs and usually generates errors on every deviation from it.众所周知, Apple在遵循 OpenGL 规范方面偏执,并且通常在每次偏离时都会产生错误。 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.在这里我们看到 Apple 工程师阅读了 OpenGL 3.2 规范的另一部分,将支持的 GLSL 版本列为 1.40 和 1.50 - 因此它不接受 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.需要注意的是,大多数厂商在实现了OpenGL 3.0和3.1之后才实现了OpenGL 3.2,所以支持从1.10开始的所有GLSL版本对他们来说真的没什么大不了的。

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).相比之下,Apple 从来没有 OpenGL 3.0/3.1 并且直接实现了 OpenGL 3.2 核心配置文件(对实现兼容配置文件没有任何兴趣)。 That's why, I guess, they preferred to read specs that GLSL 1.30 (OpenGL 3.1) is not supported.这就是为什么,我想,他们更喜欢阅读不支持 GLSL 1.30 (OpenGL 3.1) 的规范。

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. OpenGL 规范中的一般措辞表明支持的 GLSL 版本范围可能更广,并建议查询GL_SHADING_LANGUAGE_VERSION ,但显然,此查询对于检索最小 GLSL 版本或支持版本的完整列表是无用的,并且没有为此目的提供其他 API . 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.另一方面,独立于 OpenGL 的单独 GLSL 版本控制看起来是多余的,因为较新的 GLSL 修订版也与早期版本兼容(保留已弃用的功能)——因此没有太多理由在使用 OpenGL 4.2 时不强制使用 GLSL 4.20,只要您不仅仅是要验证 GLSL 与旧 OpenGL 版本的兼容性。

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.实际上,OpenGL 3.2 和它的 GLSL 1.50 看起来是一个更合理的开发基线,因为我真的不知道支持 OpenGL 3.1 但不支持 OpenGL 3.2 核心配置文件的最新实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM