Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-80585

How to handle uniform blocks without an instance name with the OpenGL backend

    XMLWordPrintable

Details

    • Task
    • Resolution: Done
    • P2: Important
    • None
    • None
    • Qt RHI
    • None
    • 3c255045eed12bdc887d05c9ab645d5d347d2f49 (qt-labs/qtshadertools/master)

    Description

      Quick3D shaders would like to rely to uniform blocks without an instance name:

      layout(std140, binding = 0) uniform cbMain {
        vec4 base_color;
        vec3 material_diffuse;
        vec4 material_properties;
        mat4 modelViewProjection;
      }; // note that there is no instance name specified here
      

      This allows writing, for example, "material_properties" in the shader code, even though it is a block member.

      Qt Quick materials do not follow this, there the uniform block always has an instance name, like "ubuf", and every member access is qualified with "ubuf.". For Quick3D this is not quite ideal due to wanting compatibility with the vast amount of existing shader code.

      This raises a problem with the OpenGL backend of QRhi which never uses true uniform blocks. Rather, SPIRV-Cross converts the uniform block to a struct and a plain uniform. The problem is that without an instance name the uniform name becomes an autogenerated "_N" name where N is an arbitrary uint. So for example:

      struct cbMain {
        vec4 base_color;
        vec3 material_diffuse;
        vec4 material_properties;
        mat4 modelViewProjection;
      };
      uniform cbMain _14;
      

      and we have no way of knowing what the name is (it is _14 in the example).

      In addition, N is chosen on a per-shader basis, leading to two sets of independent uniforms (assuming a vertex and a fragment shader), that is bad too.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              lagocs Laszlo Agocs
              lagocs Laszlo Agocs
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes