AST: Remove convertToBasicType() which was obfuscating the conversion design.

Reinforces that conversion rules are operation-specific.
Side effect is that HLSL logical-operator conversions are more direct
(e.g. float -> bool, rather than float -> int -> bool).
This commit is contained in:
John Kessenich 2018-03-15 19:14:47 -06:00
parent 2ad4737dc2
commit 137a24dffa
4 changed files with 315 additions and 329 deletions

View File

@ -74,12 +74,11 @@ gl_FragCoord origin is upper left
0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1}) 0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1})
0:17 Constant: 0:17 Constant:
0:17 1 (const uint) 0:17 1 (const uint)
0:17 Convert int to bool ( temp bool) 0:17 Convert float to bool ( temp bool)
0:17 Convert float to int ( temp int) 0:17 condf: direct index for structure ( uniform float)
0:17 condf: direct index for structure ( uniform float) 0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1})
0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1}) 0:17 Constant:
0:17 Constant: 0:17 0 (const uint)
0:17 0 (const uint)
0:17 Convert float to bool ( temp bool) 0:17 Convert float to bool ( temp bool)
0:17 condf1: direct index for structure ( uniform 1-component vector of float) 0:17 condf1: direct index for structure ( uniform 1-component vector of float)
0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1}) 0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1})
@ -243,12 +242,11 @@ gl_FragCoord origin is upper left
0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1}) 0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1})
0:17 Constant: 0:17 Constant:
0:17 1 (const uint) 0:17 1 (const uint)
0:17 Convert int to bool ( temp bool) 0:17 Convert float to bool ( temp bool)
0:17 Convert float to int ( temp int) 0:17 condf: direct index for structure ( uniform float)
0:17 condf: direct index for structure ( uniform float) 0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1})
0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1}) 0:17 Constant:
0:17 Constant: 0:17 0 (const uint)
0:17 0 (const uint)
0:17 Convert float to bool ( temp bool) 0:17 Convert float to bool ( temp bool)
0:17 condf1: direct index for structure ( uniform 1-component vector of float) 0:17 condf1: direct index for structure ( uniform 1-component vector of float)
0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1}) 0:17 'anon@0' (layout( row_major std140) uniform block{ uniform float condf, uniform int condi, uniform 1-component vector of float condf1, uniform 1-component vector of int condi1})
@ -335,12 +333,12 @@ gl_FragCoord origin is upper left
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80006 // Generated by (magic number): 80006
// Id's are bound by 140 // Id's are bound by 139
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 138 EntryPoint Fragment 4 "main" 137
ExecutionMode 4 OriginUpperLeft ExecutionMode 4 OriginUpperLeft
Source HLSL 500 Source HLSL 500
Name 4 "main" Name 4 "main"
@ -352,17 +350,17 @@ gl_FragCoord origin is upper left
MemberName 16($Global) 2 "condf1" MemberName 16($Global) 2 "condf1"
MemberName 16($Global) 3 "condi1" MemberName 16($Global) 3 "condi1"
Name 18 "" Name 18 ""
Name 88 "f" Name 87 "f"
Name 101 "i" Name 100 "i"
Name 121 "g" Name 120 "g"
Name 138 "@entryPointOutput" Name 137 "@entryPointOutput"
MemberDecorate 16($Global) 0 Offset 0 MemberDecorate 16($Global) 0 Offset 0
MemberDecorate 16($Global) 1 Offset 4 MemberDecorate 16($Global) 1 Offset 4
MemberDecorate 16($Global) 2 Offset 8 MemberDecorate 16($Global) 2 Offset 8
MemberDecorate 16($Global) 3 Offset 12 MemberDecorate 16($Global) 3 Offset 12
Decorate 16($Global) Block Decorate 16($Global) Block
Decorate 18 DescriptorSet 0 Decorate 18 DescriptorSet 0
Decorate 138(@entryPointOutput) Location 0 Decorate 137(@entryPointOutput) Location 0
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
@ -388,25 +386,25 @@ gl_FragCoord origin is upper left
53: 6(float) Constant 1077936128 53: 6(float) Constant 1077936128
57: 15(int) Constant 3 57: 15(int) Constant 3
64: 6(float) Constant 1082130432 64: 6(float) Constant 1082130432
83: 6(float) Constant 1084227584 82: 6(float) Constant 1084227584
87: TypePointer Function 6(float) 86: TypePointer Function 6(float)
100: TypePointer Function 15(int) 99: TypePointer Function 15(int)
125: 6(float) Constant 1088421888 124: 6(float) Constant 1088421888
126: 6(float) Constant 1090519040 125: 6(float) Constant 1090519040
137: TypePointer Output 7(fvec4) 136: TypePointer Output 7(fvec4)
138(@entryPointOutput): 137(ptr) Variable Output 137(@entryPointOutput): 136(ptr) Variable Output
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
139: 7(fvec4) FunctionCall 9(@main() 138: 7(fvec4) FunctionCall 9(@main()
Store 138(@entryPointOutput) 139 Store 137(@entryPointOutput) 138
Return Return
FunctionEnd FunctionEnd
9(@main(): 7(fvec4) Function None 8 9(@main(): 7(fvec4) Function None 8
10: Label 10: Label
12(a): 11(ptr) Variable Function 12(a): 11(ptr) Variable Function
88(f): 87(ptr) Variable Function 87(f): 86(ptr) Variable Function
101(i): 100(ptr) Variable Function 100(i): 99(ptr) Variable Function
121(g): 87(ptr) Variable Function 120(g): 86(ptr) Variable Function
Store 12(a) 14 Store 12(a) 14
21: 20(ptr) AccessChain 18 19 21: 20(ptr) AccessChain 18 19
22: 15(int) Load 21 22: 15(int) Load 21
@ -457,85 +455,84 @@ gl_FragCoord origin is upper left
70: 23(bool) INotEqual 69 25 70: 23(bool) INotEqual 69 25
71: 35(ptr) AccessChain 18 34 71: 35(ptr) AccessChain 18 34
72: 6(float) Load 71 72: 6(float) Load 71
73: 15(int) ConvertFToS 72 73: 23(bool) FOrdNotEqual 72 38
74: 23(bool) INotEqual 73 25 74: 23(bool) LogicalAnd 70 73
75: 23(bool) LogicalAnd 70 74 75: 35(ptr) AccessChain 18 46
76: 35(ptr) AccessChain 18 46 76: 6(float) Load 75
77: 6(float) Load 76 77: 23(bool) FOrdNotEqual 76 38
78: 23(bool) FOrdNotEqual 77 38 78: 23(bool) LogicalOr 74 77
79: 23(bool) LogicalOr 75 78 SelectionMerge 80 None
SelectionMerge 81 None BranchConditional 78 79 80
BranchConditional 79 80 81 79: Label
80: Label 81: 7(fvec4) Load 12(a)
82: 7(fvec4) Load 12(a) 83: 7(fvec4) CompositeConstruct 82 82 82 82
84: 7(fvec4) CompositeConstruct 83 83 83 83 84: 7(fvec4) FAdd 81 83
85: 7(fvec4) FAdd 82 84 ReturnValue 84
ReturnValue 85 80: Label
81: Label 88: 35(ptr) AccessChain 18 34
89: 35(ptr) AccessChain 18 34 89: 6(float) Load 88
90: 6(float) Load 89 Store 87(f) 89
Store 88(f) 90 Branch 90
Branch 91 90: Label
91: Label LoopMerge 92 93 None
LoopMerge 93 94 None Branch 94
Branch 95 94: Label
95: Label 95: 6(float) Load 87(f)
96: 6(float) Load 88(f) 96: 23(bool) FOrdNotEqual 95 38
97: 23(bool) FOrdNotEqual 96 38 BranchConditional 96 91 92
BranchConditional 97 92 93 91: Label
92: Label 97: 6(float) Load 87(f)
98: 6(float) Load 88(f) 98: 6(float) FSub 97 30
99: 6(float) FSub 98 30 Store 87(f) 98
Store 88(f) 99 Branch 93
Branch 94 93: Label
94: Label Branch 90
Branch 91 92: Label
93: Label 101: 20(ptr) AccessChain 18 19
102: 20(ptr) AccessChain 18 19 102: 15(int) Load 101
103: 15(int) Load 102 Store 100(i) 102
Store 101(i) 103 Branch 103
103: Label
LoopMerge 105 106 None
Branch 104 Branch 104
104: Label 104: Label
LoopMerge 106 107 None 107: 15(int) Load 100(i)
Branch 105 108: 15(int) ISub 107 19
105: Label Store 100(i) 108
108: 15(int) Load 101(i) Branch 106
109: 15(int) ISub 108 19
Store 101(i) 109
Branch 107
107: Label
110: 15(int) Load 101(i)
111: 23(bool) INotEqual 110 25
BranchConditional 111 104 106
106: Label 106: Label
Branch 112 109: 15(int) Load 100(i)
112: Label 110: 23(bool) INotEqual 109 25
LoopMerge 114 115 None BranchConditional 110 103 105
Branch 116 105: Label
116: Label Branch 111
117: 15(int) Load 101(i) 111: Label
118: 23(bool) INotEqual 117 25 LoopMerge 113 114 None
BranchConditional 118 113 114 Branch 115
113: Label 115: Label
119: 15(int) Load 101(i) 116: 15(int) Load 100(i)
120: 15(int) ISub 119 19 117: 23(bool) INotEqual 116 25
Store 101(i) 120 BranchConditional 117 112 113
Branch 115 112: Label
115: Label 118: 15(int) Load 100(i)
Branch 112 119: 15(int) ISub 118 19
114: Label Store 100(i) 119
122: 35(ptr) AccessChain 18 34 Branch 114
123: 6(float) Load 122 114: Label
124: 23(bool) FOrdNotEqual 123 38 Branch 111
127: 6(float) Select 124 125 126 113: Label
Store 121(g) 127 121: 35(ptr) AccessChain 18 34
128: 6(float) Load 121(g) 122: 6(float) Load 121
129: 7(fvec4) Load 12(a) 123: 23(bool) FOrdNotEqual 122 38
130: 7(fvec4) CompositeConstruct 128 128 128 128 126: 6(float) Select 123 124 125
131: 7(fvec4) FAdd 129 130 Store 120(g) 126
Store 12(a) 131 127: 6(float) Load 120(g)
132: 7(fvec4) Load 12(a) 128: 7(fvec4) Load 12(a)
133: 7(fvec4) CompositeConstruct 30 30 30 30 129: 7(fvec4) CompositeConstruct 127 127 127 127
134: 7(fvec4) FSub 132 133 130: 7(fvec4) FAdd 128 129
ReturnValue 134 Store 12(a) 130
131: 7(fvec4) Load 12(a)
132: 7(fvec4) CompositeConstruct 30 30 30 30
133: 7(fvec4) FSub 131 132
ReturnValue 133
FunctionEnd FunctionEnd

View File

@ -13,12 +13,11 @@ gl_FragCoord origin is upper left
0:13 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4}) 0:13 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4})
0:13 Constant: 0:13 Constant:
0:13 0 (const uint) 0:13 0 (const uint)
0:13 Convert int to bool ( temp bool) 0:13 Convert float to bool ( temp bool)
0:13 Convert float to int ( temp int) 0:13 fval: direct index for structure ( uniform float)
0:13 fval: direct index for structure ( uniform float) 0:13 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4})
0:13 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4}) 0:13 Constant:
0:13 Constant: 0:13 2 (const uint)
0:13 2 (const uint)
0:13 true case is null 0:13 true case is null
0:14 Test condition and select ( temp void) 0:14 Test condition and select ( temp void)
0:14 Condition 0:14 Condition
@ -28,12 +27,11 @@ gl_FragCoord origin is upper left
0:14 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4}) 0:14 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4})
0:14 Constant: 0:14 Constant:
0:14 0 (const uint) 0:14 0 (const uint)
0:14 Convert int to bool ( temp bool) 0:14 Convert float to bool ( temp bool)
0:14 Convert float to int ( temp int) 0:14 fval: direct index for structure ( uniform float)
0:14 fval: direct index for structure ( uniform float) 0:14 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4})
0:14 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4}) 0:14 Constant:
0:14 Constant: 0:14 2 (const uint)
0:14 2 (const uint)
0:14 true case is null 0:14 true case is null
0:17 move second child to first child ( temp 4-component vector of float) 0:17 move second child to first child ( temp 4-component vector of float)
0:17 Color: direct index for structure ( temp 4-component vector of float) 0:17 Color: direct index for structure ( temp 4-component vector of float)
@ -79,12 +77,11 @@ gl_FragCoord origin is upper left
0:13 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4}) 0:13 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4})
0:13 Constant: 0:13 Constant:
0:13 0 (const uint) 0:13 0 (const uint)
0:13 Convert int to bool ( temp bool) 0:13 Convert float to bool ( temp bool)
0:13 Convert float to int ( temp int) 0:13 fval: direct index for structure ( uniform float)
0:13 fval: direct index for structure ( uniform float) 0:13 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4})
0:13 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4}) 0:13 Constant:
0:13 Constant: 0:13 2 (const uint)
0:13 2 (const uint)
0:13 true case is null 0:13 true case is null
0:14 Test condition and select ( temp void) 0:14 Test condition and select ( temp void)
0:14 Condition 0:14 Condition
@ -94,12 +91,11 @@ gl_FragCoord origin is upper left
0:14 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4}) 0:14 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4})
0:14 Constant: 0:14 Constant:
0:14 0 (const uint) 0:14 0 (const uint)
0:14 Convert int to bool ( temp bool) 0:14 Convert float to bool ( temp bool)
0:14 Convert float to int ( temp int) 0:14 fval: direct index for structure ( uniform float)
0:14 fval: direct index for structure ( uniform float) 0:14 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4})
0:14 'anon@0' (layout( row_major std140) uniform block{ uniform int ival, uniform 4-component vector of int ival4, uniform float fval, uniform 4-component vector of float fval4}) 0:14 Constant:
0:14 Constant: 0:14 2 (const uint)
0:14 2 (const uint)
0:14 true case is null 0:14 true case is null
0:17 move second child to first child ( temp 4-component vector of float) 0:17 move second child to first child ( temp 4-component vector of float)
0:17 Color: direct index for structure ( temp 4-component vector of float) 0:17 Color: direct index for structure ( temp 4-component vector of float)
@ -129,12 +125,12 @@ gl_FragCoord origin is upper left
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80006 // Generated by (magic number): 80006
// Id's are bound by 57 // Id's are bound by 56
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 54 EntryPoint Fragment 4 "main" 53
ExecutionMode 4 OriginUpperLeft ExecutionMode 4 OriginUpperLeft
Source HLSL 500 Source HLSL 500
Name 4 "main" Name 4 "main"
@ -147,15 +143,15 @@ gl_FragCoord origin is upper left
MemberName 14($Global) 2 "fval" MemberName 14($Global) 2 "fval"
MemberName 14($Global) 3 "fval4" MemberName 14($Global) 3 "fval4"
Name 16 "" Name 16 ""
Name 45 "psout" Name 44 "psout"
Name 54 "@entryPointOutput.Color" Name 53 "@entryPointOutput.Color"
MemberDecorate 14($Global) 0 Offset 0 MemberDecorate 14($Global) 0 Offset 0
MemberDecorate 14($Global) 1 Offset 16 MemberDecorate 14($Global) 1 Offset 16
MemberDecorate 14($Global) 2 Offset 32 MemberDecorate 14($Global) 2 Offset 32
MemberDecorate 14($Global) 3 Offset 48 MemberDecorate 14($Global) 3 Offset 48
Decorate 14($Global) Block Decorate 14($Global) Block
Decorate 16 DescriptorSet 0 Decorate 16 DescriptorSet 0
Decorate 54(@entryPointOutput.Color) Location 0 Decorate 53(@entryPointOutput.Color) Location 0
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
@ -174,29 +170,29 @@ gl_FragCoord origin is upper left
23: 22(int) Constant 0 23: 22(int) Constant 0
25: 12(int) Constant 2 25: 12(int) Constant 2
26: TypePointer Uniform 6(float) 26: TypePointer Uniform 6(float)
44: TypePointer Function 8(PS_OUTPUT) 29: 6(float) Constant 0
46: 6(float) Constant 1065353216 43: TypePointer Function 8(PS_OUTPUT)
47: 7(fvec4) ConstantComposite 46 46 46 46 45: 6(float) Constant 1065353216
48: TypePointer Function 7(fvec4) 46: 7(fvec4) ConstantComposite 45 45 45 45
53: TypePointer Output 7(fvec4) 47: TypePointer Function 7(fvec4)
54(@entryPointOutput.Color): 53(ptr) Variable Output 52: TypePointer Output 7(fvec4)
53(@entryPointOutput.Color): 52(ptr) Variable Output
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
55:8(PS_OUTPUT) FunctionCall 10(@main() 54:8(PS_OUTPUT) FunctionCall 10(@main()
56: 7(fvec4) CompositeExtract 55 0 55: 7(fvec4) CompositeExtract 54 0
Store 54(@entryPointOutput.Color) 56 Store 53(@entryPointOutput.Color) 55
Return Return
FunctionEnd FunctionEnd
10(@main():8(PS_OUTPUT) Function None 9 10(@main():8(PS_OUTPUT) Function None 9
11: Label 11: Label
45(psout): 44(ptr) Variable Function 44(psout): 43(ptr) Variable Function
19: 18(ptr) AccessChain 16 17 19: 18(ptr) AccessChain 16 17
20: 12(int) Load 19 20: 12(int) Load 19
24: 21(bool) INotEqual 20 23 24: 21(bool) INotEqual 20 23
27: 26(ptr) AccessChain 16 25 27: 26(ptr) AccessChain 16 25
28: 6(float) Load 27 28: 6(float) Load 27
29: 12(int) ConvertFToS 28 30: 21(bool) FOrdNotEqual 28 29
30: 21(bool) INotEqual 29 23
31: 21(bool) LogicalAnd 24 30 31: 21(bool) LogicalAnd 24 30
SelectionMerge 33 None SelectionMerge 33 None
BranchConditional 31 32 33 BranchConditional 31 32 33
@ -208,16 +204,15 @@ gl_FragCoord origin is upper left
36: 21(bool) INotEqual 35 23 36: 21(bool) INotEqual 35 23
37: 26(ptr) AccessChain 16 25 37: 26(ptr) AccessChain 16 25
38: 6(float) Load 37 38: 6(float) Load 37
39: 12(int) ConvertFToS 38 39: 21(bool) FOrdNotEqual 38 29
40: 21(bool) INotEqual 39 23 40: 21(bool) LogicalOr 36 39
41: 21(bool) LogicalOr 36 40 SelectionMerge 42 None
SelectionMerge 43 None BranchConditional 40 41 42
BranchConditional 41 42 43 41: Label
42: Label Branch 42
Branch 43 42: Label
43: Label 48: 47(ptr) AccessChain 44(psout) 17
49: 48(ptr) AccessChain 45(psout) 17 Store 48 46
Store 49 47 49:8(PS_OUTPUT) Load 44(psout)
50:8(PS_OUTPUT) Load 45(psout) ReturnValue 49
ReturnValue 50
FunctionEnd FunctionEnd

View File

@ -475,7 +475,7 @@ bool TIntermediate::isConversionAllowed(TOperator op, TIntermTyped* node) const
// This is 'mechanism' here, it does any conversion told. // This is 'mechanism' here, it does any conversion told.
// It is about basic type, not about shape. // It is about basic type, not about shape.
// The policy comes from the shader or the above code. // The policy comes from the shader or the calling code.
TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped* node) const TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped* node) const
{ {
// //
@ -488,44 +488,44 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
switch (convertTo) { switch (convertTo) {
case EbtDouble: case EbtDouble:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtInt8: newOp = EOpConvInt8ToDouble; break; case EbtInt8: newOp = EOpConvInt8ToDouble; break;
case EbtUint8: newOp = EOpConvUint8ToDouble; break; case EbtUint8: newOp = EOpConvUint8ToDouble; break;
case EbtInt16: newOp = EOpConvInt16ToDouble; break; case EbtInt16: newOp = EOpConvInt16ToDouble; break;
case EbtUint16:newOp = EOpConvUint16ToDouble;break; case EbtUint16: newOp = EOpConvUint16ToDouble; break;
case EbtInt: newOp = EOpConvIntToDouble; break; case EbtInt: newOp = EOpConvIntToDouble; break;
case EbtUint: newOp = EOpConvUintToDouble; break; case EbtUint: newOp = EOpConvUintToDouble; break;
case EbtBool: newOp = EOpConvBoolToDouble; break; case EbtBool: newOp = EOpConvBoolToDouble; break;
case EbtFloat: newOp = EOpConvFloatToDouble; break; case EbtFloat: newOp = EOpConvFloatToDouble; break;
case EbtFloat16: newOp = EOpConvFloat16ToDouble; break; case EbtFloat16: newOp = EOpConvFloat16ToDouble; break;
case EbtInt64: newOp = EOpConvInt64ToDouble; break; case EbtInt64: newOp = EOpConvInt64ToDouble; break;
case EbtUint64: newOp = EOpConvUint64ToDouble; break; case EbtUint64: newOp = EOpConvUint64ToDouble; break;
default: default:
return nullptr; return nullptr;
} }
break; break;
case EbtFloat: case EbtFloat:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtInt8: newOp = EOpConvInt8ToFloat; break; case EbtInt8: newOp = EOpConvInt8ToFloat; break;
case EbtUint8: newOp = EOpConvUint8ToFloat; break; case EbtUint8: newOp = EOpConvUint8ToFloat; break;
case EbtInt16: newOp = EOpConvInt16ToFloat; break; case EbtInt16: newOp = EOpConvInt16ToFloat; break;
case EbtUint16: newOp = EOpConvUint16ToFloat; break; case EbtUint16: newOp = EOpConvUint16ToFloat; break;
case EbtInt: newOp = EOpConvIntToFloat; break; case EbtInt: newOp = EOpConvIntToFloat; break;
case EbtUint: newOp = EOpConvUintToFloat; break; case EbtUint: newOp = EOpConvUintToFloat; break;
case EbtBool: newOp = EOpConvBoolToFloat; break; case EbtBool: newOp = EOpConvBoolToFloat; break;
case EbtDouble: newOp = EOpConvDoubleToFloat; break; case EbtDouble: newOp = EOpConvDoubleToFloat; break;
case EbtFloat16: newOp = EOpConvFloat16ToFloat; break; case EbtFloat16: newOp = EOpConvFloat16ToFloat; break;
case EbtInt64: newOp = EOpConvInt64ToFloat; break; case EbtInt64: newOp = EOpConvInt64ToFloat; break;
case EbtUint64: newOp = EOpConvUint64ToFloat; break; case EbtUint64: newOp = EOpConvUint64ToFloat; break;
default: default:
return nullptr; return nullptr;
} }
break; break;
case EbtFloat16: case EbtFloat16:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtInt8: newOp = EOpConvInt8ToFloat16; break; case EbtInt8: newOp = EOpConvInt8ToFloat16; break;
case EbtUint8: newOp = EOpConvUint8ToFloat16; break; case EbtUint8: newOp = EOpConvUint8ToFloat16; break;
case EbtInt16: newOp = EOpConvInt16ToFloat16; break; case EbtInt16: newOp = EOpConvInt16ToFloat16; break;
case EbtUint16: newOp = EOpConvUint16ToFloat16; break; case EbtUint16: newOp = EOpConvUint16ToFloat16; break;
case EbtInt: newOp = EOpConvIntToFloat16; break; case EbtInt: newOp = EOpConvIntToFloat16; break;
case EbtUint: newOp = EOpConvUintToFloat16; break; case EbtUint: newOp = EOpConvUintToFloat16; break;
case EbtBool: newOp = EOpConvBoolToFloat16; break; case EbtBool: newOp = EOpConvBoolToFloat16; break;
@ -539,33 +539,33 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
break; break;
case EbtBool: case EbtBool:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtInt8: newOp = EOpConvInt8ToBool; break; case EbtInt8: newOp = EOpConvInt8ToBool; break;
case EbtUint8: newOp = EOpConvUint8ToBool; break; case EbtUint8: newOp = EOpConvUint8ToBool; break;
case EbtInt16: newOp = EOpConvInt16ToBool; break; case EbtInt16: newOp = EOpConvInt16ToBool; break;
case EbtUint16: newOp = EOpConvUint16ToBool; break; case EbtUint16: newOp = EOpConvUint16ToBool; break;
case EbtInt: newOp = EOpConvIntToBool; break; case EbtInt: newOp = EOpConvIntToBool; break;
case EbtUint: newOp = EOpConvUintToBool; break; case EbtUint: newOp = EOpConvUintToBool; break;
case EbtFloat: newOp = EOpConvFloatToBool; break; case EbtFloat: newOp = EOpConvFloatToBool; break;
case EbtDouble: newOp = EOpConvDoubleToBool; break; case EbtDouble: newOp = EOpConvDoubleToBool; break;
case EbtFloat16: newOp = EOpConvFloat16ToBool; break; case EbtFloat16: newOp = EOpConvFloat16ToBool; break;
case EbtInt64: newOp = EOpConvInt64ToBool; break; case EbtInt64: newOp = EOpConvInt64ToBool; break;
case EbtUint64: newOp = EOpConvUint64ToBool; break; case EbtUint64: newOp = EOpConvUint64ToBool; break;
default: default:
return nullptr; return nullptr;
} }
break; break;
case EbtInt8: case EbtInt8:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtUint8: newOp = EOpConvUint8ToInt8; break; case EbtUint8: newOp = EOpConvUint8ToInt8; break;
case EbtInt16: newOp = EOpConvInt16ToInt8; break; case EbtInt16: newOp = EOpConvInt16ToInt8; break;
case EbtUint16: newOp = EOpConvUint16ToInt8; break; case EbtUint16: newOp = EOpConvUint16ToInt8; break;
case EbtInt: newOp = EOpConvIntToInt8; break; case EbtInt: newOp = EOpConvIntToInt8; break;
case EbtUint: newOp = EOpConvUintToInt8; break; case EbtUint: newOp = EOpConvUintToInt8; break;
case EbtInt64: newOp = EOpConvInt64ToInt8; break; case EbtInt64: newOp = EOpConvInt64ToInt8; break;
case EbtUint64: newOp = EOpConvUint64ToInt8; break; case EbtUint64: newOp = EOpConvUint64ToInt8; break;
case EbtBool: newOp = EOpConvBoolToInt8; break; case EbtBool: newOp = EOpConvBoolToInt8; break;
case EbtFloat: newOp = EOpConvFloatToInt8; break; case EbtFloat: newOp = EOpConvFloatToInt8; break;
case EbtDouble: newOp = EOpConvDoubleToInt8; break; case EbtDouble: newOp = EOpConvDoubleToInt8; break;
case EbtFloat16: newOp = EOpConvFloat16ToInt8; break; case EbtFloat16: newOp = EOpConvFloat16ToInt8; break;
default: default:
return nullptr; return nullptr;
@ -573,16 +573,16 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
break; break;
case EbtUint8: case EbtUint8:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtInt8: newOp = EOpConvInt8ToUint8; break; case EbtInt8: newOp = EOpConvInt8ToUint8; break;
case EbtInt16: newOp = EOpConvInt16ToUint8; break; case EbtInt16: newOp = EOpConvInt16ToUint8; break;
case EbtUint16: newOp = EOpConvUint16ToUint8; break; case EbtUint16: newOp = EOpConvUint16ToUint8; break;
case EbtInt: newOp = EOpConvIntToUint8; break; case EbtInt: newOp = EOpConvIntToUint8; break;
case EbtUint: newOp = EOpConvUintToUint8; break; case EbtUint: newOp = EOpConvUintToUint8; break;
case EbtInt64: newOp = EOpConvInt64ToUint8; break; case EbtInt64: newOp = EOpConvInt64ToUint8; break;
case EbtUint64: newOp = EOpConvUint64ToUint8; break; case EbtUint64: newOp = EOpConvUint64ToUint8; break;
case EbtBool: newOp = EOpConvBoolToUint8; break; case EbtBool: newOp = EOpConvBoolToUint8; break;
case EbtFloat: newOp = EOpConvFloatToUint8; break; case EbtFloat: newOp = EOpConvFloatToUint8; break;
case EbtDouble: newOp = EOpConvDoubleToUint8; break; case EbtDouble: newOp = EOpConvDoubleToUint8; break;
case EbtFloat16: newOp = EOpConvFloat16ToUint8; break; case EbtFloat16: newOp = EOpConvFloat16ToUint8; break;
default: default:
return nullptr; return nullptr;
@ -591,16 +591,16 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
case EbtInt16: case EbtInt16:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtUint8: newOp = EOpConvUint8ToInt16; break; case EbtUint8: newOp = EOpConvUint8ToInt16; break;
case EbtInt8: newOp = EOpConvInt8ToInt16; break; case EbtInt8: newOp = EOpConvInt8ToInt16; break;
case EbtUint16: newOp = EOpConvUint16ToInt16; break; case EbtUint16: newOp = EOpConvUint16ToInt16; break;
case EbtInt: newOp = EOpConvIntToInt16; break; case EbtInt: newOp = EOpConvIntToInt16; break;
case EbtUint: newOp = EOpConvUintToInt16; break; case EbtUint: newOp = EOpConvUintToInt16; break;
case EbtInt64: newOp = EOpConvInt64ToInt16; break; case EbtInt64: newOp = EOpConvInt64ToInt16; break;
case EbtUint64: newOp = EOpConvUint64ToInt16; break; case EbtUint64: newOp = EOpConvUint64ToInt16; break;
case EbtBool: newOp = EOpConvBoolToInt16; break; case EbtBool: newOp = EOpConvBoolToInt16; break;
case EbtFloat: newOp = EOpConvFloatToInt16; break; case EbtFloat: newOp = EOpConvFloatToInt16; break;
case EbtDouble: newOp = EOpConvDoubleToInt16; break; case EbtDouble: newOp = EOpConvDoubleToInt16; break;
case EbtFloat16: newOp = EOpConvFloat16ToInt16; break; case EbtFloat16: newOp = EOpConvFloat16ToInt16; break;
default: default:
return nullptr; return nullptr;
@ -608,16 +608,16 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
break; break;
case EbtUint16: case EbtUint16:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtInt8: newOp = EOpConvInt8ToUint16; break; case EbtInt8: newOp = EOpConvInt8ToUint16; break;
case EbtUint8: newOp = EOpConvUint8ToUint16; break; case EbtUint8: newOp = EOpConvUint8ToUint16; break;
case EbtInt16: newOp = EOpConvInt16ToUint16; break; case EbtInt16: newOp = EOpConvInt16ToUint16; break;
case EbtInt: newOp = EOpConvIntToUint16; break; case EbtInt: newOp = EOpConvIntToUint16; break;
case EbtUint: newOp = EOpConvUintToUint16; break; case EbtUint: newOp = EOpConvUintToUint16; break;
case EbtInt64: newOp = EOpConvInt64ToUint16; break; case EbtInt64: newOp = EOpConvInt64ToUint16; break;
case EbtUint64: newOp = EOpConvUint64ToUint16; break; case EbtUint64: newOp = EOpConvUint64ToUint16; break;
case EbtBool: newOp = EOpConvBoolToUint16; break; case EbtBool: newOp = EOpConvBoolToUint16; break;
case EbtFloat: newOp = EOpConvFloatToUint16; break; case EbtFloat: newOp = EOpConvFloatToUint16; break;
case EbtDouble: newOp = EOpConvDoubleToUint16; break; case EbtDouble: newOp = EOpConvDoubleToUint16; break;
case EbtFloat16: newOp = EOpConvFloat16ToUint16; break; case EbtFloat16: newOp = EOpConvFloat16ToUint16; break;
default: default:
return nullptr; return nullptr;
@ -626,68 +626,68 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
case EbtInt: case EbtInt:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtInt8: newOp = EOpConvInt8ToInt; break; case EbtInt8: newOp = EOpConvInt8ToInt; break;
case EbtUint8: newOp = EOpConvUint8ToInt; break; case EbtUint8: newOp = EOpConvUint8ToInt; break;
case EbtInt16: newOp = EOpConvInt16ToInt; break; case EbtInt16: newOp = EOpConvInt16ToInt; break;
case EbtUint16: newOp = EOpConvUint16ToInt; break; case EbtUint16: newOp = EOpConvUint16ToInt; break;
case EbtUint: newOp = EOpConvUintToInt; break; case EbtUint: newOp = EOpConvUintToInt; break;
case EbtBool: newOp = EOpConvBoolToInt; break; case EbtBool: newOp = EOpConvBoolToInt; break;
case EbtFloat: newOp = EOpConvFloatToInt; break; case EbtFloat: newOp = EOpConvFloatToInt; break;
case EbtDouble: newOp = EOpConvDoubleToInt; break; case EbtDouble: newOp = EOpConvDoubleToInt; break;
case EbtFloat16: newOp = EOpConvFloat16ToInt; break; case EbtFloat16: newOp = EOpConvFloat16ToInt; break;
case EbtInt64: newOp = EOpConvInt64ToInt; break; case EbtInt64: newOp = EOpConvInt64ToInt; break;
case EbtUint64: newOp = EOpConvUint64ToInt; break; case EbtUint64: newOp = EOpConvUint64ToInt; break;
default: default:
return nullptr; return nullptr;
} }
break; break;
case EbtUint: case EbtUint:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtInt8: newOp = EOpConvInt8ToUint; break; case EbtInt8: newOp = EOpConvInt8ToUint; break;
case EbtUint8: newOp = EOpConvUint8ToUint; break; case EbtUint8: newOp = EOpConvUint8ToUint; break;
case EbtInt16: newOp = EOpConvInt16ToUint; break; case EbtInt16: newOp = EOpConvInt16ToUint; break;
case EbtUint16: newOp = EOpConvUint16ToUint; break; case EbtUint16: newOp = EOpConvUint16ToUint; break;
case EbtInt: newOp = EOpConvIntToUint; break; case EbtInt: newOp = EOpConvIntToUint; break;
case EbtBool: newOp = EOpConvBoolToUint; break; case EbtBool: newOp = EOpConvBoolToUint; break;
case EbtFloat: newOp = EOpConvFloatToUint; break; case EbtFloat: newOp = EOpConvFloatToUint; break;
case EbtDouble: newOp = EOpConvDoubleToUint; break; case EbtDouble: newOp = EOpConvDoubleToUint; break;
case EbtFloat16: newOp = EOpConvFloat16ToUint; break; case EbtFloat16: newOp = EOpConvFloat16ToUint; break;
case EbtInt64: newOp = EOpConvInt64ToUint; break; case EbtInt64: newOp = EOpConvInt64ToUint; break;
case EbtUint64: newOp = EOpConvUint64ToUint; break; case EbtUint64: newOp = EOpConvUint64ToUint; break;
default: default:
return nullptr; return nullptr;
} }
break; break;
case EbtInt64: case EbtInt64:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtInt8: newOp = EOpConvInt8ToInt64; break; case EbtInt8: newOp = EOpConvInt8ToInt64; break;
case EbtUint8: newOp = EOpConvUint8ToInt64; break; case EbtUint8: newOp = EOpConvUint8ToInt64; break;
case EbtInt16: newOp = EOpConvInt16ToInt64; break; case EbtInt16: newOp = EOpConvInt16ToInt64; break;
case EbtUint16: newOp = EOpConvUint16ToInt64; break; case EbtUint16: newOp = EOpConvUint16ToInt64; break;
case EbtInt: newOp = EOpConvIntToInt64; break; case EbtInt: newOp = EOpConvIntToInt64; break;
case EbtUint: newOp = EOpConvUintToInt64; break; case EbtUint: newOp = EOpConvUintToInt64; break;
case EbtBool: newOp = EOpConvBoolToInt64; break; case EbtBool: newOp = EOpConvBoolToInt64; break;
case EbtFloat: newOp = EOpConvFloatToInt64; break; case EbtFloat: newOp = EOpConvFloatToInt64; break;
case EbtDouble: newOp = EOpConvDoubleToInt64; break; case EbtDouble: newOp = EOpConvDoubleToInt64; break;
case EbtFloat16: newOp = EOpConvFloat16ToInt64; break; case EbtFloat16: newOp = EOpConvFloat16ToInt64; break;
case EbtUint64: newOp = EOpConvUint64ToInt64; break; case EbtUint64: newOp = EOpConvUint64ToInt64; break;
default: default:
return nullptr; return nullptr;
} }
break; break;
case EbtUint64: case EbtUint64:
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtInt8: newOp = EOpConvInt8ToUint64; break; case EbtInt8: newOp = EOpConvInt8ToUint64; break;
case EbtUint8: newOp = EOpConvUint8ToUint64; break; case EbtUint8: newOp = EOpConvUint8ToUint64; break;
case EbtInt16: newOp = EOpConvInt16ToUint64; break; case EbtInt16: newOp = EOpConvInt16ToUint64; break;
case EbtUint16: newOp = EOpConvUint16ToUint64; break; case EbtUint16: newOp = EOpConvUint16ToUint64; break;
case EbtInt: newOp = EOpConvIntToUint64; break; case EbtInt: newOp = EOpConvIntToUint64; break;
case EbtUint: newOp = EOpConvUintToUint64; break; case EbtUint: newOp = EOpConvUintToUint64; break;
case EbtBool: newOp = EOpConvBoolToUint64; break; case EbtBool: newOp = EOpConvBoolToUint64; break;
case EbtFloat: newOp = EOpConvFloatToUint64; break; case EbtFloat: newOp = EOpConvFloatToUint64; break;
case EbtDouble: newOp = EOpConvDoubleToUint64; break; case EbtDouble: newOp = EOpConvDoubleToUint64; break;
case EbtFloat16: newOp = EOpConvFloat16ToUint64; break; case EbtFloat16: newOp = EOpConvFloat16ToUint64; break;
case EbtInt64: newOp = EOpConvInt64ToUint64; break; case EbtInt64: newOp = EOpConvInt64ToUint64; break;
default: default:
return nullptr; return nullptr;
} }
@ -714,25 +714,34 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
return newNode; return newNode;
} }
// For converting a pair of operands to a binary operation to compatible
// types with each other, relative to the operation in 'op'.
// This does not cover assignment operations, which is asymmetric in that the
// left type is not changeable.
// See addConversion(op, type, node) for assignments and unary operation
// conversions.
//
// Generally, this is focused on basic type conversion, not shape conversion.
// See addShapeConversion() for shape conversions.
//
// Returns the converted pair of nodes.
// Returns <nullptr, nullptr> when there is no conversion.
std::tuple<TIntermTyped*, TIntermTyped*> std::tuple<TIntermTyped*, TIntermTyped*>
TIntermediate::addConversion(TOperator op, TIntermTyped* node0, TIntermTyped* node1) const TIntermediate::addConversion(TOperator op, TIntermTyped* node0, TIntermTyped* node1) const
{ {
if (!isConversionAllowed(op, node0) || !isConversionAllowed(op, node1)) { if (!isConversionAllowed(op, node0) || !isConversionAllowed(op, node1))
return std::make_tuple(nullptr, nullptr); return std::make_tuple(nullptr, nullptr);
if (node0->getType() != node1->getType()) {
// If differing structure, then no conversions.
if (node0->isStruct() || node1->isStruct())
return std::make_tuple(nullptr, nullptr);
// If differing arrays, then no conversions.
if (node0->getType().isArray() || node1->getType().isArray())
return std::make_tuple(nullptr, nullptr);
} }
// If types are identical, no problem
if (node0->getType() == node1->getType())
return std::make_tuple(node0, node1);
// If one's a structure, then no conversions.
if (node0->isStruct() || node1->isStruct())
return std::make_tuple(nullptr, nullptr);
// If one's an array, then no conversions.
if (node0->getType().isArray() || node1->getType().isArray())
return std::make_tuple(nullptr, nullptr);
auto promoteTo = std::make_tuple(EbtNumTypes, EbtNumTypes); auto promoteTo = std::make_tuple(EbtNumTypes, EbtNumTypes);
TBasicType type0 = node0->getType().getBasicType(); TBasicType type0 = node0->getType().getBasicType();
@ -767,11 +776,8 @@ TIntermediate::addConversion(TOperator op, TIntermTyped* node0, TIntermTyped* no
case EOpAndAssign: case EOpAndAssign:
case EOpInclusiveOrAssign: case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign: case EOpExclusiveOrAssign:
case EOpLogicalNot:
case EOpLogicalAnd:
case EOpLogicalOr:
case EOpLogicalXor:
case EOpLogicalNot:
case EOpFunctionCall: case EOpFunctionCall:
case EOpReturn: case EOpReturn:
case EOpAssign: case EOpAssign:
@ -782,7 +788,6 @@ TIntermediate::addConversion(TOperator op, TIntermTyped* node0, TIntermTyped* no
case EOpMatrixTimesScalarAssign: case EOpMatrixTimesScalarAssign:
case EOpDivAssign: case EOpDivAssign:
case EOpModAssign: case EOpModAssign:
case EOpAtan: case EOpAtan:
case EOpClamp: case EOpClamp:
case EOpCross: case EOpCross:
@ -803,10 +808,10 @@ TIntermediate::addConversion(TOperator op, TIntermTyped* node0, TIntermTyped* no
case EOpRefract: case EOpRefract:
case EOpSmoothStep: case EOpSmoothStep:
case EOpStep: case EOpStep:
case EOpSequence:
case EOpConstructStruct: case EOpConstructStruct:
case EOpSequence: // used by ?:
if (type0 == type1) if (type0 == type1)
return std::make_tuple(node0, node1); return std::make_tuple(node0, node1);
@ -816,6 +821,15 @@ TIntermediate::addConversion(TOperator op, TIntermTyped* node0, TIntermTyped* no
break; break;
case EOpLogicalAnd:
case EOpLogicalOr:
case EOpLogicalXor:
if (source == EShSourceHlsl)
promoteTo = std::make_tuple(EbtBool, EbtBool);
else
return std::make_tuple(node0, node1);
break;
// Shifts can have mixed types as long as they are integer and of the same rank, // Shifts can have mixed types as long as they are integer and of the same rank,
// without converting. // without converting.
// It's the left operand's type that determines the resulting type, so no issue // It's the left operand's type that determines the resulting type, so no issue
@ -824,6 +838,8 @@ TIntermediate::addConversion(TOperator op, TIntermTyped* node0, TIntermTyped* no
case EOpRightShift: case EOpRightShift:
case EOpLeftShiftAssign: case EOpLeftShiftAssign:
case EOpRightShiftAssign: case EOpRightShiftAssign:
if (node0->getType() == node1->getType())
return std::make_tuple(node0, node1);
if (isTypeInt(type0) && isTypeInt(type1)) { if (isTypeInt(type0) && isTypeInt(type1)) {
if (getTypeRank(type0) == getTypeRank(type1)) { if (getTypeRank(type0) == getTypeRank(type1)) {
@ -838,6 +854,9 @@ TIntermediate::addConversion(TOperator op, TIntermTyped* node0, TIntermTyped* no
break; break;
default: default:
if (node0->getType() == node1->getType())
return std::make_tuple(node0, node1);
return std::make_tuple(nullptr, nullptr); return std::make_tuple(nullptr, nullptr);
} }
@ -872,7 +891,7 @@ TIntermediate::addConversion(TOperator op, TIntermTyped* node0, TIntermTyped* no
// node passed in if no conversion was needed. // node passed in if no conversion was needed.
// //
// Generally, this is focused on basic type conversion, not shape conversion. // Generally, this is focused on basic type conversion, not shape conversion.
// See addShapeConversion(). // See addShapeConversion() for shape conversions.
// //
// Return nullptr if a conversion can't be done. // Return nullptr if a conversion can't be done.
// //
@ -2952,7 +2971,7 @@ bool TIntermediate::promoteUnary(TIntermUnary& node)
// Convert operand to a boolean type // Convert operand to a boolean type
if (operand->getBasicType() != EbtBool) { if (operand->getBasicType() != EbtBool) {
// Add constructor to boolean type. If that fails, we can't do it, so return false. // Add constructor to boolean type. If that fails, we can't do it, so return false.
TIntermTyped* converted = convertToBasicType(op, EbtBool, operand); TIntermTyped* converted = addConversion(op, TType(EbtBool), operand);
if (converted == nullptr) if (converted == nullptr)
return false; return false;
@ -2997,24 +3016,6 @@ void TIntermUnary::updatePrecision()
} }
} }
// If it is not already, convert this node to the given basic type.
TIntermTyped* TIntermediate::convertToBasicType(TOperator op, TBasicType basicType, TIntermTyped* node) const
{
if (node == nullptr)
return nullptr;
// It's already this basic type: nothing needs to be done, so use the node directly.
if (node->getBasicType() == basicType)
return node;
const TType& type = node->getType();
const TType newType(basicType, type.getQualifier().storage,
type.getVectorSize(), type.getMatrixCols(), type.getMatrixRows(), type.isVector());
// Add constructor to the right vectorness of the right type. If that fails, we can't do it, so return nullptr.
return addConversion(op, newType, node);
}
// //
// See TIntermediate::promote // See TIntermediate::promote
// //
@ -3139,21 +3140,17 @@ bool TIntermediate::promoteBinary(TIntermBinary& node)
case EOpLogicalAnd: case EOpLogicalAnd:
case EOpLogicalOr: case EOpLogicalOr:
case EOpLogicalXor: case EOpLogicalXor:
if (getSource() == EShSourceHlsl) { // logical ops operate only on Booleans or vectors of Booleans.
TIntermTyped* convertedL = convertToBasicType(op, EbtBool, left); if (left->getBasicType() != EbtBool || left->isMatrix())
TIntermTyped* convertedR = convertToBasicType(op, EbtBool, right);
if (convertedL == nullptr || convertedR == nullptr)
return false; return false;
node.setLeft(left = convertedL); // also updates stack variable
node.setRight(right = convertedR); // also updates stack variable if (getSource() == EShSourceGlsl) {
} else {
// logical ops operate only on scalar Booleans and will promote to scalar Boolean. // logical ops operate only on scalar Booleans and will promote to scalar Boolean.
if (left->getBasicType() != EbtBool || left->isVector() || left->isMatrix()) if (left->isVector())
return false; return false;
} }
node.setType(TType(EbtBool, EvqTemporary, left->getVectorSize())); node.setType(TType(EbtBool, EvqTemporary, left->getVectorSize()));
break; break;
case EOpRightShift: case EOpRightShift:

View File

@ -459,9 +459,6 @@ public:
TIntermUnary* addUnaryNode(TOperator op, TIntermTyped* child, TSourceLoc) const; TIntermUnary* addUnaryNode(TOperator op, TIntermTyped* child, TSourceLoc) const;
TIntermUnary* addUnaryNode(TOperator op, TIntermTyped* child, TSourceLoc, const TType&) const; TIntermUnary* addUnaryNode(TOperator op, TIntermTyped* child, TSourceLoc, const TType&) const;
// Add conversion from node's type to given basic type.
TIntermTyped* convertToBasicType(TOperator op, TBasicType basicType, TIntermTyped* node) const;
// Constant folding (in Constant.cpp) // Constant folding (in Constant.cpp)
TIntermTyped* fold(TIntermAggregate* aggrNode); TIntermTyped* fold(TIntermAggregate* aggrNode);
TIntermTyped* foldConstructor(TIntermAggregate* aggrNode); TIntermTyped* foldConstructor(TIntermAggregate* aggrNode);