#extension GL_ARB_gpu_shader5 support the implicit conversion ,
authorZhiqianXia <xzq0528@outlook.com>
Mon, 2 Aug 2021 08:41:21 +0000 (16:41 +0800)
committerZhiqianXia <xzq0528@outlook.com>
Wed, 10 Nov 2021 01:44:16 +0000 (09:44 +0800)
So the best function matching algorithm should be actived.

Signed-off-by: ZhiqianXia <xzq0528@outlook.com>
Test/BestMatchFunction.vert [new file with mode: 0644]
Test/baseResults/BestMatchFunction.vert.out [new file with mode: 0644]
glslang/MachineIndependent/ParseHelper.cpp
gtests/AST.FromFile.cpp

diff --git a/Test/BestMatchFunction.vert b/Test/BestMatchFunction.vert
new file mode 100644 (file)
index 0000000..eb09233
--- /dev/null
@@ -0,0 +1,20 @@
+#version 150
+#extension GL_ARB_gpu_shader5 : require
+
+uniform ivec4 u1;
+uniform uvec4 u2;
+out     vec4  result;
+vec4 f(in vec4 a, in vec4 b){ return a * b;}           // choice 1
+vec4 f(in uvec4 a, in uvec4 b){ return vec4(a - b);}   // choice 2
+
+void main()
+{
+    result = f(u1, u2); // should match choice 2. which have less implicit conversion. 
+    switch (gl_VertexID)
+    {
+      case 0: gl_Position = vec4(-1.0, 1.0, 0.0, 1.0); break;
+      case 1: gl_Position = vec4( 1.0, 1.0, 0.0, 1.0); break;
+      case 2: gl_Position = vec4(-1.0,-1.0, 0.0, 1.0); break;
+      case 3: gl_Position = vec4( 1.0,-1.0, 0.0, 1.0); break;
+    }
+}
diff --git a/Test/baseResults/BestMatchFunction.vert.out b/Test/baseResults/BestMatchFunction.vert.out
new file mode 100644 (file)
index 0000000..843ffd7
--- /dev/null
@@ -0,0 +1,206 @@
+BestMatchFunction.vert
+WARNING: 0:2: '#extension' : extension is only partially supported: GL_ARB_gpu_shader5
+
+Shader version: 150
+Requested GL_ARB_gpu_shader5
+0:? Sequence
+0:7  Function Definition: f(vf4;vf4; ( global 4-component vector of float)
+0:7    Function Parameters: 
+0:7      'a' ( in 4-component vector of float)
+0:7      'b' ( in 4-component vector of float)
+0:7    Sequence
+0:7      Branch: Return with expression
+0:7        component-wise multiply ( temp 4-component vector of float)
+0:7          'a' ( in 4-component vector of float)
+0:7          'b' ( in 4-component vector of float)
+0:8  Function Definition: f(vu4;vu4; ( global 4-component vector of float)
+0:8    Function Parameters: 
+0:8      'a' ( in 4-component vector of uint)
+0:8      'b' ( in 4-component vector of uint)
+0:8    Sequence
+0:8      Branch: Return with expression
+0:8        Convert uint to float ( temp 4-component vector of float)
+0:8          subtract ( temp 4-component vector of uint)
+0:8            'a' ( in 4-component vector of uint)
+0:8            'b' ( in 4-component vector of uint)
+0:10  Function Definition: main( ( global void)
+0:10    Function Parameters: 
+0:12    Sequence
+0:12      move second child to first child ( temp 4-component vector of float)
+0:12        'result' ( smooth out 4-component vector of float)
+0:12        Function Call: f(vu4;vu4; ( global 4-component vector of float)
+0:12          Convert int to uint ( temp 4-component vector of uint)
+0:12            'u1' ( uniform 4-component vector of int)
+0:12          'u2' ( uniform 4-component vector of uint)
+0:13      switch
+0:13      condition
+0:13        'gl_VertexID' ( gl_VertexId int VertexId)
+0:13      body
+0:13        Sequence
+0:15          case:  with expression
+0:15            Constant:
+0:15              0 (const int)
+0:?           Sequence
+0:15            move second child to first child ( temp 4-component vector of float)
+0:15              gl_Position: direct index for structure ( gl_Position 4-component vector of float Position)
+0:15                'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position,  gl_PointSize float PointSize gl_PointSize,  out unsized 1-element array of float ClipDistance gl_ClipDistance})
+0:15                Constant:
+0:15                  0 (const uint)
+0:15              Constant:
+0:15                -1.000000
+0:15                1.000000
+0:15                0.000000
+0:15                1.000000
+0:15            Branch: Break
+0:16          case:  with expression
+0:16            Constant:
+0:16              1 (const int)
+0:?           Sequence
+0:16            move second child to first child ( temp 4-component vector of float)
+0:16              gl_Position: direct index for structure ( gl_Position 4-component vector of float Position)
+0:16                'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position,  gl_PointSize float PointSize gl_PointSize,  out unsized 1-element array of float ClipDistance gl_ClipDistance})
+0:16                Constant:
+0:16                  0 (const uint)
+0:16              Constant:
+0:16                1.000000
+0:16                1.000000
+0:16                0.000000
+0:16                1.000000
+0:16            Branch: Break
+0:17          case:  with expression
+0:17            Constant:
+0:17              2 (const int)
+0:?           Sequence
+0:17            move second child to first child ( temp 4-component vector of float)
+0:17              gl_Position: direct index for structure ( gl_Position 4-component vector of float Position)
+0:17                'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position,  gl_PointSize float PointSize gl_PointSize,  out unsized 1-element array of float ClipDistance gl_ClipDistance})
+0:17                Constant:
+0:17                  0 (const uint)
+0:17              Constant:
+0:17                -1.000000
+0:17                -1.000000
+0:17                0.000000
+0:17                1.000000
+0:17            Branch: Break
+0:18          case:  with expression
+0:18            Constant:
+0:18              3 (const int)
+0:?           Sequence
+0:18            move second child to first child ( temp 4-component vector of float)
+0:18              gl_Position: direct index for structure ( gl_Position 4-component vector of float Position)
+0:18                'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position,  gl_PointSize float PointSize gl_PointSize,  out unsized 1-element array of float ClipDistance gl_ClipDistance})
+0:18                Constant:
+0:18                  0 (const uint)
+0:18              Constant:
+0:18                1.000000
+0:18                -1.000000
+0:18                0.000000
+0:18                1.000000
+0:18            Branch: Break
+0:?   Linker Objects
+0:?     'u1' ( uniform 4-component vector of int)
+0:?     'u2' ( uniform 4-component vector of uint)
+0:?     'result' ( smooth out 4-component vector of float)
+0:?     'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position,  gl_PointSize float PointSize gl_PointSize,  out unsized 1-element array of float ClipDistance gl_ClipDistance})
+0:?     'gl_VertexID' ( gl_VertexId int VertexId)
+0:?     'gl_InstanceID' ( gl_InstanceId int InstanceId)
+
+
+Linked vertex stage:
+
+
+Shader version: 150
+Requested GL_ARB_gpu_shader5
+0:? Sequence
+0:8  Function Definition: f(vu4;vu4; ( global 4-component vector of float)
+0:8    Function Parameters: 
+0:8      'a' ( in 4-component vector of uint)
+0:8      'b' ( in 4-component vector of uint)
+0:8    Sequence
+0:8      Branch: Return with expression
+0:8        Convert uint to float ( temp 4-component vector of float)
+0:8          subtract ( temp 4-component vector of uint)
+0:8            'a' ( in 4-component vector of uint)
+0:8            'b' ( in 4-component vector of uint)
+0:10  Function Definition: main( ( global void)
+0:10    Function Parameters: 
+0:12    Sequence
+0:12      move second child to first child ( temp 4-component vector of float)
+0:12        'result' ( smooth out 4-component vector of float)
+0:12        Function Call: f(vu4;vu4; ( global 4-component vector of float)
+0:12          Convert int to uint ( temp 4-component vector of uint)
+0:12            'u1' ( uniform 4-component vector of int)
+0:12          'u2' ( uniform 4-component vector of uint)
+0:13      switch
+0:13      condition
+0:13        'gl_VertexID' ( gl_VertexId int VertexId)
+0:13      body
+0:13        Sequence
+0:15          case:  with expression
+0:15            Constant:
+0:15              0 (const int)
+0:?           Sequence
+0:15            move second child to first child ( temp 4-component vector of float)
+0:15              gl_Position: direct index for structure ( gl_Position 4-component vector of float Position)
+0:15                'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position,  gl_PointSize float PointSize gl_PointSize,  out 1-element array of float ClipDistance gl_ClipDistance})
+0:15                Constant:
+0:15                  0 (const uint)
+0:15              Constant:
+0:15                -1.000000
+0:15                1.000000
+0:15                0.000000
+0:15                1.000000
+0:15            Branch: Break
+0:16          case:  with expression
+0:16            Constant:
+0:16              1 (const int)
+0:?           Sequence
+0:16            move second child to first child ( temp 4-component vector of float)
+0:16              gl_Position: direct index for structure ( gl_Position 4-component vector of float Position)
+0:16                'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position,  gl_PointSize float PointSize gl_PointSize,  out 1-element array of float ClipDistance gl_ClipDistance})
+0:16                Constant:
+0:16                  0 (const uint)
+0:16              Constant:
+0:16                1.000000
+0:16                1.000000
+0:16                0.000000
+0:16                1.000000
+0:16            Branch: Break
+0:17          case:  with expression
+0:17            Constant:
+0:17              2 (const int)
+0:?           Sequence
+0:17            move second child to first child ( temp 4-component vector of float)
+0:17              gl_Position: direct index for structure ( gl_Position 4-component vector of float Position)
+0:17                'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position,  gl_PointSize float PointSize gl_PointSize,  out 1-element array of float ClipDistance gl_ClipDistance})
+0:17                Constant:
+0:17                  0 (const uint)
+0:17              Constant:
+0:17                -1.000000
+0:17                -1.000000
+0:17                0.000000
+0:17                1.000000
+0:17            Branch: Break
+0:18          case:  with expression
+0:18            Constant:
+0:18              3 (const int)
+0:?           Sequence
+0:18            move second child to first child ( temp 4-component vector of float)
+0:18              gl_Position: direct index for structure ( gl_Position 4-component vector of float Position)
+0:18                'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position,  gl_PointSize float PointSize gl_PointSize,  out 1-element array of float ClipDistance gl_ClipDistance})
+0:18                Constant:
+0:18                  0 (const uint)
+0:18              Constant:
+0:18                1.000000
+0:18                -1.000000
+0:18                0.000000
+0:18                1.000000
+0:18            Branch: Break
+0:?   Linker Objects
+0:?     'u1' ( uniform 4-component vector of int)
+0:?     'u2' ( uniform 4-component vector of uint)
+0:?     'result' ( smooth out 4-component vector of float)
+0:?     'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position,  gl_PointSize float PointSize gl_PointSize,  out 1-element array of float ClipDistance gl_ClipDistance})
+0:?     'gl_VertexID' ( gl_VertexId int VertexId)
+0:?     'gl_InstanceID' ( gl_InstanceId int InstanceId)
+
index 9ab1207..e4d4791 100644 (file)
@@ -6650,8 +6650,10 @@ const TFunction* TParseContext::findFunction(const TSourceLoc& loc, const TFunct
                       : findFunctionExact(loc, call, builtIn));
     else if (version < 120)
         function = findFunctionExact(loc, call, builtIn);
-    else if (version < 400)
-        function = extensionTurnedOn(E_GL_ARB_gpu_shader_fp64) ? findFunction400(loc, call, builtIn) : findFunction120(loc, call, builtIn);
+    else if (version < 400) {
+        bool needfindFunction400 = extensionTurnedOn(E_GL_ARB_gpu_shader_fp64) || extensionTurnedOn(E_GL_ARB_gpu_shader5);
+        function = needfindFunction400 ? findFunction400(loc, call, builtIn) : findFunction120(loc, call, builtIn);
+    }
     else if (explicitTypesEnabled)
         function = findFunctionExplicitTypes(loc, call, builtIn);
     else
index f9680dd..6976d9e 100644 (file)
@@ -287,6 +287,7 @@ INSTANTIATE_TEST_SUITE_P(
         "atomicCounterARBOps.vert",
         "GL_EXT_shader_integer_mix.vert",
         "GL_ARB_draw_instanced.vert",
+        "BestMatchFunction.vert",
     })),
     FileNameAsCustomTestSuffix
 );