HLSL: Fix #96: Support do-while loop substatements with no curly braces.

This commit is contained in:
John Kessenich 2017-04-20 11:08:24 -06:00
parent 670271890d
commit 0c6f9360f5
4 changed files with 180 additions and 77 deletions

View File

@ -2,9 +2,9 @@ hlsl.doLoop.frag
Shader version: 500 Shader version: 500
gl_FragCoord origin is upper left gl_FragCoord origin is upper left
0:? Sequence 0:? Sequence
0:2 Function Definition: @PixelShaderFunction(vf4; ( temp 4-component vector of float) 0:2 Function Definition: @PixelShaderFunction(f1; ( temp 4-component vector of float)
0:2 Function Parameters: 0:2 Function Parameters:
0:2 'input' ( in 4-component vector of float) 0:2 'input' ( in float)
0:? Sequence 0:? Sequence
0:3 Loop with condition not tested first 0:3 Loop with condition not tested first
0:3 Loop Condition 0:3 Loop Condition
@ -18,26 +18,56 @@ gl_FragCoord origin is upper left
0:4 No loop body 0:4 No loop body
0:5 Loop with condition not tested first 0:5 Loop with condition not tested first
0:5 Loop Condition 0:5 Loop Condition
0:5 all ( temp bool) 0:5 Compare Greater Than ( temp bool)
0:5 Equal ( temp 4-component vector of bool) 0:5 'input' ( in float)
0:5 'input' ( in 4-component vector of float) 0:5 Constant:
0:5 'input' ( in 4-component vector of float) 0:5 2.000000
0:5 Loop Body 0:5 Loop Body
0:5 Branch: Return with expression 0:? Sequence
0:5 'input' ( in 4-component vector of float) 0:5 Branch: Return with expression
0:5 Construct vec4 ( temp 4-component vector of float)
0:5 'input' ( in float)
0:6 Loop with condition not tested first
0:6 Loop Condition
0:6 Compare Less Than ( temp bool)
0:6 'input' ( in float)
0:6 Constant:
0:6 10.000000
0:6 Loop Body
0:6 Pre-Increment ( temp float)
0:6 'input' ( in float)
0:7 Loop with condition not tested first
0:7 Loop Condition
0:7 Compare Less Than ( temp bool)
0:7 Pre-Increment ( temp float)
0:7 'input' ( in float)
0:7 Constant:
0:7 10.000000
0:7 Loop Body
0:7 Loop with condition tested first
0:7 Loop Condition
0:7 Compare Less Than ( temp bool)
0:7 Pre-Increment ( temp float)
0:7 'input' ( in float)
0:7 Constant:
0:7 10.000000
0:7 No loop body
0:8 Branch: Return with expression
0:8 Construct vec4 ( temp 4-component vector of float)
0:8 'input' ( in float)
0:2 Function Definition: PixelShaderFunction( ( temp void) 0:2 Function Definition: PixelShaderFunction( ( temp void)
0:2 Function Parameters: 0:2 Function Parameters:
0:? Sequence 0:? Sequence
0:2 move second child to first child ( temp 4-component vector of float) 0:2 move second child to first child ( temp float)
0:? 'input' ( temp 4-component vector of float) 0:? 'input' ( temp float)
0:? 'input' (layout( location=0) in 4-component vector of float) 0:? 'input' (layout( location=0) in float)
0:2 move second child to first child ( temp 4-component vector of float) 0:2 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) 0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:2 Function Call: @PixelShaderFunction(vf4; ( temp 4-component vector of float) 0:2 Function Call: @PixelShaderFunction(f1; ( temp 4-component vector of float)
0:? 'input' ( temp 4-component vector of float) 0:? 'input' ( temp float)
0:? Linker Objects 0:? Linker Objects
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) 0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:? 'input' (layout( location=0) in 4-component vector of float) 0:? 'input' (layout( location=0) in float)
Linked fragment stage: Linked fragment stage:
@ -46,9 +76,9 @@ Linked fragment stage:
Shader version: 500 Shader version: 500
gl_FragCoord origin is upper left gl_FragCoord origin is upper left
0:? Sequence 0:? Sequence
0:2 Function Definition: @PixelShaderFunction(vf4; ( temp 4-component vector of float) 0:2 Function Definition: @PixelShaderFunction(f1; ( temp 4-component vector of float)
0:2 Function Parameters: 0:2 Function Parameters:
0:2 'input' ( in 4-component vector of float) 0:2 'input' ( in float)
0:? Sequence 0:? Sequence
0:3 Loop with condition not tested first 0:3 Loop with condition not tested first
0:3 Loop Condition 0:3 Loop Condition
@ -62,73 +92,105 @@ gl_FragCoord origin is upper left
0:4 No loop body 0:4 No loop body
0:5 Loop with condition not tested first 0:5 Loop with condition not tested first
0:5 Loop Condition 0:5 Loop Condition
0:5 all ( temp bool) 0:5 Compare Greater Than ( temp bool)
0:5 Equal ( temp 4-component vector of bool) 0:5 'input' ( in float)
0:5 'input' ( in 4-component vector of float) 0:5 Constant:
0:5 'input' ( in 4-component vector of float) 0:5 2.000000
0:5 Loop Body 0:5 Loop Body
0:5 Branch: Return with expression 0:? Sequence
0:5 'input' ( in 4-component vector of float) 0:5 Branch: Return with expression
0:5 Construct vec4 ( temp 4-component vector of float)
0:5 'input' ( in float)
0:6 Loop with condition not tested first
0:6 Loop Condition
0:6 Compare Less Than ( temp bool)
0:6 'input' ( in float)
0:6 Constant:
0:6 10.000000
0:6 Loop Body
0:6 Pre-Increment ( temp float)
0:6 'input' ( in float)
0:7 Loop with condition not tested first
0:7 Loop Condition
0:7 Compare Less Than ( temp bool)
0:7 Pre-Increment ( temp float)
0:7 'input' ( in float)
0:7 Constant:
0:7 10.000000
0:7 Loop Body
0:7 Loop with condition tested first
0:7 Loop Condition
0:7 Compare Less Than ( temp bool)
0:7 Pre-Increment ( temp float)
0:7 'input' ( in float)
0:7 Constant:
0:7 10.000000
0:7 No loop body
0:8 Branch: Return with expression
0:8 Construct vec4 ( temp 4-component vector of float)
0:8 'input' ( in float)
0:2 Function Definition: PixelShaderFunction( ( temp void) 0:2 Function Definition: PixelShaderFunction( ( temp void)
0:2 Function Parameters: 0:2 Function Parameters:
0:? Sequence 0:? Sequence
0:2 move second child to first child ( temp 4-component vector of float) 0:2 move second child to first child ( temp float)
0:? 'input' ( temp 4-component vector of float) 0:? 'input' ( temp float)
0:? 'input' (layout( location=0) in 4-component vector of float) 0:? 'input' (layout( location=0) in float)
0:2 move second child to first child ( temp 4-component vector of float) 0:2 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) 0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:2 Function Call: @PixelShaderFunction(vf4; ( temp 4-component vector of float) 0:2 Function Call: @PixelShaderFunction(f1; ( temp 4-component vector of float)
0:? 'input' ( temp 4-component vector of float) 0:? 'input' ( temp float)
0:? Linker Objects 0:? Linker Objects
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) 0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:? 'input' (layout( location=0) in 4-component vector of float) 0:? 'input' (layout( location=0) in float)
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 44 // Id's are bound by 71
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Fragment 4 "PixelShaderFunction" 37 40 EntryPoint Fragment 4 "PixelShaderFunction" 64 67
ExecutionMode 4 OriginUpperLeft ExecutionMode 4 OriginUpperLeft
Source HLSL 500 Source HLSL 500
Name 4 "PixelShaderFunction" Name 4 "PixelShaderFunction"
Name 11 "@PixelShaderFunction(vf4;" Name 11 "@PixelShaderFunction(f1;"
Name 10 "input" Name 10 "input"
Name 35 "input" Name 62 "input"
Name 37 "input" Name 64 "input"
Name 40 "@entryPointOutput" Name 67 "@entryPointOutput"
Name 41 "param" Name 68 "param"
Decorate 37(input) Location 0 Decorate 64(input) Location 0
Decorate 40(@entryPointOutput) Location 0 Decorate 67(@entryPointOutput) Location 0
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
7: TypeVector 6(float) 4 7: TypePointer Function 6(float)
8: TypePointer Function 7(fvec4) 8: TypeVector 6(float) 4
9: TypeFunction 7(fvec4) 8(ptr) 9: TypeFunction 8(fvec4) 7(ptr)
17: TypeBool 17: TypeBool
18: 17(bool) ConstantFalse 18: 17(bool) ConstantFalse
31: TypeVector 17(bool) 4 31: 6(float) Constant 1073741824
36: TypePointer Input 7(fvec4) 38: 6(float) Constant 1065353216
37(input): 36(ptr) Variable Input 41: 6(float) Constant 1092616192
39: TypePointer Output 7(fvec4) 63: TypePointer Input 6(float)
40(@entryPointOutput): 39(ptr) Variable Output 64(input): 63(ptr) Variable Input
66: TypePointer Output 8(fvec4)
67(@entryPointOutput): 66(ptr) Variable Output
4(PixelShaderFunction): 2 Function None 3 4(PixelShaderFunction): 2 Function None 3
5: Label 5: Label
35(input): 8(ptr) Variable Function 62(input): 7(ptr) Variable Function
41(param): 8(ptr) Variable Function 68(param): 7(ptr) Variable Function
38: 7(fvec4) Load 37(input) 65: 6(float) Load 64(input)
Store 35(input) 38 Store 62(input) 65
42: 7(fvec4) Load 35(input) 69: 6(float) Load 62(input)
Store 41(param) 42 Store 68(param) 69
43: 7(fvec4) FunctionCall 11(@PixelShaderFunction(vf4;) 41(param) 70: 8(fvec4) FunctionCall 11(@PixelShaderFunction(f1;) 68(param)
Store 40(@entryPointOutput) 43 Store 67(@entryPointOutput) 70
Return Return
FunctionEnd FunctionEnd
11(@PixelShaderFunction(vf4;): 7(fvec4) Function None 9 11(@PixelShaderFunction(f1;): 8(fvec4) Function None 9
10(input): 8(ptr) FunctionParameter 10(input): 7(ptr) FunctionParameter
12: Label 12: Label
Branch 13 Branch 13
13: Label 13: Label
@ -153,15 +215,57 @@ gl_FragCoord origin is upper left
LoopMerge 25 26 None LoopMerge 25 26 None
Branch 24 Branch 24
24: Label 24: Label
27: 7(fvec4) Load 10(input) 27: 6(float) Load 10(input)
ReturnValue 27 28: 8(fvec4) CompositeConstruct 27 27 27 27
ReturnValue 28
26: Label 26: Label
29: 7(fvec4) Load 10(input) 30: 6(float) Load 10(input)
30: 7(fvec4) Load 10(input) 32: 17(bool) FOrdGreaterThan 30 31
32: 31(bvec4) FOrdEqual 29 30 BranchConditional 32 23 25
33: 17(bool) All 32
BranchConditional 33 23 25
25: Label 25: Label
34: 7(fvec4) Undef Branch 33
ReturnValue 34 33: Label
LoopMerge 35 36 None
Branch 34
34: Label
37: 6(float) Load 10(input)
39: 6(float) FAdd 37 38
Store 10(input) 39
Branch 36
36: Label
40: 6(float) Load 10(input)
42: 17(bool) FOrdLessThan 40 41
BranchConditional 42 33 35
35: Label
Branch 43
43: Label
LoopMerge 45 46 None
Branch 44
44: Label
Branch 47
47: Label
LoopMerge 49 50 None
Branch 51
51: Label
52: 6(float) Load 10(input)
53: 6(float) FAdd 52 38
Store 10(input) 53
54: 17(bool) FOrdLessThan 53 41
BranchConditional 54 48 49
48: Label
Branch 50
50: Label
Branch 47
49: Label
Branch 46
46: Label
55: 6(float) Load 10(input)
56: 6(float) FAdd 55 38
Store 10(input) 56
57: 17(bool) FOrdLessThan 56 41
BranchConditional 57 43 45
45: Label
58: 6(float) Load 10(input)
59: 8(fvec4) CompositeConstruct 58 58 58 58
ReturnValue 59
FunctionEnd FunctionEnd

View File

@ -118,8 +118,9 @@ gl_FragCoord origin is upper left
0:24 Convert int to bool ( temp bool) 0:24 Convert int to bool ( temp bool)
0:24 'i' ( temp int) 0:24 'i' ( temp int)
0:24 Loop Body 0:24 Loop Body
0:24 Pre-Decrement ( temp int) 0:? Sequence
0:24 'i' ( temp int) 0:24 Pre-Decrement ( temp int)
0:24 'i' ( temp int)
0:? Sequence 0:? Sequence
0:26 Loop with condition tested first 0:26 Loop with condition tested first
0:26 Loop Condition 0:26 Loop Condition
@ -286,8 +287,9 @@ gl_FragCoord origin is upper left
0:24 Convert int to bool ( temp bool) 0:24 Convert int to bool ( temp bool)
0:24 'i' ( temp int) 0:24 'i' ( temp int)
0:24 Loop Body 0:24 Loop Body
0:24 Pre-Decrement ( temp int) 0:? Sequence
0:24 'i' ( temp int) 0:24 Pre-Decrement ( temp int)
0:24 'i' ( temp int)
0:? Sequence 0:? Sequence
0:26 Loop with condition tested first 0:26 Loop with condition tested first
0:26 Loop Condition 0:26 Loop Condition

View File

@ -1,6 +1,9 @@
float4 PixelShaderFunction(float4 input) : COLOR0 float4 PixelShaderFunction(float input) : COLOR0
{ {
[unroll] do {} while (false); [unroll] do {} while (false);
[unroll] do {;} while (false); [unroll] do {;} while (false);
do { return input; } while (all(input == input)); do { return (float4)input; } while (input > 2.0);
do ++input; while (input < 10.0);
do while (++input < 10.0); while (++input < 10.0); // nest while inside do-while
return (float4)input;
} }

View File

@ -3328,18 +3328,12 @@ bool HlslGrammar::acceptIterationStatement(TIntermNode*& statement)
case EHTokDo: case EHTokDo:
parseContext.nestLooping(); parseContext.nestLooping();
if (! acceptTokenClass(EHTokLeftBrace))
expected("{");
// statement // statement
if (! peekTokenClass(EHTokRightBrace) && ! acceptScopedStatement(statement)) { if (! acceptScopedStatement(statement)) {
expected("do sub-statement"); expected("do sub-statement");
return false; return false;
} }
if (! acceptTokenClass(EHTokRightBrace))
expected("}");
// WHILE // WHILE
if (! acceptTokenClass(EHTokWhile)) { if (! acceptTokenClass(EHTokWhile)) {
expected("while"); expected("while");