Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Binary shaders support in OpenGL

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

    Question Binary shaders support in OpenGL

    Hi,
    I'm using a heavy shader which takes a lot of time to compile so I'm trying to use binary shaders.

    I'd like to compile a shader once and just load it onto shader pipeline next time I use it. It's a common practice in Direct3D by using CreatePixelShader or CreateVertexShader functions to load compiled binary shaders.

    Only thing I googled is glShaderBinary which is part of OpenGL ES and I cannot use it because glGetIntegerv with parameter GL_NUM_SHADER_BINARY_FORMATS returns 0 (obviously because I don't have OpenGL ES extension).

    Is there a way to make it work without OpenGL ES?
    What's the minimal version of OpenGL standard that supports this?

    Thanks

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,789
    What you want is glProgramBinary, and its associated gets.

    The minimum GL version that has this as a core feature is 4.1. However, pretty much any hardware that is still supported by the IVH (outside of Intel hardware of course) exposes it via ARB_get_program_binary on any platform. So all Radeon HD-class hardware and GeForce 6xxx and above.

  3. #3
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    303
    Quote Originally Posted by Alfonse Reinheart View Post
    However, pretty much any hardware that is still supported by the IVH (outside of Intel hardware of course) exposes it via ARB_get_program_binary on any platform.
    Except for MacOS X :-(

  4. #4

  5. #5
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    14
    Thanks,
    I have a few more questions.

    Link provided by Alfonse says that there are vendor-specific format which can be provided by 3rd party extensions.

    Does that means there are formats which produce device-independent binary program codes?

    That would mean that I can compile shaders into binary format which could be loaded from completely different hardware configuration. That is important because Direct3D generates code which is completely independent. It can even be produced on a machine without 3d-accelerated graphic card using console command fxd which is part of DirectX SDK and can be run on any computer with hardware that supports chosen shader language version.

    Target machines I would use are PC computers (including Windows and Linux).

  6. #6
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,789
    Does that means there are formats which produce device-independent binary program codes?
    The API is open to permit such formats to exist. But none do currently. Nor are they likely to in the future.

  7. #7
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    14
    That makes me sad

    Is there any enumeration in GLEW and/or MESA with program binary formats they support so I could get something besides the raw numbers?

    I'd like to know what's the idea behind some of those formats so I could study more about them.

    Thanks again

  8. #8
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655
    The idea behind binary formats is that they load fast on their dedicated hardware.

    They are the opposite of being able to run on completely different hardware. This however is the aim of GLSL.

  9. #9
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,789
    The format value is nothing more than a way to tell where a binary came from and whether an implementation will accept this binary. You're not going to get anything "besides the raw numbers" because they don't mean anything. NVIDIA drivers of a particular version spit out one number, AMD drivers of a particular version spit out a different number. What matters is which numbers the implementations support.

    Program binary is intended to be a way of caching compiled shaders, not shipping pre-compiled shaders with your application (though you can try to do that too, as long as you precompile them on all hardware of interest). In either case, the format field is how you detect if the implementation can load that particular version of the shader.

  10. #10
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    14
    Thanks for the detailed info.

    Sorry for being so curious, but I really wan't to go into how OpenGL shaders work.

    I'm now studying of ways how to create programs and I'm looking at ARB assembly language. It seems that assembly could be compiled really fast into binary and easily converted from my Direct3D shader assembly code.
    However, there is a problem with that. ARB_fragment_program instructions list does not include branching and looping operations so I cannot convert my rep, if_lt and if_gt commands.

    There is also NV_gpu_program4 instruction set which supports them, but they are nvidia-specific.

    Is there an AMD version of instruction set or something similar since those NV functions are not likely to be available on radeon graphic cards?

    Thanks

Posting Permissions

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