Difference between revisions of "Detecting the Shader Model"

From OpenGL Wiki
Jump to navigation Jump to search
(Making this page seem reasonable.)
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>
+
Shading language versions 1.3 is equivalent to much of Shader Model 4.0. Version 1.4 introduces [[Uniform Buffer Objects|uniform buffers]] and a few other features. Version 1.5 introduces [[Geometry Shaders|geometry shaders]]; this version could be said to be feature-identical to Shader Model 4.
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>
+
All versions less than 1.3 are equivalent to Shader Models 2 and 3. Because GLSL is a high-level language, many of the differences between SM 2 and 3 are not exposed to the user.
  int params[2];
+
 
  glhGetIntegerv(GLH_GPU_SHADERMODEL, params);
+
== ARB Assembly Language ==
and params[0] will get the major version (2, 3, 4)<br>
+
 
and params[1] will get the minor version (always 0)<br>
+
These are done through testing the presence of extensions. You should test them in this order:
http://www.geocities.com/vmelkon/glhlibrary.html<br>
+
 
<br>
+
# GL_NV_gpu_program4: SM 4.0 or better.
Another method is to write some specific shaders and see if they compile.<br>
+
# GL_NV_vertex_program3: SM 3.0 or better.
If they do compile, check the info log for the presence of the word "software"<br>
+
# GL_ARB_fragment_program: SM 2.0 or better.
<br>
+
 
=== Update ===
+
ATI does not support higher than SM 2.0 functionality in assembly shaders.
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>
 
and soon after, GL_EXT_gpu_shader4, GL_EXT_geometry_shader4, and some others.<br>
 

Revision as of 20:50, 17 August 2009

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.

Shading language versions 1.3 is equivalent to much of Shader Model 4.0. Version 1.4 introduces uniform buffers and a few other features. Version 1.5 introduces geometry shaders; this version could be said to be feature-identical to Shader Model 4.

All versions less than 1.3 are equivalent to Shader Models 2 and 3. 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.