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

Thread: Issues with UBO std140 shared between different shaders using latest nVidia drivers

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Feb 2005
    Posts
    90

    Question Issues with UBO std140 shared between different shaders using latest nVidia drivers

    Hi,

    I have a two programs, one is a fixed pipeline emulator, and the other is an extension that adds additional functionality to it. I want to share the same state (matrices, light, etc...), so i put all these uniforms in a one big uniform block (std140), and shared it with the other program.
    I have a uniform (the modelview inverse matrix) that is used only in the second program, i used std140 layout so that uniform will not be removed by optimization, and it worked in nVidia 310.xx but not the latest versions (the second program doesn't see that uniform).

    Am I doing the right thing for sharing UBO ?

    Thanks
    Ido

  2. #2
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    326
    As of driver 319, Nvidia stopped reporting unused members of a uniform block. If you inspect the structure and size of the UBO, you should notice that the used uniforms are in the same locations and the UBO is the same size in both cases. The driver just isn't reporting the unused uniforms to you. This is consistent with the intent of the GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS enum (ie, "Active"), but isn't very convenient in the cases where you're sharing UBOs. The UBO with the 'missing uniforms' should still be compatible with both shaders and contain the data of the unused uniforms.

  3. #3
    Intern Contributor
    Join Date
    Feb 2005
    Posts
    90
    Hi,

    Thanks for the reply.

    I've installed latest 320.49 which behaves a little different then the previous drivers that broke my code.
    The UBO size returned is the size of all uniforms active or not so my allocated buffer is the correct size, I can see the active/non-active uniforms correctly as you said in each program but still nothing renders and I see no error.

    Do I need to pay attention to specific things in the change to get this to work, the code have been working for almost two years and I'm lost

    Thanks,
    Ido

  4. #4
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    326
    The problem I had with the new driver was that my code was no longer initializing the uniform block members that were unused by the first shader that reported the block, so the second shader would use uninitialized data and produce bad results. Are you certain that all members are initialized?

  5. #5
    Intern Contributor
    Join Date
    Feb 2005
    Posts
    90
    Hi,

    I query the uniform location ,offset, size, stride and type in each program, although I use std140 the code query everything from OpenGL, this may not be the most efficient way in std140 but make it easier to change the shader code and the client, is that what you mean by initialization of members?
    Actually I was not sure when first written if is it legal to query only once for all shared programs, and it looked like good practice if I wanted to use other layouts.

    I can share part of the code by mail if someone is willing to browse it and help (and not laugh at it )

    Malexander I really appreciate your answers but I'm lost.

    Thanks,
    Ido

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    If you want to protect yourself from having different programs having different versions of a shared buffer. I suggest you write a pre-processor that includes the shared buffer in each program as it is compiled. Now they must all match and your cpu code can just use a standard include for the shared buffer. I use a
    Code :
    #pragma include file.h
    The file is the .h for my c++ code which I parse into glsl code

Posting Permissions

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