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

qbs generation problems with macros

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.9.2
    • Qt Shader Tools
    • None
    • Windows 11, VS 2022
      macOS 26, xCode 26
      Qt Creator 17
    • All

      Given is the following shader:

      #version 450
      
      #ifdef QSHADER_GLSL
      layout(location = 0) in vec2 a_pos;
      #else
      layout(location = 0) in ivec2 a_pos_int;
      #endif
      
      layout(binding = 0) uniform Locals {
          mat4 u_mvp;
          vec4 u_color;
          vec2 u_scale;
      };
      
      void main() {
      #ifdef QSHADER_GLSL
          // no op
      #else
          vec2 a_pos = vec2(a_pos_int);
      #endif
          gl_Position = u_mvp * vec4(a_pos, 0.0, 1.0);
      }
      

      cmake

      qt6_add_shaders(appbasis "vtm_uniform_shaders"
      	PERTARGETCOMPILE
      	GLSL_DEFINES "QSHADER_GLSL=true"
      	#DEFINES "QSHADER_GLSL=true"
      	FILES
      		vtm/shaders/uniform/base_shader.vert
      )
      

      ``qbs --dump`` version 1:

      Stage: Vertex
      QSB_VERSION: 9
      Has 6 shaders:
        Shader 0: SPIR-V 100 [Standard]
        Shader 1: GLSL 100 es [Standard]
        Shader 2: GLSL 120 [Standard]
        Shader 3: GLSL 150 [Standard]
        Shader 4: HLSL 50 [Standard]
        Shader 5: MSL 12 [Standard]
      
      Reflection info: {
          "inputs": [
              {
                  "location": 0,
                  "name": "a_pos_int",
                  "type": "ivec2"
              }
          ],
          "outBuiltins": [
              {
                  "name": "Position",
                  "type": "vec4"
              }
          ],
          "uniformBlocks": [
              {
                  "binding": 0,
                  "blockName": "Locals",
                  "members": [
                      {
                          "matrixStride": 16,
                          "name": "u_mvp",
                          "offset": 0,
                          "size": 64,
                          "type": "mat4"
                      },
                      {
                          "name": "u_color",
                          "offset": 64,
                          "size": 16,
                          "type": "vec4"
                      },
                      {
                          "name": "u_scale",
                          "offset": 80,
                          "size": 8,
                          "type": "vec2"
                      }
                  ],
                  "set": 0,
                  "size": 88,
                  "structName": "_27"
              }
          ]
      }
      
      
      Shader 0: SPIR-V 100 [Standard]
      Entry point: main
      Contents:
      Binary of 1004 bytes
      
      
      ************************************
      
      Shader 1: GLSL 100 es [Standard]
      Entry point: main
      Contents:
      #version 100
      
      struct Locals
      {
          mat4 u_mvp;
          vec4 u_color;
          vec2 u_scale;
      };
      
      uniform Locals _20;
      
      attribute vec2 a_pos;
      
      void main()
      {
          gl_Position = _20.u_mvp * vec4(a_pos, 0.0, 1.0);
      }
      
      
      
      ************************************
      
      Shader 2: GLSL 120 [Standard]
      Entry point: main
      Contents:
      #version 120
      
      struct Locals
      {
          mat4 u_mvp;
          vec4 u_color;
          vec2 u_scale;
      };
      
      uniform Locals _20;
      
      attribute vec2 a_pos;
      
      void main()
      {
          gl_Position = _20.u_mvp * vec4(a_pos, 0.0, 1.0);
      }
      
      
      
      ************************************
      
      Shader 3: GLSL 150 [Standard]
      Entry point: main
      Contents:
      #version 150
      
      struct Locals
      {
          mat4 u_mvp;
          vec4 u_color;
          vec2 u_scale;
      };
      
      uniform Locals _20;
      
      in vec2 a_pos;
      
      void main()
      {
          gl_Position = _20.u_mvp * vec4(a_pos, 0.0, 1.0);
      }
      
      
      
      ************************************
      
      Shader 4: HLSL 50 [Standard]
      Entry point: main
      Native resource binding map:
      0 -> [0, -1]
      Contents:
      cbuffer Locals : register(b0)
      {
          row_major float4x4 _27_u_mvp : packoffset(c0);
          float4 _27_u_color : packoffset(c4);
          float2 _27_u_scale : packoffset(c5);
      };
      
      
      static float4 gl_Position;
      static int2 a_pos_int;
      
      struct SPIRV_Cross_Input
      {
          int2 a_pos_int : TEXCOORD0;
      };
      
      struct SPIRV_Cross_Output
      {
          float4 gl_Position : SV_Position;
      };
      
      void vert_main()
      {
          float2 a_pos = float2(a_pos_int);
          gl_Position = mul(float4(a_pos, 0.0f, 1.0f), _27_u_mvp);
      }
      
      SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
      {
          a_pos_int = stage_input.a_pos_int;
          vert_main();
          SPIRV_Cross_Output stage_output;
          stage_output.gl_Position = gl_Position;
          return stage_output;
      }
      
      
      ************************************
      
      Shader 5: MSL 12 [Standard]
      Entry point: main0
      Native resource binding map:
      0 -> [0, -1]
      Contents:
      #include <metal_stdlib>
      #include <simd/simd.h>
      
      using namespace metal;
      
      struct Locals
      {
          float4x4 u_mvp;
          float4 u_color;
          float2 u_scale;
      };
      
      struct main0_out
      {
          float4 gl_Position [[position]];
      };
      
      struct main0_in
      {
          int2 a_pos_int [[attribute(0)]];
      };
      
      vertex main0_out main0(main0_in in [[stage_in]], constant Locals& _27 [[buffer(0)]])
      {
          main0_out out = {};
          float2 a_pos = float2(in.a_pos_int);
          out.gl_Position = _27.u_mvp * float4(a_pos, 0.0, 1.0);
          return out;
      }
      
      
      
      ************************************
      

      ``qbs --dump`` version 2:

      Stage: Vertex
      QSB_VERSION: 9
      Has 6 shaders:
        Shader 0: SPIR-V 100 [Standard]
        Shader 1: GLSL 100 es [Standard]
        Shader 2: GLSL 120 [Standard]
        Shader 3: GLSL 150 [Standard]
        Shader 4: HLSL 50 [Standard]
        Shader 5: MSL 12 [Standard]
      
      Reflection info: {
          "inputs": [
              {
                  "location": 0,
                  "name": "a_pos",
                  "type": "vec2"
              }
          ],
          "outBuiltins": [
              {
                  "name": "Position",
                  "type": "vec4"
              }
          ],
          "uniformBlocks": [
              {
                  "binding": 0,
                  "blockName": "Locals",
                  "members": [
                      {
                          "matrixStride": 16,
                          "name": "u_mvp",
                          "offset": 0,
                          "size": 64,
                          "type": "mat4"
                      },
                      {
                          "name": "u_color",
                          "offset": 64,
                          "size": 16,
                          "type": "vec4"
                      },
                      {
                          "name": "u_scale",
                          "offset": 80,
                          "size": 8,
                          "type": "vec2"
                      }
                  ],
                  "set": 0,
                  "size": 88,
                  "structName": "_20"
              }
          ]
      }
      
      
      Shader 0: SPIR-V 100 [Standard]
      Entry point: main
      Contents:
      Binary of 1004 bytes
      
      
      ************************************
      
      Shader 1: GLSL 100 es [Standard]
      Entry point: main
      Contents:
      #version 100
      
      struct Locals
      {
          mat4 u_mvp;
          vec4 u_color;
          vec2 u_scale;
      };
      
      uniform Locals _20;
      
      attribute vec2 a_pos;
      
      void main()
      {
          gl_Position = _20.u_mvp * vec4(a_pos, 0.0, 1.0);
      }
      
      
      
      ************************************
      
      Shader 2: GLSL 120 [Standard]
      Entry point: main
      Contents:
      #version 120
      
      struct Locals
      {
          mat4 u_mvp;
          vec4 u_color;
          vec2 u_scale;
      };
      
      uniform Locals _20;
      
      attribute vec2 a_pos;
      
      void main()
      {
          gl_Position = _20.u_mvp * vec4(a_pos, 0.0, 1.0);
      }
      
      
      
      ************************************
      
      Shader 3: GLSL 150 [Standard]
      Entry point: main
      Contents:
      #version 150
      
      struct Locals
      {
          mat4 u_mvp;
          vec4 u_color;
          vec2 u_scale;
      };
      
      uniform Locals _20;
      
      in vec2 a_pos;
      
      void main()
      {
          gl_Position = _20.u_mvp * vec4(a_pos, 0.0, 1.0);
      }
      
      
      
      ************************************
      
      Shader 4: HLSL 50 [Standard]
      Entry point: main
      Native resource binding map:
      0 -> [0, -1]
      Contents:
      cbuffer Locals : register(b0)
      {
          row_major float4x4 _27_u_mvp : packoffset(c0);
          float4 _27_u_color : packoffset(c4);
          float2 _27_u_scale : packoffset(c5);
      };
      
      
      static float4 gl_Position;
      static int2 a_pos_int;
      
      struct SPIRV_Cross_Input
      {
          int2 a_pos_int : TEXCOORD0;
      };
      
      struct SPIRV_Cross_Output
      {
          float4 gl_Position : SV_Position;
      };
      
      void vert_main()
      {
          float2 a_pos = float2(a_pos_int);
          gl_Position = mul(float4(a_pos, 0.0f, 1.0f), _27_u_mvp);
      }
      
      SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
      {
          a_pos_int = stage_input.a_pos_int;
          vert_main();
          SPIRV_Cross_Output stage_output;
          stage_output.gl_Position = gl_Position;
          return stage_output;
      }
      
      
      ************************************
      
      Shader 5: MSL 12 [Standard]
      Entry point: main0
      Native resource binding map:
      0 -> [0, -1]
      Contents:
      #include <metal_stdlib>
      #include <simd/simd.h>
      
      using namespace metal;
      
      struct Locals
      {
          float4x4 u_mvp;
          float4 u_color;
          float2 u_scale;
      };
      
      struct main0_out
      {
          float4 gl_Position [[position]];
      };
      
      struct main0_in
      {
          int2 a_pos_int [[attribute(0)]];
      };
      
      vertex main0_out main0(main0_in in [[stage_in]], constant Locals& _27 [[buffer(0)]])
      {
          main0_out out = {};
          float2 a_pos = float2(in.a_pos_int);
          out.gl_Position = _27.u_mvp * float4(a_pos, 0.0, 1.0);
          return out;
      }
      
      
      
      ************************************
      

      ``qt6_add_shaders``/``qbs`` seems to randomly generate one of these two versions (notice the different "Reflection info" entries). The problem is that the QRhi OpenGL backend works only with version 2 (Vulkan, DirectX, Metal seem to ignore this).

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

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

              Created:
              Updated:

                There are no open Gerrit changes