Difference between revisions of "Detecting the Shader Model"

From OpenGL Wiki
Jump to navigation Jump to search
m
(→‎OpenGL Shading Language: Welcome to OpenGL 4.3.)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
This question has come up a few times and the best thread can be found here :<br>
+
OpenGL does not follow the Direct3D Shader Model format; it has its own way to expose specific sets of functionality to the user. The OpenGL version number and the presence of extensions is a better test for what features are available on the hardware.
http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=11;t=001090<br>
+
 
note : The link does not work since the forum software has changed<br>
+
However, if you ''must'' equate GL functionality with Direct3D Shader Model versions, here is how to do so. It differs for different shading languages.
<br>
+
 
Short explanation below:<br>
+
== OpenGL Shading Language ==
If you can detect GL_NV_vertex_program3, then you have a SM 3.0 GPU<br>
+
 
GL_NV_fragment_program2 would do as well.<br>
+
Query the version of with <code>glGetString(GL_SHADING_LANGUAGE_VERSION)</code>. The version is formatted as <code><nowiki><version number><space><vendor-specific information></nowiki></code>, where <code><nowiki><version number></nowiki></code> is a <code>MAJOR.MINOR</code> format, with an optional release number.
This works for nVidia GPUs<br>
+
 
ATI 3.0 GPUs advertize GL_ATI_shader_texture_lod<br>
+
GLSL versions went through some interesting number changes.
If those extensions are not present and if your GL version 2.0, then you have a SM 2.0 GPU.<br>
+
 
In glhlib 1.60,<br>
+
Until version 3.30, the GLSL version number and the corresponding OpenGL version number were different. Here's a table:
  int params[2];
+
 
  glhGetIntegerv(GLH_GPU_SHADERMODEL, params);
+
{|
and params[0] will get the major version (2, 3, 4)<br>
+
!OpenGL<br/>Version
and params[1] will get the minor version (always 0)<br>
+
!GLSL<br/>Version
http://www.geocities.com/vmelkon/glhlibrary.html<br>
+
|-
<br>
+
|2.0
Another method is to write some specific shaders and see if they compile.<br>
+
|1.10
If they do compile, check the info log for the presence of the word "software"<br>
+
|-
<br>
+
|2.1
=== Update ===
+
|1.20
SM 4.0 GPUs came out so how to detect these ones?<br>
+
|-
The most surefire way is to look for the following extension : GL_NV_gpu_program4, GL_NV_geometry_program4, GL_NV_vertex_program4, GL_NV_fragment_program4<br>
+
|3.0
and soon after, GL_EXT_gpu_shader4, GL_EXT_geometry_shader4, and some others.<br>
+
|1.30
 +
|-
 +
|3.1
 +
|1.40
 +
|-
 +
|3.2
 +
|1.50
 +
|-
 +
|}
 +
 
 +
For all versions of OpenGL 3.3 and above, the corresponding GLSL version matches the OpenGL version. So GL 4.1 uses GLSL 4.10.
 +
 
 +
Direct3D Shader Model 4.0 is equivalent to GLSL version 3.30. Earlier GLSL versions for OpenGL 3.x provide subsets of this functionality, based on the available functionality in the OpenGL version, though 1.50 is almost feature-identical to SM4.
 +
 
 +
Direct3D Shader Model 5.0 is equivalent to GLSL version 4.30.
 +
 
 +
For earlier shader models, GLSL versions less than 1.30 are used. Because GLSL is a high-level language, many of the differences between SM 2 and 3 are not exposed to the user.
 +
 
 +
== ARB Assembly Language ==
 +
 
 +
These are done through testing the presence of extensions. You should test them in this order:
 +
 
 +
# GL_NV_gpu_program4: SM 4.0 or better.
 +
# GL_NV_vertex_program3: SM 3.0 or better.
 +
# GL_ARB_fragment_program: SM 2.0 or better.
 +
 
 +
ATI does not support higher than SM 2.0 functionality in assembly shaders.

Latest revision as of 03:23, 28 September 2012

OpenGL does not follow the Direct3D Shader Model format; it has its own way to expose specific sets of functionality to the user. The OpenGL version number and the presence of extensions is a better test for what features are available on the hardware.

However, if you must equate GL functionality with Direct3D Shader Model versions, here is how to do so. It differs for different shading languages.

OpenGL Shading Language

Query the version of with glGetString(GL_SHADING_LANGUAGE_VERSION). The version is formatted as <version number><space><vendor-specific information>, where <version number> is a MAJOR.MINOR format, with an optional release number.

GLSL versions went through some interesting number changes.

Until version 3.30, the GLSL version number and the corresponding OpenGL version number were different. Here's a table:

OpenGL
Version
GLSL
Version
2.0 1.10
2.1 1.20
3.0 1.30
3.1 1.40
3.2 1.50

For all versions of OpenGL 3.3 and above, the corresponding GLSL version matches the OpenGL version. So GL 4.1 uses GLSL 4.10.

Direct3D Shader Model 4.0 is equivalent to GLSL version 3.30. Earlier GLSL versions for OpenGL 3.x provide subsets of this functionality, based on the available functionality in the OpenGL version, though 1.50 is almost feature-identical to SM4.

Direct3D Shader Model 5.0 is equivalent to GLSL version 4.30.

For earlier shader models, GLSL versions less than 1.30 are used. Because GLSL is a high-level language, many of the differences between SM 2 and 3 are not exposed to the user.

ARB Assembly Language

These are done through testing the presence of extensions. You should test them in this order:

  1. GL_NV_gpu_program4: SM 4.0 or better.
  2. GL_NV_vertex_program3: SM 3.0 or better.
  3. GL_ARB_fragment_program: SM 2.0 or better.

ATI does not support higher than SM 2.0 functionality in assembly shaders.