From 4ae01c5f41ed7c52ce9fe178293ee98e6f972dbd Mon Sep 17 00:00:00 2001 From: Dawid Lorenz Date: Mon, 3 Jul 2023 15:19:41 +0200 Subject: [PATCH] Add support for pre and post HLSL qualifier validation The change makes it possible to define a const variable after the marked type. Example "float const" --- Test/baseResults/hlsl.function.frag.out | 158 +++++++----- Test/baseResults/hlsl.init2.frag.out | 304 ++++++++++++------------ Test/hlsl.function.frag | 11 +- Test/hlsl.init2.frag | 21 +- glslang/HLSL/hlslGrammar.cpp | 31 ++- glslang/HLSL/hlslGrammar.h | 4 +- 6 files changed, 300 insertions(+), 229 deletions(-) diff --git a/Test/baseResults/hlsl.function.frag.out b/Test/baseResults/hlsl.function.frag.out index faa31479..bfa5af4d 100644 --- a/Test/baseResults/hlsl.function.frag.out +++ b/Test/baseResults/hlsl.function.frag.out @@ -1,6 +1,6 @@ hlsl.function.frag -ERROR: 0:24: 'fun1' : unknown variable -ERROR: 0:24: 'return' : type does not match, or is not convertible to, the function's return type +ERROR: 0:29: 'fun1' : unknown variable +ERROR: 0:29: 'return' : type does not match, or is not convertible to, the function's return type ERROR: 2 compilation errors. No code generated. @@ -16,45 +16,64 @@ ERROR: node is still EOpNull! 0:3 1.000000 0:3 1.000000 0:3 1.000000 -0:7 Function Definition: fun2(vf4; ( temp uint) +0:7 Function Definition: fun2(vf4; ( temp 4-component vector of float) 0:7 Function Parameters: -0:7 'col' ( in 4-component vector of float) +0:7 'col' ( const (read only) 4-component vector of float) 0:? Sequence 0:8 Branch: Return with expression -0:8 Constant: -0:8 7 (const uint) -0:12 Function Definition: fun4(u1;u1; ( temp 4-component vector of float) +0:8 Construct vec4 ( temp 4-component vector of float) +0:8 Convert int to float ( temp float) +0:8 Comma ( temp int) +0:8 Comma ( temp int) +0:8 Comma ( temp int) +0:8 Constant: +0:8 1 (const int) +0:8 Constant: +0:8 2 (const int) +0:8 Constant: +0:8 3 (const int) +0:8 Constant: +0:8 4 (const int) +0:12 Function Definition: fun3(vf4; ( temp uint) 0:12 Function Parameters: -0:12 'id1' ( in uint) -0:12 'id2' ( uniform uint) +0:12 'col' ( const (read only) 4-component vector of float) 0:? Sequence 0:13 Branch: Return with expression -0:13 Construct vec4 ( temp 4-component vector of float) -0:13 Convert uint to float ( temp float) -0:13 component-wise multiply ( temp uint) -0:13 'id1' ( in uint) -0:13 'id2' ( uniform uint) -0:17 Function Definition: fun1(i1; ( temp 4-component vector of float) +0:13 Constant: +0:13 7 (const uint) +0:17 Function Definition: fun4(u1;u1; ( temp 4-component vector of float) 0:17 Function Parameters: -0:17 'index' ( in int) +0:17 'id1' ( in uint) +0:17 'id2' ( uniform uint) 0:? Sequence -0:18 Sequence -0:18 move second child to first child ( temp uint) -0:18 'entityId' ( temp uint) -0:18 Function Call: fun2(vf4; ( temp uint) -0:18 Function Call: fun0( ( temp 4-component vector of float) -0:19 Branch: Return with expression -0:19 Function Call: fun4(u1;u1; ( temp 4-component vector of float) -0:19 'entityId' ( temp uint) -0:19 'entityId' ( temp uint) -0:23 Function Definition: @main( ( temp int) -0:23 Function Parameters: -0:23 Function Definition: main( ( temp void) -0:23 Function Parameters: +0:18 Branch: Return with expression +0:18 Construct vec4 ( temp 4-component vector of float) +0:18 Convert uint to float ( temp float) +0:18 component-wise multiply ( temp uint) +0:18 'id1' ( in uint) +0:18 'id2' ( uniform uint) +0:22 Function Definition: fun1(i1; ( temp 4-component vector of float) +0:22 Function Parameters: +0:22 'index' ( in int) 0:? Sequence -0:23 move second child to first child ( temp int) +0:23 Sequence +0:23 move second child to first child ( temp uint) +0:23 'entityId' ( temp uint) +0:23 Function Call: fun3(vf4; ( temp uint) +0:23 Function Call: fun2(vf4; ( temp 4-component vector of float) +0:23 Function Call: fun0( ( temp 4-component vector of float) +0:24 Branch: Return with expression +0:24 Function Call: fun4(u1;u1; ( temp 4-component vector of float) +0:24 'entityId' ( temp uint) +0:24 'entityId' ( temp uint) +0:28 Function Definition: @main( ( temp int) +0:28 Function Parameters: +0:28 Function Definition: main( ( temp void) +0:28 Function Parameters: +0:? Sequence +0:28 move second child to first child ( temp int) 0:? '@entryPointOutput' (layout( location=0) out int) -0:23 Function Call: @main( ( temp int) +0:28 Function Call: @main( ( temp int) 0:? Linker Objects 0:? '@entryPointOutput' (layout( location=0) out int) @@ -74,45 +93,64 @@ ERROR: node is still EOpNull! 0:3 1.000000 0:3 1.000000 0:3 1.000000 -0:7 Function Definition: fun2(vf4; ( temp uint) +0:7 Function Definition: fun2(vf4; ( temp 4-component vector of float) 0:7 Function Parameters: -0:7 'col' ( in 4-component vector of float) +0:7 'col' ( const (read only) 4-component vector of float) 0:? Sequence 0:8 Branch: Return with expression -0:8 Constant: -0:8 7 (const uint) -0:12 Function Definition: fun4(u1;u1; ( temp 4-component vector of float) +0:8 Construct vec4 ( temp 4-component vector of float) +0:8 Convert int to float ( temp float) +0:8 Comma ( temp int) +0:8 Comma ( temp int) +0:8 Comma ( temp int) +0:8 Constant: +0:8 1 (const int) +0:8 Constant: +0:8 2 (const int) +0:8 Constant: +0:8 3 (const int) +0:8 Constant: +0:8 4 (const int) +0:12 Function Definition: fun3(vf4; ( temp uint) 0:12 Function Parameters: -0:12 'id1' ( in uint) -0:12 'id2' ( uniform uint) +0:12 'col' ( const (read only) 4-component vector of float) 0:? Sequence 0:13 Branch: Return with expression -0:13 Construct vec4 ( temp 4-component vector of float) -0:13 Convert uint to float ( temp float) -0:13 component-wise multiply ( temp uint) -0:13 'id1' ( in uint) -0:13 'id2' ( uniform uint) -0:17 Function Definition: fun1(i1; ( temp 4-component vector of float) +0:13 Constant: +0:13 7 (const uint) +0:17 Function Definition: fun4(u1;u1; ( temp 4-component vector of float) 0:17 Function Parameters: -0:17 'index' ( in int) +0:17 'id1' ( in uint) +0:17 'id2' ( uniform uint) 0:? Sequence -0:18 Sequence -0:18 move second child to first child ( temp uint) -0:18 'entityId' ( temp uint) -0:18 Function Call: fun2(vf4; ( temp uint) -0:18 Function Call: fun0( ( temp 4-component vector of float) -0:19 Branch: Return with expression -0:19 Function Call: fun4(u1;u1; ( temp 4-component vector of float) -0:19 'entityId' ( temp uint) -0:19 'entityId' ( temp uint) -0:23 Function Definition: @main( ( temp int) -0:23 Function Parameters: -0:23 Function Definition: main( ( temp void) -0:23 Function Parameters: +0:18 Branch: Return with expression +0:18 Construct vec4 ( temp 4-component vector of float) +0:18 Convert uint to float ( temp float) +0:18 component-wise multiply ( temp uint) +0:18 'id1' ( in uint) +0:18 'id2' ( uniform uint) +0:22 Function Definition: fun1(i1; ( temp 4-component vector of float) +0:22 Function Parameters: +0:22 'index' ( in int) 0:? Sequence -0:23 move second child to first child ( temp int) +0:23 Sequence +0:23 move second child to first child ( temp uint) +0:23 'entityId' ( temp uint) +0:23 Function Call: fun3(vf4; ( temp uint) +0:23 Function Call: fun2(vf4; ( temp 4-component vector of float) +0:23 Function Call: fun0( ( temp 4-component vector of float) +0:24 Branch: Return with expression +0:24 Function Call: fun4(u1;u1; ( temp 4-component vector of float) +0:24 'entityId' ( temp uint) +0:24 'entityId' ( temp uint) +0:28 Function Definition: @main( ( temp int) +0:28 Function Parameters: +0:28 Function Definition: main( ( temp void) +0:28 Function Parameters: +0:? Sequence +0:28 move second child to first child ( temp int) 0:? '@entryPointOutput' (layout( location=0) out int) -0:23 Function Call: @main( ( temp int) +0:28 Function Call: @main( ( temp int) 0:? Linker Objects 0:? '@entryPointOutput' (layout( location=0) out int) diff --git a/Test/baseResults/hlsl.init2.frag.out b/Test/baseResults/hlsl.init2.frag.out index b8b7afcd..bf6d6461 100644 --- a/Test/baseResults/hlsl.init2.frag.out +++ b/Test/baseResults/hlsl.init2.frag.out @@ -31,29 +31,20 @@ gl_FragCoord origin is upper left 0:20 10.000000 0:22 Constant: 0:22 10.000000 -0:25 Sequence -0:25 move second child to first child ( temp float) -0:25 'n' ( temp float) -0:25 Constant: -0:25 0.000000 0:26 Sequence -0:26 move second child to first child ( temp 8-element array of 3-component vector of float) -0:26 'a' ( const (read only) 8-element array of 3-component vector of float) -0:26 Construct vec3 ( temp 8-element array of 3-component vector of float) -0:27 vector-scale ( temp 3-component vector of float) -0:27 Constant: -0:27 0.577350 -0:27 0.577350 -0:27 0.577350 -0:27 add second child into first child ( temp float) -0:27 'n' ( temp float) -0:27 Constant: -0:27 1.000000 +0:26 move second child to first child ( temp float) +0:26 'n' ( temp float) +0:26 Constant: +0:26 0.000000 +0:27 Sequence +0:27 move second child to first child ( temp 8-element array of 3-component vector of float) +0:27 'a' ( const (read only) 8-element array of 3-component vector of float) +0:27 Construct vec3 ( temp 8-element array of 3-component vector of float) 0:28 vector-scale ( temp 3-component vector of float) 0:28 Constant: -0:28 -0.577350 -0:28 -0.577350 -0:28 -0.577350 +0:28 0.577350 +0:28 0.577350 +0:28 0.577350 0:28 add second child into first child ( temp float) 0:28 'n' ( temp float) 0:28 Constant: @@ -62,7 +53,7 @@ gl_FragCoord origin is upper left 0:29 Constant: 0:29 -0.577350 0:29 -0.577350 -0:29 0.577350 +0:29 -0.577350 0:29 add second child into first child ( temp float) 0:29 'n' ( temp float) 0:29 Constant: @@ -70,8 +61,8 @@ gl_FragCoord origin is upper left 0:30 vector-scale ( temp 3-component vector of float) 0:30 Constant: 0:30 -0.577350 -0:30 0.577350 0:30 -0.577350 +0:30 0.577350 0:30 add second child into first child ( temp float) 0:30 'n' ( temp float) 0:30 Constant: @@ -80,16 +71,16 @@ gl_FragCoord origin is upper left 0:31 Constant: 0:31 -0.577350 0:31 0.577350 -0:31 0.577350 +0:31 -0.577350 0:31 add second child into first child ( temp float) 0:31 'n' ( temp float) 0:31 Constant: 0:31 1.000000 0:32 vector-scale ( temp 3-component vector of float) 0:32 Constant: +0:32 -0.577350 +0:32 0.577350 0:32 0.577350 -0:32 -0.577350 -0:32 -0.577350 0:32 add second child into first child ( temp float) 0:32 'n' ( temp float) 0:32 Constant: @@ -98,7 +89,7 @@ gl_FragCoord origin is upper left 0:33 Constant: 0:33 0.577350 0:33 -0.577350 -0:33 0.577350 +0:33 -0.577350 0:33 add second child into first child ( temp float) 0:33 'n' ( temp float) 0:33 Constant: @@ -106,38 +97,38 @@ gl_FragCoord origin is upper left 0:34 vector-scale ( temp 3-component vector of float) 0:34 Constant: 0:34 0.577350 -0:34 0.577350 0:34 -0.577350 +0:34 0.577350 0:34 add second child into first child ( temp float) 0:34 'n' ( temp float) 0:34 Constant: 0:34 1.000000 -0:36 Sequence -0:36 move second child to first child ( temp structure{ temp 3-component vector of float a}) -0:36 'oneNonConst' ( const (read only) structure{ temp 3-component vector of float a}) -0:36 Construct structure ( temp structure{ temp 3-component vector of float a}) -0:36 vector-scale ( temp 3-component vector of float) -0:36 Constant: -0:36 -0.577350 -0:36 0.577350 -0:36 0.577350 -0:36 add second child into first child ( temp float) -0:36 'n' ( temp float) -0:36 Constant: -0:36 1.000000 -0:38 Sequence -0:38 move second child to first child ( temp structure{ temp 3-component vector of float a, temp 3-component vector of float b}) -0:38 'twoNonConst' ( const (read only) structure{ temp 3-component vector of float a, temp 3-component vector of float b}) -0:38 Construct structure ( temp structure{ temp 3-component vector of float a, temp 3-component vector of float b}) -0:38 vector-scale ( temp 3-component vector of float) -0:38 Constant: -0:38 -0.577350 -0:38 0.577350 -0:38 0.577350 -0:38 add second child into first child ( temp float) -0:38 'n' ( temp float) -0:38 Constant: -0:38 1.000000 +0:35 vector-scale ( temp 3-component vector of float) +0:35 Constant: +0:35 0.577350 +0:35 0.577350 +0:35 -0.577350 +0:35 add second child into first child ( temp float) +0:35 'n' ( temp float) +0:35 Constant: +0:35 1.000000 +0:37 Sequence +0:37 move second child to first child ( temp structure{ temp 3-component vector of float a}) +0:37 'oneNonConst' ( const (read only) structure{ temp 3-component vector of float a}) +0:37 Construct structure ( temp structure{ temp 3-component vector of float a}) +0:37 vector-scale ( temp 3-component vector of float) +0:37 Constant: +0:37 -0.577350 +0:37 0.577350 +0:37 0.577350 +0:37 add second child into first child ( temp float) +0:37 'n' ( temp float) +0:37 Constant: +0:37 1.000000 +0:39 Sequence +0:39 move second child to first child ( temp structure{ temp 3-component vector of float a, temp 3-component vector of float b}) +0:39 'twoNonConst' ( const (read only) structure{ temp 3-component vector of float a, temp 3-component vector of float b}) +0:39 Construct structure ( temp structure{ temp 3-component vector of float a, temp 3-component vector of float b}) 0:39 vector-scale ( temp 3-component vector of float) 0:39 Constant: 0:39 -0.577350 @@ -147,32 +138,41 @@ gl_FragCoord origin is upper left 0:39 'n' ( temp float) 0:39 Constant: 0:39 1.000000 -0:45 Function Definition: @main( ( temp structure{ temp 4-component vector of float color}) -0:45 Function Parameters: +0:40 vector-scale ( temp 3-component vector of float) +0:40 Constant: +0:40 -0.577350 +0:40 0.577350 +0:40 0.577350 +0:40 add second child into first child ( temp float) +0:40 'n' ( temp float) +0:40 Constant: +0:40 1.000000 +0:46 Function Definition: @main( ( temp structure{ temp 4-component vector of float color}) +0:46 Function Parameters: 0:? Sequence -0:46 Function Call: Test1( ( temp void) -0:49 move second child to first child ( temp 4-component vector of float) -0:49 color: direct index for structure ( temp 4-component vector of float) -0:49 'ps_output' ( temp structure{ temp 4-component vector of float color}) -0:49 Constant: -0:49 0 (const int) -0:49 Constant: -0:49 1.000000 -0:49 1.000000 -0:49 1.000000 -0:49 1.000000 -0:50 Branch: Return with expression -0:50 'ps_output' ( temp structure{ temp 4-component vector of float color}) -0:45 Function Definition: main( ( temp void) -0:45 Function Parameters: +0:47 Function Call: Test1( ( temp void) +0:50 move second child to first child ( temp 4-component vector of float) +0:50 color: direct index for structure ( temp 4-component vector of float) +0:50 'ps_output' ( temp structure{ temp 4-component vector of float color}) +0:50 Constant: +0:50 0 (const int) +0:50 Constant: +0:50 1.000000 +0:50 1.000000 +0:50 1.000000 +0:50 1.000000 +0:51 Branch: Return with expression +0:51 'ps_output' ( temp structure{ temp 4-component vector of float color}) +0:46 Function Definition: main( ( temp void) +0:46 Function Parameters: 0:? Sequence -0:45 Sequence -0:45 move second child to first child ( temp 4-component vector of float) +0:46 Sequence +0:46 move second child to first child ( temp 4-component vector of float) 0:? '@entryPointOutput.color' (layout( location=0) out 4-component vector of float) -0:45 color: direct index for structure ( temp 4-component vector of float) -0:45 Function Call: @main( ( temp structure{ temp 4-component vector of float color}) -0:45 Constant: -0:45 0 (const int) +0:46 color: direct index for structure ( temp 4-component vector of float) +0:46 Function Call: @main( ( temp structure{ temp 4-component vector of float color}) +0:46 Constant: +0:46 0 (const int) 0:? Linker Objects 0:? '@entryPointOutput.color' (layout( location=0) out 4-component vector of float) @@ -212,29 +212,20 @@ gl_FragCoord origin is upper left 0:20 10.000000 0:22 Constant: 0:22 10.000000 -0:25 Sequence -0:25 move second child to first child ( temp float) -0:25 'n' ( temp float) -0:25 Constant: -0:25 0.000000 0:26 Sequence -0:26 move second child to first child ( temp 8-element array of 3-component vector of float) -0:26 'a' ( const (read only) 8-element array of 3-component vector of float) -0:26 Construct vec3 ( temp 8-element array of 3-component vector of float) -0:27 vector-scale ( temp 3-component vector of float) -0:27 Constant: -0:27 0.577350 -0:27 0.577350 -0:27 0.577350 -0:27 add second child into first child ( temp float) -0:27 'n' ( temp float) -0:27 Constant: -0:27 1.000000 +0:26 move second child to first child ( temp float) +0:26 'n' ( temp float) +0:26 Constant: +0:26 0.000000 +0:27 Sequence +0:27 move second child to first child ( temp 8-element array of 3-component vector of float) +0:27 'a' ( const (read only) 8-element array of 3-component vector of float) +0:27 Construct vec3 ( temp 8-element array of 3-component vector of float) 0:28 vector-scale ( temp 3-component vector of float) 0:28 Constant: -0:28 -0.577350 -0:28 -0.577350 -0:28 -0.577350 +0:28 0.577350 +0:28 0.577350 +0:28 0.577350 0:28 add second child into first child ( temp float) 0:28 'n' ( temp float) 0:28 Constant: @@ -243,7 +234,7 @@ gl_FragCoord origin is upper left 0:29 Constant: 0:29 -0.577350 0:29 -0.577350 -0:29 0.577350 +0:29 -0.577350 0:29 add second child into first child ( temp float) 0:29 'n' ( temp float) 0:29 Constant: @@ -251,8 +242,8 @@ gl_FragCoord origin is upper left 0:30 vector-scale ( temp 3-component vector of float) 0:30 Constant: 0:30 -0.577350 -0:30 0.577350 0:30 -0.577350 +0:30 0.577350 0:30 add second child into first child ( temp float) 0:30 'n' ( temp float) 0:30 Constant: @@ -261,16 +252,16 @@ gl_FragCoord origin is upper left 0:31 Constant: 0:31 -0.577350 0:31 0.577350 -0:31 0.577350 +0:31 -0.577350 0:31 add second child into first child ( temp float) 0:31 'n' ( temp float) 0:31 Constant: 0:31 1.000000 0:32 vector-scale ( temp 3-component vector of float) 0:32 Constant: +0:32 -0.577350 +0:32 0.577350 0:32 0.577350 -0:32 -0.577350 -0:32 -0.577350 0:32 add second child into first child ( temp float) 0:32 'n' ( temp float) 0:32 Constant: @@ -279,7 +270,7 @@ gl_FragCoord origin is upper left 0:33 Constant: 0:33 0.577350 0:33 -0.577350 -0:33 0.577350 +0:33 -0.577350 0:33 add second child into first child ( temp float) 0:33 'n' ( temp float) 0:33 Constant: @@ -287,38 +278,38 @@ gl_FragCoord origin is upper left 0:34 vector-scale ( temp 3-component vector of float) 0:34 Constant: 0:34 0.577350 -0:34 0.577350 0:34 -0.577350 +0:34 0.577350 0:34 add second child into first child ( temp float) 0:34 'n' ( temp float) 0:34 Constant: 0:34 1.000000 -0:36 Sequence -0:36 move second child to first child ( temp structure{ temp 3-component vector of float a}) -0:36 'oneNonConst' ( const (read only) structure{ temp 3-component vector of float a}) -0:36 Construct structure ( temp structure{ temp 3-component vector of float a}) -0:36 vector-scale ( temp 3-component vector of float) -0:36 Constant: -0:36 -0.577350 -0:36 0.577350 -0:36 0.577350 -0:36 add second child into first child ( temp float) -0:36 'n' ( temp float) -0:36 Constant: -0:36 1.000000 -0:38 Sequence -0:38 move second child to first child ( temp structure{ temp 3-component vector of float a, temp 3-component vector of float b}) -0:38 'twoNonConst' ( const (read only) structure{ temp 3-component vector of float a, temp 3-component vector of float b}) -0:38 Construct structure ( temp structure{ temp 3-component vector of float a, temp 3-component vector of float b}) -0:38 vector-scale ( temp 3-component vector of float) -0:38 Constant: -0:38 -0.577350 -0:38 0.577350 -0:38 0.577350 -0:38 add second child into first child ( temp float) -0:38 'n' ( temp float) -0:38 Constant: -0:38 1.000000 +0:35 vector-scale ( temp 3-component vector of float) +0:35 Constant: +0:35 0.577350 +0:35 0.577350 +0:35 -0.577350 +0:35 add second child into first child ( temp float) +0:35 'n' ( temp float) +0:35 Constant: +0:35 1.000000 +0:37 Sequence +0:37 move second child to first child ( temp structure{ temp 3-component vector of float a}) +0:37 'oneNonConst' ( const (read only) structure{ temp 3-component vector of float a}) +0:37 Construct structure ( temp structure{ temp 3-component vector of float a}) +0:37 vector-scale ( temp 3-component vector of float) +0:37 Constant: +0:37 -0.577350 +0:37 0.577350 +0:37 0.577350 +0:37 add second child into first child ( temp float) +0:37 'n' ( temp float) +0:37 Constant: +0:37 1.000000 +0:39 Sequence +0:39 move second child to first child ( temp structure{ temp 3-component vector of float a, temp 3-component vector of float b}) +0:39 'twoNonConst' ( const (read only) structure{ temp 3-component vector of float a, temp 3-component vector of float b}) +0:39 Construct structure ( temp structure{ temp 3-component vector of float a, temp 3-component vector of float b}) 0:39 vector-scale ( temp 3-component vector of float) 0:39 Constant: 0:39 -0.577350 @@ -328,32 +319,41 @@ gl_FragCoord origin is upper left 0:39 'n' ( temp float) 0:39 Constant: 0:39 1.000000 -0:45 Function Definition: @main( ( temp structure{ temp 4-component vector of float color}) -0:45 Function Parameters: +0:40 vector-scale ( temp 3-component vector of float) +0:40 Constant: +0:40 -0.577350 +0:40 0.577350 +0:40 0.577350 +0:40 add second child into first child ( temp float) +0:40 'n' ( temp float) +0:40 Constant: +0:40 1.000000 +0:46 Function Definition: @main( ( temp structure{ temp 4-component vector of float color}) +0:46 Function Parameters: 0:? Sequence -0:46 Function Call: Test1( ( temp void) -0:49 move second child to first child ( temp 4-component vector of float) -0:49 color: direct index for structure ( temp 4-component vector of float) -0:49 'ps_output' ( temp structure{ temp 4-component vector of float color}) -0:49 Constant: -0:49 0 (const int) -0:49 Constant: -0:49 1.000000 -0:49 1.000000 -0:49 1.000000 -0:49 1.000000 -0:50 Branch: Return with expression -0:50 'ps_output' ( temp structure{ temp 4-component vector of float color}) -0:45 Function Definition: main( ( temp void) -0:45 Function Parameters: +0:47 Function Call: Test1( ( temp void) +0:50 move second child to first child ( temp 4-component vector of float) +0:50 color: direct index for structure ( temp 4-component vector of float) +0:50 'ps_output' ( temp structure{ temp 4-component vector of float color}) +0:50 Constant: +0:50 0 (const int) +0:50 Constant: +0:50 1.000000 +0:50 1.000000 +0:50 1.000000 +0:50 1.000000 +0:51 Branch: Return with expression +0:51 'ps_output' ( temp structure{ temp 4-component vector of float color}) +0:46 Function Definition: main( ( temp void) +0:46 Function Parameters: 0:? Sequence -0:45 Sequence -0:45 move second child to first child ( temp 4-component vector of float) +0:46 Sequence +0:46 move second child to first child ( temp 4-component vector of float) 0:? '@entryPointOutput.color' (layout( location=0) out 4-component vector of float) -0:45 color: direct index for structure ( temp 4-component vector of float) -0:45 Function Call: @main( ( temp structure{ temp 4-component vector of float color}) -0:45 Constant: -0:45 0 (const int) +0:46 color: direct index for structure ( temp 4-component vector of float) +0:46 Function Call: @main( ( temp structure{ temp 4-component vector of float color}) +0:46 Constant: +0:46 0 (const int) 0:? Linker Objects 0:? '@entryPointOutput.color' (layout( location=0) out 4-component vector of float) diff --git a/Test/hlsl.function.frag b/Test/hlsl.function.frag index 5834b319..2085005b 100644 --- a/Test/hlsl.function.frag +++ b/Test/hlsl.function.frag @@ -3,9 +3,14 @@ float4 fun0() return 1.0f; } -uint fun2(float4 col) +float4 fun2(float4 const col) { - return 7; + return (1, 2, 3, 4); +} + +uint fun3(const float4 col) +{ + return 7; } float4 fun4(uint id1, uniform uint id2) @@ -15,7 +20,7 @@ float4 fun4(uint id1, uniform uint id2) float4 fun1(int index) { - uint entityId = fun2(fun0()); + uint entityId = fun3(fun2(fun0())); return fun4(entityId, entityId); } diff --git a/Test/hlsl.init2.frag b/Test/hlsl.init2.frag index 2b9b7e68..6dcb6cb7 100644 --- a/Test/hlsl.init2.frag +++ b/Test/hlsl.init2.frag @@ -21,16 +21,17 @@ void Test1() const mystruct2 constTest5 = { {8,}, {9,}, {10}, }; constTest5.c; - const float step = 1.f; - float n = 0; - const float3 a[8] = { - normalize(float3(1, 1, 1)) * (n += step), - normalize(float3(-1, -1, -1)) * (n += step), - normalize(float3(-1, -1, 1)) * (n += step), - normalize(float3(-1, 1, -1)) * (n += step), - normalize(float3(-1, 1, 1)) * (n += step), - normalize(float3(1, -1, -1)) * (n += step), - normalize(float3(1, -1, 1)) * (n += step), + float const origStep = 1.0f; + const float step = origStep; + float n = 0; + const float3 a[8] = { + normalize(float3(1, 1, 1)) * (n += step), + normalize(float3(-1, -1, -1)) * (n += step), + normalize(float3(-1, -1, 1)) * (n += step), + normalize(float3(-1, 1, -1)) * (n += step), + normalize(float3(-1, 1, 1)) * (n += step), + normalize(float3(1, -1, -1)) * (n += step), + normalize(float3(1, -1, 1)) * (n += step), normalize(float3(1, 1, -1)) * (n += step) }; const struct one { float3 a; } oneNonConst = { normalize(float3(-1, 1, 1)) * (n += step) }; diff --git a/glslang/HLSL/hlslGrammar.cpp b/glslang/HLSL/hlslGrammar.cpp index 8e6f44e3..048e95da 100644 --- a/glslang/HLSL/hlslGrammar.cpp +++ b/glslang/HLSL/hlslGrammar.cpp @@ -1,6 +1,7 @@ // // Copyright (C) 2016-2018 Google, Inc. // Copyright (C) 2016 LunarG, Inc. +// Copyright (C) 2023 Mobica Limited // // All rights reserved. // @@ -594,6 +595,7 @@ bool HlslGrammar::acceptControlDeclaration(TIntermNode*& node) // fully_specified_type // : type_specifier // | type_qualifier type_specifier +// | type_specifier type_qualifier // bool HlslGrammar::acceptFullySpecifiedType(TType& type, const TAttributes& attributes) { @@ -605,7 +607,7 @@ bool HlslGrammar::acceptFullySpecifiedType(TType& type, TIntermNode*& nodeList, // type_qualifier TQualifier qualifier; qualifier.clear(); - if (! acceptQualifier(qualifier)) + if (! acceptPreQualifier(qualifier)) return false; TSourceLoc loc = token.loc; @@ -620,6 +622,10 @@ bool HlslGrammar::acceptFullySpecifiedType(TType& type, TIntermNode*& nodeList, return false; } + // type_qualifier + if (! acceptPostQualifier(qualifier)) + return false; + if (type.getBasicType() == EbtBlock) { // the type was a block, which set some parts of the qualifier parseContext.mergeQualifiers(type.getQualifier(), qualifier); @@ -634,7 +640,7 @@ bool HlslGrammar::acceptFullySpecifiedType(TType& type, TIntermNode*& nodeList, parseContext.declareBlock(loc, type); } else { // Some qualifiers are set when parsing the type. Merge those with - // whatever comes from acceptQualifier. + // whatever comes from acceptPreQualifier and acceptPostQualifier. assert(qualifier.layoutFormat == ElfNone); qualifier.layoutFormat = type.getQualifier().layoutFormat; @@ -660,7 +666,7 @@ bool HlslGrammar::acceptFullySpecifiedType(TType& type, TIntermNode*& nodeList, // // Zero or more of these, so this can't return false. // -bool HlslGrammar::acceptQualifier(TQualifier& qualifier) +bool HlslGrammar::acceptPreQualifier(TQualifier& qualifier) { do { switch (peek()) { @@ -766,6 +772,25 @@ bool HlslGrammar::acceptQualifier(TQualifier& qualifier) } while (true); } +// type_qualifier +// : qualifier qualifier ... +// +// Zero or more of these, so this can't return false. +// +bool HlslGrammar::acceptPostQualifier(TQualifier& qualifier) +{ + do { + switch (peek()) { + case EHTokConst: + qualifier.storage = EvqConst; + break; + default: + return true; + } + advanceToken(); + } while (true); +} + // layout_qualifier_list // : LAYOUT LEFT_PAREN layout_qualifier COMMA layout_qualifier ... RIGHT_PAREN // diff --git a/glslang/HLSL/hlslGrammar.h b/glslang/HLSL/hlslGrammar.h index 6c120081..cfe294bc 100644 --- a/glslang/HLSL/hlslGrammar.h +++ b/glslang/HLSL/hlslGrammar.h @@ -1,6 +1,7 @@ // // Copyright (C) 2016-2018 Google, Inc. // Copyright (C) 2016 LunarG, Inc. +// Copyright (C) 2023 Mobica Limited. // // All rights reserved. // @@ -72,7 +73,8 @@ namespace glslang { bool acceptSamplerState(); bool acceptFullySpecifiedType(TType&, const TAttributes&); bool acceptFullySpecifiedType(TType&, TIntermNode*& nodeList, const TAttributes&, bool forbidDeclarators = false); - bool acceptQualifier(TQualifier&); + bool acceptPreQualifier(TQualifier&); + bool acceptPostQualifier(TQualifier&); bool acceptLayoutQualifierList(TQualifier&); bool acceptType(TType&); bool acceptType(TType&, TIntermNode*& nodeList);