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 9 of 9

Thread: Redundant texture switches

  1. #1
    Member Regular Contributor
    Join Date
    Mar 2007
    Location
    California
    Posts
    410

    Redundant texture switches

    I just wanted to make sure of something. If I bind a texture that is already bound, is that just as expensive as switching a texture? Does OpenGL know that the texture is already bound, or does it just re-bind it regardless? My guess is it re-binds it in order to make it so OpenGL does exactly what you tell it to do.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,401

    Re: Redundant texture switches

    my guess is that most drivers check for the redundant bind, but it's not specified wither way (implementation dependent thing).

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,401

    Re: Redundant texture switches

    you could probably devise an elaborate performance test to verify this one way or another... if you've got some extra time to waste. Might be better time wasted simply checking for this yourself. That's waht I do......... and probably most everyone else ;-)

  4. #4
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: Redundant texture switches

    your performance test would show it's cheaper to check first yourself, otherwise you'll be paying for simply calling glBindTexture. Not much maybe, but significant cpu work if you have lots of texture binds. Personally I have a very lightweight inline'd layer between me and GL, and do a redundancy check on every state change. I pay nothing for a function call if it's redundant, but pay twice for a redundancy check if the driver's already doing one, but it will work out cheaper overall. I remember asking an nvidia driver writer years ago if they do a redundancy check, and he told me they don't under the assumption that the app will be doing it's own, so it would be repeating work that should already have been done. Maybe things have changed in recent years.
    Knackered

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,052

    Re: Redundant texture switches

    AFAIK drivers do redundancy checks for very expensive operations like shader and texture switches. Though to be sure, do your own checks, too.

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  6. #6
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Redundant texture switches

    It's surely faster to do your own state cache and avoid calling into OpenGL if you don't need to.
    A simple comparison is faster than calling any function.

    Calling into the OpenGL implementation under Windows involves a function call into OpenGL32.dll, a jump to the ICD, error checks on the user parameters and *finally* it can check if the call was redundant and return.

    Also never do something like glIsEnabled or glGet to query the state and then set it if it's different. (The only exception would be in a library which needs to restore an application's OpenGL state.)

  7. #7
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: Redundant texture switches

    Jan, I don't think nvidia drivers would do any redundancy checks in the application thread (their drivers are multithreaded). So you'll be paying the price of queueing up a command with all its parameters at the very least.
    Knackered

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,052

    Re: Redundant texture switches

    True. But IF you do a redundant state-change, it will still not be as bad as it was, if it wasn't rejected, at all.

    But i agree completely, that a professional program should do redundancy checks for all states. With textures and shaders that's actually very easy, for all the small states, that OpenGL 2.x exposes it can be a bit annoying to write a complete wrapper for the whole API (though, again, professional software should do it).

    With OpenGL 3's new state-blocks etc. it should be very easy to do redundancy checks for absolutely every state-change.

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  9. #9
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Redundant texture switches

    I have not benchmarked this recently but a long time ago I just stuck a simple check for the texture ID. The performance went up by 2 or 3x. The code was making a lot of glBindTexture calls.
    It's been said on these boards that drivers don't do redundancy check so it must be true. It applies to both NV and ATI.

    Calling into the OpenGL implementation under Windows involves a function call into OpenGL32.dll, a jump to the ICD, error checks on the user parameters and *finally* it can check if the call was redundant and return.
    Jump to opengl32.dll happens for GL 1.1 functions.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

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