Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Limit of 32 samplers in GLSL shaders

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    6

    Limit of 32 samplers in GLSL shaders

    Hi,

    we are currently running into the GLSL sampler/texture limit per stage which is defined by MAX_TEXTURE_IMAGE_UNITS. This is currently 32 for me, but I am wondering if there is any way to sample more textures.
    I already checked into the sampler objects (http://www.opengl.org/registry/specs...er_objects.txt) which allows you to nicely split the sampler states from the texture objects, but there isn't any counterpart for this on the GLSL side, so I don't think this will help us increase the limit.

    I know on D3D11 there is a split on samplers and textures also in HLSL where you can have upto 16 samplers per stage, and upto 128 textures. Textures are sampled by defining a sampler to use then. I guess nothing like this is available in OpenGL?

    I also checked into the NV extension: NV_bindless_texture (http://developer.download.nvidia.com...ss_texture.txt), but sadly enough this only works on nVidia Keppler hardware.

    Any suggestions?

    Kind Regards,
    Kenzo

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    942
    I already checked into the sampler objects
    As to my knowledge, samplers can be bound to texture units which effectively changes state used in texture look-ups on the texture bound to this unit and target and a shader does not discriminate between sampler and texture object.

    This is currently 32 for me, but I am wondering if there is any way to sample more textures.
    There are plenty of ways to circumvent the texture unit limit. First, the tried and true texture atlas which combines multiple smaller textures into a single large one. Accessing a single texture is then done using offsets in s and t. Second, you can use texture arrays which increase the number of textures per unit to MAX_ARRAY_TEXTURE_LAYERS. This is more convenient than using a texture atlas since you'll only have to use an index and sample the returned texture like you would any other texture. Third, do multiple passes where each pass uses the necessary amount of units as long as unit < MAX_COMBINED_TEXTURE_IMAGE_UNITS.

  3. #3
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    6
    Hi,

    thank you for the reply, but I know about the ways to work around the limitation but all of them have issues:
    - Texture Atlas: hard to do good texture wrapping without making the shader expensive and mip maps often look bad. And the data has to be modified for this.
    - Texture Arrays: this looks like the best possibility but has an annoying memory layout which is not very efficient for streaming data.
    - Multi pass rendering: not easy possible for every technique because of limited blending option. How to properly blend tessellated or POM materials for example? And also adds extra overhead on the code side.

    Just more textures samplers in a shader is easier, but if that's not possible than it will have to be texture arrays I guess.

    Kind Regards,
    Kenzo

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    942
    Just more textures samplers in a shader is easier
    There is no way to increase the number of MAX_COMBINED_TEXTURE_UNITS yourself. It's implementation dependent.

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,792
    we are currently running into the GLSL sampler/texture limit per stage which is defined by MAX_TEXTURE_IMAGE_UNITS
    Wrong. GL_MAX_TEXTURE_IMAGE_UNITS gives the limit for the fragment shader stage only. Each shader stage has a separate query. GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS is for the vertex shader. And so forth.

    Sure, on modern hardware, these are almost always the same. But OpenGL does not require this to be so.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    947
    Quote Originally Posted by Guoshima View Post
    - Texture Arrays: this looks like the best possibility but has an annoying memory layout which is not very efficient for streaming data.
    Tell me what do you mean here? Texture arrays don't have any "annoying memory layout". They are simply arrays of simple textures. The only restriction is that all layers must have the same size, internal format and mipmap level count.
    What does prevent you from streaming data efficiently to texture arrays?
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •