From 3d2391fb2521c06c69b4f7160c1ce88941d685a2 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Wed, 15 Jul 2020 23:38:47 -0600 Subject: [PATCH] GLSL/SPV: Propagaet precision qualifier from function to return value. When a return value's type has no precision qualification (e.g., the return expression is formed from a constructor), and the formal function return type has a precision qualification, back propagate that from the return type to the type of the return value's expression. --- Test/baseResults/310AofA.vert.out | 6 +- Test/baseResults/array100.frag.out | 4 +- Test/baseResults/spv.forwardFun.frag.out | 54 +- Test/baseResults/spv.switch.frag.out | 805 ++++++++++---------- glslang/Include/intermediate.h | 1 + glslang/MachineIndependent/Intermediate.cpp | 32 +- glslang/MachineIndependent/ParseHelper.cpp | 15 +- 7 files changed, 462 insertions(+), 455 deletions(-) diff --git a/Test/baseResults/310AofA.vert.out b/Test/baseResults/310AofA.vert.out index 451cc0b4..eec22cc6 100644 --- a/Test/baseResults/310AofA.vert.out +++ b/Test/baseResults/310AofA.vert.out @@ -61,7 +61,7 @@ ERROR: node is still EOpNull! 0:49 Constant: 0:49 0.000000 0:50 Branch: Return with expression -0:50 Construct float ( temp 4-element array of 7-element array of float) +0:50 Construct float ( temp 4-element array of 7-element array of highp float) 0:50 direct index ( temp 7-element array of highp float) 0:50 'a' ( in 5-element array of 7-element array of highp float) 0:50 Constant: @@ -76,7 +76,7 @@ ERROR: node is still EOpNull! 0:50 Constant: 0:50 3 (const int) 0:51 Branch: Return with expression -0:51 Construct float ( temp 4-element array of 7-element array of float) +0:51 Construct float ( temp 4-element array of 7-element array of highp float) 0:51 direct index ( temp 7-element array of highp float) 0:51 'a' ( in 5-element array of 7-element array of highp float) 0:51 Constant: @@ -91,7 +91,7 @@ ERROR: node is still EOpNull! 0:51 Constant: 0:51 3 (const int) 0:52 Branch: Return with expression -0:52 Construct float ( temp 4-element array of 7-element array of float) +0:52 Construct float ( temp 4-element array of 7-element array of highp float) 0:52 direct index ( temp 7-element array of highp float) 0:52 'a' ( in 5-element array of 7-element array of highp float) 0:52 Constant: diff --git a/Test/baseResults/array100.frag.out b/Test/baseResults/array100.frag.out index e6f9f8dc..ecb55f9d 100644 --- a/Test/baseResults/array100.frag.out +++ b/Test/baseResults/array100.frag.out @@ -31,7 +31,7 @@ ERROR: node is still EOpNull! 0:9 'a' ( in 5-element array of mediump float) 0:11 Sequence 0:11 Branch: Return with expression -0:11 Construct float ( temp 4-element array of float) +0:11 Construct float ( temp 4-element array of mediump float) 0:11 direct index ( temp mediump float) 0:11 'a' ( in 5-element array of mediump float) 0:11 Constant: @@ -168,7 +168,7 @@ ERROR: node is still EOpNull! 0:9 'a' ( in 5-element array of mediump float) 0:11 Sequence 0:11 Branch: Return with expression -0:11 Construct float ( temp 4-element array of float) +0:11 Construct float ( temp 4-element array of mediump float) 0:11 direct index ( temp mediump float) 0:11 'a' ( in 5-element array of mediump float) 0:11 Constant: diff --git a/Test/baseResults/spv.forwardFun.frag.out b/Test/baseResults/spv.forwardFun.frag.out index acec2c4f..f1662865 100644 --- a/Test/baseResults/spv.forwardFun.frag.out +++ b/Test/baseResults/spv.forwardFun.frag.out @@ -1,12 +1,12 @@ spv.forwardFun.frag // Module Version 10000 // Generated by (magic number): 8000a -// Id's are bound by 64 +// Id's are bound by 60 Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 4 "main" 20 30 36 63 + EntryPoint Fragment 4 "main" 20 30 36 59 ExecutionMode 4 OriginUpperLeft Source GLSL 140 Name 4 "main" @@ -20,7 +20,7 @@ spv.forwardFun.frag Name 27 "f" Name 30 "gl_FragColor" Name 36 "d" - Name 63 "bigColor" + Name 59 "bigColor" Decorate 10(unreachableReturn() RelaxedPrecision Decorate 16(foo(vf4;) RelaxedPrecision Decorate 15(bar) RelaxedPrecision @@ -41,15 +41,11 @@ spv.forwardFun.frag Decorate 36(d) RelaxedPrecision Decorate 36(d) Location 2 Decorate 37 RelaxedPrecision - Decorate 44 RelaxedPrecision - Decorate 45 RelaxedPrecision - Decorate 49 RelaxedPrecision - Decorate 50 RelaxedPrecision + Decorate 52 RelaxedPrecision + Decorate 55 RelaxedPrecision Decorate 56 RelaxedPrecision - Decorate 59 RelaxedPrecision - Decorate 60 RelaxedPrecision - Decorate 63(bigColor) RelaxedPrecision - Decorate 63(bigColor) Location 0 + Decorate 59(bigColor) RelaxedPrecision + Decorate 59(bigColor) Location 0 2: TypeVoid 3: TypeFunction 2 8: TypeFloat 32 @@ -67,11 +63,11 @@ spv.forwardFun.frag 38: 8(float) Constant 1082549862 39: TypeBool 43: 8(float) Constant 1067030938 - 48: 8(float) Constant 1083179008 - 53: TypeInt 32 0 - 54: 53(int) Constant 0 - 57: 53(int) Constant 1 - 63(bigColor): 19(ptr) Variable Input + 46: 8(float) Constant 1083179008 + 49: TypeInt 32 0 + 50: 49(int) Constant 0 + 53: 49(int) Constant 1 + 59(bigColor): 19(ptr) Variable Input 4(main): 2 Function None 3 5: Label 18(color): 13(ptr) Variable Function @@ -97,31 +93,25 @@ spv.forwardFun.frag FunctionEnd 10(unreachableReturn(): 8(float) Function None 9 11: Label - 44: 26(ptr) Variable Function - 49: 26(ptr) Variable Function 34: 2 FunctionCall 6(bar() 37: 8(float) Load 36(d) 40: 39(bool) FOrdLessThan 37 38 SelectionMerge 42 None - BranchConditional 40 41 47 + BranchConditional 40 41 45 41: Label - Store 44 43 - 45: 8(float) Load 44 - ReturnValue 45 - 47: Label - Store 49 48 - 50: 8(float) Load 49 - ReturnValue 50 + ReturnValue 43 + 45: Label + ReturnValue 46 42: Label Unreachable FunctionEnd 16(foo(vf4;): 8(float) Function None 14 15(bar): 13(ptr) FunctionParameter 17: Label - 55: 26(ptr) AccessChain 15(bar) 54 - 56: 8(float) Load 55 - 58: 26(ptr) AccessChain 15(bar) 57 - 59: 8(float) Load 58 - 60: 8(float) FAdd 56 59 - ReturnValue 60 + 51: 26(ptr) AccessChain 15(bar) 50 + 52: 8(float) Load 51 + 54: 26(ptr) AccessChain 15(bar) 53 + 55: 8(float) Load 54 + 56: 8(float) FAdd 52 55 + ReturnValue 56 FunctionEnd diff --git a/Test/baseResults/spv.switch.frag.out b/Test/baseResults/spv.switch.frag.out index 7612f5fd..9c68657f 100644 --- a/Test/baseResults/spv.switch.frag.out +++ b/Test/baseResults/spv.switch.frag.out @@ -5,12 +5,12 @@ WARNING: 0:139: 'switch' : last case/default label not followed by statements // Module Version 10000 // Generated by (magic number): 8000a -// Id's are bound by 275 +// Id's are bound by 269 Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 4 "main" 68 81 135 233 239 + EntryPoint Fragment 4 "main" 62 75 129 227 233 ExecutionMode 4 OriginUpperLeft Source ESSL 310 Name 4 "main" @@ -22,21 +22,21 @@ WARNING: 0:139: 'switch' : last case/default label not followed by statements Name 17 "v1" Name 18 "v2" Name 19 "i1" - Name 66 "local" - Name 68 "c" - Name 79 "f" - Name 81 "x" - Name 135 "d" - Name 161 "i" - Name 181 "j" - Name 233 "color" - Name 239 "v" - Name 240 "param" - Name 242 "param" - Name 244 "param" - Name 252 "param" - Name 254 "param" - Name 256 "param" + Name 60 "local" + Name 62 "c" + Name 73 "f" + Name 75 "x" + Name 129 "d" + Name 155 "i" + Name 175 "j" + Name 227 "color" + Name 233 "v" + Name 234 "param" + Name 236 "param" + Name 238 "param" + Name 246 "param" + Name 248 "param" + Name 250 "param" Decorate 15(foo1(vf4;vf4;i1;) RelaxedPrecision Decorate 12(v1) RelaxedPrecision Decorate 13(v2) RelaxedPrecision @@ -51,142 +51,136 @@ WARNING: 0:139: 'switch' : last case/default label not followed by statements Decorate 31 RelaxedPrecision Decorate 32 RelaxedPrecision Decorate 33 RelaxedPrecision - Decorate 38 RelaxedPrecision - Decorate 39 RelaxedPrecision - Decorate 42 RelaxedPrecision - Decorate 48 RelaxedPrecision - Decorate 52 RelaxedPrecision + Decorate 40 RelaxedPrecision + Decorate 46 RelaxedPrecision + Decorate 51 RelaxedPrecision Decorate 53 RelaxedPrecision + Decorate 54 RelaxedPrecision Decorate 55 RelaxedPrecision - Decorate 57 RelaxedPrecision - Decorate 58 RelaxedPrecision - Decorate 59 RelaxedPrecision - Decorate 62 RelaxedPrecision + Decorate 60(local) RelaxedPrecision + Decorate 62(c) RelaxedPrecision + Decorate 62(c) Flat + Decorate 62(c) Location 0 Decorate 63 RelaxedPrecision - Decorate 66(local) RelaxedPrecision - Decorate 68(c) RelaxedPrecision - Decorate 68(c) Flat - Decorate 68(c) Location 0 - Decorate 69 RelaxedPrecision - Decorate 70 RelaxedPrecision - Decorate 72 RelaxedPrecision - Decorate 73 RelaxedPrecision - Decorate 79(f) RelaxedPrecision - Decorate 81(x) RelaxedPrecision - Decorate 81(x) Location 2 + Decorate 64 RelaxedPrecision + Decorate 66 RelaxedPrecision + Decorate 67 RelaxedPrecision + Decorate 73(f) RelaxedPrecision + Decorate 75(x) RelaxedPrecision + Decorate 75(x) Location 2 + Decorate 76 RelaxedPrecision + Decorate 77 RelaxedPrecision + Decorate 79 RelaxedPrecision + Decorate 80 RelaxedPrecision Decorate 82 RelaxedPrecision Decorate 83 RelaxedPrecision Decorate 85 RelaxedPrecision - Decorate 86 RelaxedPrecision - Decorate 88 RelaxedPrecision - Decorate 89 RelaxedPrecision + Decorate 90 RelaxedPrecision Decorate 91 RelaxedPrecision + Decorate 92 RelaxedPrecision + Decorate 93 RelaxedPrecision + Decorate 94 RelaxedPrecision + Decorate 95 RelaxedPrecision Decorate 96 RelaxedPrecision Decorate 97 RelaxedPrecision - Decorate 98 RelaxedPrecision Decorate 99 RelaxedPrecision Decorate 100 RelaxedPrecision Decorate 101 RelaxedPrecision Decorate 102 RelaxedPrecision - Decorate 103 RelaxedPrecision - Decorate 105 RelaxedPrecision - Decorate 106 RelaxedPrecision - Decorate 107 RelaxedPrecision + Decorate 104 RelaxedPrecision Decorate 108 RelaxedPrecision + Decorate 109 RelaxedPrecision Decorate 110 RelaxedPrecision + Decorate 111 RelaxedPrecision + Decorate 113 RelaxedPrecision Decorate 114 RelaxedPrecision Decorate 115 RelaxedPrecision Decorate 116 RelaxedPrecision - Decorate 117 RelaxedPrecision Decorate 119 RelaxedPrecision - Decorate 120 RelaxedPrecision - Decorate 121 RelaxedPrecision - Decorate 122 RelaxedPrecision + Decorate 124 RelaxedPrecision Decorate 125 RelaxedPrecision + Decorate 126 RelaxedPrecision + Decorate 127 RelaxedPrecision + Decorate 129(d) RelaxedPrecision + Decorate 129(d) Flat + Decorate 129(d) Location 1 Decorate 130 RelaxedPrecision - Decorate 131 RelaxedPrecision - Decorate 132 RelaxedPrecision - Decorate 133 RelaxedPrecision - Decorate 135(d) RelaxedPrecision - Decorate 135(d) Flat - Decorate 135(d) Location 1 + Decorate 134 RelaxedPrecision + Decorate 135 RelaxedPrecision Decorate 136 RelaxedPrecision + Decorate 137 RelaxedPrecision + Decorate 138 RelaxedPrecision + Decorate 139 RelaxedPrecision Decorate 140 RelaxedPrecision - Decorate 141 RelaxedPrecision Decorate 142 RelaxedPrecision Decorate 143 RelaxedPrecision Decorate 144 RelaxedPrecision Decorate 145 RelaxedPrecision Decorate 146 RelaxedPrecision - Decorate 148 RelaxedPrecision - Decorate 149 RelaxedPrecision Decorate 150 RelaxedPrecision Decorate 151 RelaxedPrecision Decorate 152 RelaxedPrecision - Decorate 156 RelaxedPrecision - Decorate 157 RelaxedPrecision - Decorate 158 RelaxedPrecision - Decorate 159 RelaxedPrecision - Decorate 161(i) RelaxedPrecision - Decorate 168 RelaxedPrecision + Decorate 153 RelaxedPrecision + Decorate 155(i) RelaxedPrecision + Decorate 162 RelaxedPrecision + Decorate 166 RelaxedPrecision + Decorate 171 RelaxedPrecision Decorate 172 RelaxedPrecision - Decorate 177 RelaxedPrecision - Decorate 178 RelaxedPrecision - Decorate 179 RelaxedPrecision - Decorate 180 RelaxedPrecision - Decorate 181(j) RelaxedPrecision - Decorate 188 RelaxedPrecision - Decorate 191 RelaxedPrecision - Decorate 192 RelaxedPrecision + Decorate 173 RelaxedPrecision + Decorate 174 RelaxedPrecision + Decorate 175(j) RelaxedPrecision + Decorate 182 RelaxedPrecision + Decorate 185 RelaxedPrecision + Decorate 186 RelaxedPrecision + Decorate 187 RelaxedPrecision Decorate 193 RelaxedPrecision + Decorate 194 RelaxedPrecision + Decorate 196 RelaxedPrecision + Decorate 197 RelaxedPrecision + Decorate 198 RelaxedPrecision Decorate 199 RelaxedPrecision - Decorate 200 RelaxedPrecision Decorate 202 RelaxedPrecision Decorate 203 RelaxedPrecision Decorate 204 RelaxedPrecision Decorate 205 RelaxedPrecision - Decorate 208 RelaxedPrecision - Decorate 209 RelaxedPrecision - Decorate 210 RelaxedPrecision - Decorate 211 RelaxedPrecision + Decorate 207 RelaxedPrecision Decorate 213 RelaxedPrecision + Decorate 214 RelaxedPrecision + Decorate 215 RelaxedPrecision Decorate 219 RelaxedPrecision Decorate 220 RelaxedPrecision Decorate 221 RelaxedPrecision - Decorate 225 RelaxedPrecision - Decorate 226 RelaxedPrecision - Decorate 227 RelaxedPrecision + Decorate 222 RelaxedPrecision + Decorate 227(color) RelaxedPrecision + Decorate 227(color) Location 0 Decorate 228 RelaxedPrecision - Decorate 233(color) RelaxedPrecision - Decorate 233(color) Location 0 - Decorate 234 RelaxedPrecision + Decorate 229 RelaxedPrecision + Decorate 230 RelaxedPrecision + Decorate 231 RelaxedPrecision + Decorate 233(v) RelaxedPrecision + Decorate 233(v) Location 3 + Decorate 234(param) RelaxedPrecision Decorate 235 RelaxedPrecision - Decorate 236 RelaxedPrecision + Decorate 236(param) RelaxedPrecision Decorate 237 RelaxedPrecision - Decorate 239(v) RelaxedPrecision - Decorate 239(v) Location 3 - Decorate 240(param) RelaxedPrecision - Decorate 241 RelaxedPrecision - Decorate 242(param) RelaxedPrecision + Decorate 238(param) RelaxedPrecision + Decorate 239 RelaxedPrecision + Decorate 240 RelaxedPrecision Decorate 243 RelaxedPrecision - Decorate 244(param) RelaxedPrecision + Decorate 244 RelaxedPrecision Decorate 245 RelaxedPrecision - Decorate 246 RelaxedPrecision + Decorate 246(param) RelaxedPrecision + Decorate 247 RelaxedPrecision + Decorate 248(param) RelaxedPrecision Decorate 249 RelaxedPrecision - Decorate 250 RelaxedPrecision + Decorate 250(param) RelaxedPrecision Decorate 251 RelaxedPrecision - Decorate 252(param) RelaxedPrecision - Decorate 253 RelaxedPrecision - Decorate 254(param) RelaxedPrecision + Decorate 252 RelaxedPrecision + Decorate 254 RelaxedPrecision Decorate 255 RelaxedPrecision - Decorate 256(param) RelaxedPrecision + Decorate 256 RelaxedPrecision Decorate 257 RelaxedPrecision - Decorate 258 RelaxedPrecision - Decorate 260 RelaxedPrecision - Decorate 261 RelaxedPrecision - Decorate 262 RelaxedPrecision - Decorate 263 RelaxedPrecision - Decorate 270 RelaxedPrecision + Decorate 264 RelaxedPrecision 2: TypeVoid 3: TypeFunction 2 6: TypeFloat 32 @@ -197,295 +191,295 @@ WARNING: 0:139: 'switch' : last case/default label not followed by statements 11: TypeFunction 7(fvec4) 8(ptr) 8(ptr) 10(ptr) 36: 6(float) Constant 0 37: 7(fvec4) ConstantComposite 36 36 36 36 - 50: 6(float) Constant 1065353216 - 51: 7(fvec4) ConstantComposite 50 50 50 50 - 67: TypePointer Input 9(int) - 68(c): 67(ptr) Variable Input - 71: 9(int) Constant 1 - 78: TypePointer Function 6(float) - 80: TypePointer Input 6(float) - 81(x): 80(ptr) Variable Input - 135(d): 67(ptr) Variable Input - 162: 9(int) Constant 0 - 169: 9(int) Constant 10 - 170: TypeBool - 182: 9(int) Constant 20 - 189: 9(int) Constant 30 - 194: 6(float) Constant 1120429670 - 214: 6(float) Constant 1079739679 - 232: TypePointer Output 6(float) - 233(color): 232(ptr) Variable Output - 238: TypePointer Input 7(fvec4) - 239(v): 238(ptr) Variable Input - 247: TypeInt 32 0 - 248: 247(int) Constant 1 - 259: 247(int) Constant 2 + 48: 6(float) Constant 1065353216 + 49: 7(fvec4) ConstantComposite 48 48 48 48 + 61: TypePointer Input 9(int) + 62(c): 61(ptr) Variable Input + 65: 9(int) Constant 1 + 72: TypePointer Function 6(float) + 74: TypePointer Input 6(float) + 75(x): 74(ptr) Variable Input + 129(d): 61(ptr) Variable Input + 156: 9(int) Constant 0 + 163: 9(int) Constant 10 + 164: TypeBool + 176: 9(int) Constant 20 + 183: 9(int) Constant 30 + 188: 6(float) Constant 1120429670 + 208: 6(float) Constant 1079739679 + 226: TypePointer Output 6(float) + 227(color): 226(ptr) Variable Output + 232: TypePointer Input 7(fvec4) + 233(v): 232(ptr) Variable Input + 241: TypeInt 32 0 + 242: 241(int) Constant 1 + 253: 241(int) Constant 2 4(main): 2 Function None 3 5: Label - 66(local): 10(ptr) Variable Function - 79(f): 78(ptr) Variable Function - 161(i): 10(ptr) Variable Function - 181(j): 10(ptr) Variable Function - 240(param): 8(ptr) Variable Function - 242(param): 8(ptr) Variable Function - 244(param): 10(ptr) Variable Function - 252(param): 8(ptr) Variable Function - 254(param): 8(ptr) Variable Function - 256(param): 10(ptr) Variable Function - 69: 9(int) Load 68(c) - Store 66(local) 69 - 70: 9(int) Load 66(local) - 72: 9(int) IAdd 70 71 - Store 66(local) 72 - 73: 9(int) Load 68(c) - SelectionMerge 77 None - Switch 73 76 - case 1: 74 - case 2: 75 - 76: Label - 88: 6(float) Load 81(x) - 89: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 88 - Store 79(f) 89 - Branch 77 - 74: Label - 82: 6(float) Load 81(x) - 83: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 82 - Store 79(f) 83 - Branch 77 - 75: Label - 85: 6(float) Load 81(x) - 86: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 85 - Store 79(f) 86 - Branch 77 - 77: Label - 91: 9(int) Load 68(c) - SelectionMerge 95 None - Switch 91 94 - case 1: 92 - case 2: 93 - 94: Label - 105: 6(float) Load 81(x) - 106: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 105 - 107: 6(float) Load 79(f) - 108: 6(float) FAdd 107 106 - Store 79(f) 108 - Branch 95 - 92: Label - 96: 6(float) Load 81(x) - 97: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 96 - 98: 6(float) Load 79(f) - 99: 6(float) FAdd 98 97 - Store 79(f) 99 - Branch 93 - 93: Label - 100: 6(float) Load 81(x) - 101: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 100 - 102: 6(float) Load 79(f) - 103: 6(float) FAdd 102 101 - Store 79(f) 103 - Branch 95 - 95: Label - 110: 9(int) Load 68(c) - SelectionMerge 113 None - Switch 110 113 - case 1: 111 - case 2: 112 - 111: Label - 114: 6(float) Load 81(x) - 115: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 114 - 116: 6(float) Load 79(f) - 117: 6(float) FAdd 116 115 - Store 79(f) 117 - Branch 113 - 112: Label - 119: 6(float) Load 81(x) - 120: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 119 - 121: 6(float) Load 79(f) - 122: 6(float) FAdd 121 120 - Store 79(f) 122 - Branch 113 - 113: Label - 125: 9(int) Load 68(c) - SelectionMerge 129 None - Switch 125 128 - case 1: 126 - case 2: 127 - 128: Label - 156: 6(float) Load 81(x) - 157: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 156 - 158: 6(float) Load 79(f) - 159: 6(float) FAdd 158 157 - Store 79(f) 159 - Branch 129 - 126: Label - 130: 6(float) Load 81(x) - 131: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 130 - 132: 6(float) Load 79(f) - 133: 6(float) FAdd 132 131 - Store 79(f) 133 - Branch 129 - 127: Label - 136: 9(int) Load 135(d) - SelectionMerge 139 None - Switch 136 139 - case 1: 137 - case 2: 138 - 137: Label - 140: 6(float) Load 81(x) - 141: 6(float) Load 81(x) - 142: 6(float) FMul 140 141 - 143: 6(float) Load 81(x) + 60(local): 10(ptr) Variable Function + 73(f): 72(ptr) Variable Function + 155(i): 10(ptr) Variable Function + 175(j): 10(ptr) Variable Function + 234(param): 8(ptr) Variable Function + 236(param): 8(ptr) Variable Function + 238(param): 10(ptr) Variable Function + 246(param): 8(ptr) Variable Function + 248(param): 8(ptr) Variable Function + 250(param): 10(ptr) Variable Function + 63: 9(int) Load 62(c) + Store 60(local) 63 + 64: 9(int) Load 60(local) + 66: 9(int) IAdd 64 65 + Store 60(local) 66 + 67: 9(int) Load 62(c) + SelectionMerge 71 None + Switch 67 70 + case 1: 68 + case 2: 69 + 70: Label + 82: 6(float) Load 75(x) + 83: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 82 + Store 73(f) 83 + Branch 71 + 68: Label + 76: 6(float) Load 75(x) + 77: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 76 + Store 73(f) 77 + Branch 71 + 69: Label + 79: 6(float) Load 75(x) + 80: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 79 + Store 73(f) 80 + Branch 71 + 71: Label + 85: 9(int) Load 62(c) + SelectionMerge 89 None + Switch 85 88 + case 1: 86 + case 2: 87 + 88: Label + 99: 6(float) Load 75(x) + 100: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 99 + 101: 6(float) Load 73(f) + 102: 6(float) FAdd 101 100 + Store 73(f) 102 + Branch 89 + 86: Label + 90: 6(float) Load 75(x) + 91: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 90 + 92: 6(float) Load 73(f) + 93: 6(float) FAdd 92 91 + Store 73(f) 93 + Branch 87 + 87: Label + 94: 6(float) Load 75(x) + 95: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 94 + 96: 6(float) Load 73(f) + 97: 6(float) FAdd 96 95 + Store 73(f) 97 + Branch 89 + 89: Label + 104: 9(int) Load 62(c) + SelectionMerge 107 None + Switch 104 107 + case 1: 105 + case 2: 106 + 105: Label + 108: 6(float) Load 75(x) + 109: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 108 + 110: 6(float) Load 73(f) + 111: 6(float) FAdd 110 109 + Store 73(f) 111 + Branch 107 + 106: Label + 113: 6(float) Load 75(x) + 114: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 113 + 115: 6(float) Load 73(f) + 116: 6(float) FAdd 115 114 + Store 73(f) 116 + Branch 107 + 107: Label + 119: 9(int) Load 62(c) + SelectionMerge 123 None + Switch 119 122 + case 1: 120 + case 2: 121 + 122: Label + 150: 6(float) Load 75(x) + 151: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 150 + 152: 6(float) Load 73(f) + 153: 6(float) FAdd 152 151 + Store 73(f) 153 + Branch 123 + 120: Label + 124: 6(float) Load 75(x) + 125: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 124 + 126: 6(float) Load 73(f) + 127: 6(float) FAdd 126 125 + Store 73(f) 127 + Branch 123 + 121: Label + 130: 9(int) Load 129(d) + SelectionMerge 133 None + Switch 130 133 + case 1: 131 + case 2: 132 + 131: Label + 134: 6(float) Load 75(x) + 135: 6(float) Load 75(x) + 136: 6(float) FMul 134 135 + 137: 6(float) Load 75(x) + 138: 6(float) FMul 136 137 + 139: 6(float) Load 73(f) + 140: 6(float) FAdd 139 138 + Store 73(f) 140 + Branch 133 + 132: Label + 142: 6(float) Load 75(x) + 143: 6(float) Load 75(x) 144: 6(float) FMul 142 143 - 145: 6(float) Load 79(f) + 145: 6(float) Load 73(f) 146: 6(float) FAdd 145 144 - Store 79(f) 146 - Branch 139 - 138: Label - 148: 6(float) Load 81(x) - 149: 6(float) Load 81(x) - 150: 6(float) FMul 148 149 - 151: 6(float) Load 79(f) - 152: 6(float) FAdd 151 150 - Store 79(f) 152 - Branch 139 - 139: Label - Branch 129 - 129: Label - Store 161(i) 162 - Branch 163 - 163: Label - LoopMerge 165 166 None - Branch 167 - 167: Label - 168: 9(int) Load 161(i) - 171: 170(bool) SLessThan 168 169 - BranchConditional 171 164 165 - 164: Label - 172: 9(int) Load 68(c) - SelectionMerge 176 None - Switch 172 175 - case 1: 173 - case 2: 174 - 175: Label - 208: 6(float) Load 81(x) - 209: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 208 - 210: 6(float) Load 79(f) - 211: 6(float) FAdd 210 209 - Store 79(f) 211 - Branch 176 - 173: Label - 177: 6(float) Load 81(x) - 178: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 177 - 179: 6(float) Load 79(f) - 180: 6(float) FAdd 179 178 - Store 79(f) 180 - Store 181(j) 182 - Branch 183 - 183: Label - LoopMerge 185 186 None - Branch 187 - 187: Label - 188: 9(int) Load 181(j) - 190: 170(bool) SLessThan 188 189 - BranchConditional 190 184 185 - 184: Label - 191: 6(float) Load 79(f) - 192: 6(float) FAdd 191 50 - Store 79(f) 192 - 193: 6(float) Load 79(f) - 195: 170(bool) FOrdLessThan 193 194 - SelectionMerge 197 None - BranchConditional 195 196 197 - 196: Label - Branch 185 - 197: Label - Branch 186 - 186: Label - 199: 9(int) Load 181(j) - 200: 9(int) IAdd 199 71 - Store 181(j) 200 - Branch 183 - 185: Label - Branch 176 - 174: Label - 202: 6(float) Load 81(x) - 203: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 202 - 204: 6(float) Load 79(f) + Store 73(f) 146 + Branch 133 + 133: Label + Branch 123 + 123: Label + Store 155(i) 156 + Branch 157 + 157: Label + LoopMerge 159 160 None + Branch 161 + 161: Label + 162: 9(int) Load 155(i) + 165: 164(bool) SLessThan 162 163 + BranchConditional 165 158 159 + 158: Label + 166: 9(int) Load 62(c) + SelectionMerge 170 None + Switch 166 169 + case 1: 167 + case 2: 168 + 169: Label + 202: 6(float) Load 75(x) + 203: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 202 + 204: 6(float) Load 73(f) 205: 6(float) FAdd 204 203 - Store 79(f) 205 - Branch 176 - 176: Label - 213: 6(float) Load 79(f) - 215: 170(bool) FOrdLessThan 213 214 - SelectionMerge 217 None - BranchConditional 215 216 217 - 216: Label - Branch 165 + Store 73(f) 205 + Branch 170 + 167: Label + 171: 6(float) Load 75(x) + 172: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 171 + 173: 6(float) Load 73(f) + 174: 6(float) FAdd 173 172 + Store 73(f) 174 + Store 175(j) 176 + Branch 177 + 177: Label + LoopMerge 179 180 None + Branch 181 + 181: Label + 182: 9(int) Load 175(j) + 184: 164(bool) SLessThan 182 183 + BranchConditional 184 178 179 + 178: Label + 185: 6(float) Load 73(f) + 186: 6(float) FAdd 185 48 + Store 73(f) 186 + 187: 6(float) Load 73(f) + 189: 164(bool) FOrdLessThan 187 188 + SelectionMerge 191 None + BranchConditional 189 190 191 + 190: Label + Branch 179 + 191: Label + Branch 180 + 180: Label + 193: 9(int) Load 175(j) + 194: 9(int) IAdd 193 65 + Store 175(j) 194 + Branch 177 + 179: Label + Branch 170 + 168: Label + 196: 6(float) Load 75(x) + 197: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 196 + 198: 6(float) Load 73(f) + 199: 6(float) FAdd 198 197 + Store 73(f) 199 + Branch 170 + 170: Label + 207: 6(float) Load 73(f) + 209: 164(bool) FOrdLessThan 207 208 + SelectionMerge 211 None + BranchConditional 209 210 211 + 210: Label + Branch 159 + 211: Label + Branch 160 + 160: Label + 213: 9(int) Load 155(i) + 214: 9(int) IAdd 213 65 + Store 155(i) 214 + Branch 157 + 159: Label + 215: 9(int) Load 62(c) + SelectionMerge 218 None + Switch 215 218 + case 1: 216 + case 2: 217 + 216: Label + 219: 6(float) Load 75(x) + 220: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 219 + 221: 6(float) Load 73(f) + 222: 6(float) FAdd 221 220 + Store 73(f) 222 + Branch 218 217: Label - Branch 166 - 166: Label - 219: 9(int) Load 161(i) - 220: 9(int) IAdd 219 71 - Store 161(i) 220 - Branch 163 - 165: Label - 221: 9(int) Load 68(c) - SelectionMerge 224 None - Switch 221 224 - case 1: 222 - case 2: 223 - 222: Label - 225: 6(float) Load 81(x) - 226: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 225 - 227: 6(float) Load 79(f) - 228: 6(float) FAdd 227 226 - Store 79(f) 228 - Branch 224 - 223: Label - Branch 224 - 224: Label - 234: 6(float) Load 79(f) - 235: 9(int) Load 66(local) - 236: 6(float) ConvertSToF 235 - 237: 6(float) FAdd 234 236 - Store 233(color) 237 - 241: 7(fvec4) Load 239(v) - Store 240(param) 241 - 243: 7(fvec4) Load 239(v) - Store 242(param) 243 - 245: 9(int) Load 68(c) - Store 244(param) 245 - 246: 7(fvec4) FunctionCall 15(foo1(vf4;vf4;i1;) 240(param) 242(param) 244(param) - 249: 6(float) CompositeExtract 246 1 - 250: 6(float) Load 233(color) - 251: 6(float) FAdd 250 249 - Store 233(color) 251 - 253: 7(fvec4) Load 239(v) - Store 252(param) 253 - 255: 7(fvec4) Load 239(v) - Store 254(param) 255 - 257: 9(int) Load 68(c) - Store 256(param) 257 - 258: 7(fvec4) FunctionCall 20(foo2(vf4;vf4;i1;) 252(param) 254(param) 256(param) - 260: 6(float) CompositeExtract 258 2 - 261: 6(float) Load 233(color) - 262: 6(float) FAdd 261 260 - Store 233(color) 262 - 263: 9(int) Load 68(c) + Branch 218 + 218: Label + 228: 6(float) Load 73(f) + 229: 9(int) Load 60(local) + 230: 6(float) ConvertSToF 229 + 231: 6(float) FAdd 228 230 + Store 227(color) 231 + 235: 7(fvec4) Load 233(v) + Store 234(param) 235 + 237: 7(fvec4) Load 233(v) + Store 236(param) 237 + 239: 9(int) Load 62(c) + Store 238(param) 239 + 240: 7(fvec4) FunctionCall 15(foo1(vf4;vf4;i1;) 234(param) 236(param) 238(param) + 243: 6(float) CompositeExtract 240 1 + 244: 6(float) Load 227(color) + 245: 6(float) FAdd 244 243 + Store 227(color) 245 + 247: 7(fvec4) Load 233(v) + Store 246(param) 247 + 249: 7(fvec4) Load 233(v) + Store 248(param) 249 + 251: 9(int) Load 62(c) + Store 250(param) 251 + 252: 7(fvec4) FunctionCall 20(foo2(vf4;vf4;i1;) 246(param) 248(param) 250(param) + 254: 6(float) CompositeExtract 252 2 + 255: 6(float) Load 227(color) + 256: 6(float) FAdd 255 254 + Store 227(color) 256 + 257: 9(int) Load 62(c) + SelectionMerge 260 None + Switch 257 259 + case 0: 258 + 259: Label + Branch 260 + 258: Label + Branch 260 + 260: Label + 264: 9(int) Load 62(c) SelectionMerge 266 None - Switch 263 265 - case 0: 264 + Switch 264 265 265: Label Branch 266 - 264: Label - Branch 266 266: Label - 270: 9(int) Load 68(c) - SelectionMerge 272 None - Switch 270 271 - 271: Label - Branch 272 - 272: Label Return FunctionEnd 15(foo1(vf4;vf4;i1;): 7(fvec4) Function None 11 @@ -493,7 +487,6 @@ WARNING: 0:139: 'switch' : last case/default label not followed by statements 13(v2): 8(ptr) FunctionParameter 14(i1): 10(ptr) FunctionParameter 16: Label - 38: 8(ptr) Variable Function 22: 9(int) Load 14(i1) SelectionMerge 26 None Switch 22 26 @@ -513,41 +506,33 @@ WARNING: 0:139: 'switch' : last case/default label not followed by statements 33: 7(fvec4) FMul 31 32 ReturnValue 33 26: Label - Store 38 37 - 39: 7(fvec4) Load 38 - ReturnValue 39 + ReturnValue 37 FunctionEnd 20(foo2(vf4;vf4;i1;): 7(fvec4) Function None 11 17(v1): 8(ptr) FunctionParameter 18(v2): 8(ptr) FunctionParameter 19(i1): 10(ptr) FunctionParameter 21: Label - 52: 8(ptr) Variable Function - 62: 8(ptr) Variable Function - 42: 9(int) Load 19(i1) - SelectionMerge 47 None - Switch 42 47 - case 0: 43 - case 2: 44 - case 1: 45 - case 3: 46 + 40: 9(int) Load 19(i1) + SelectionMerge 45 None + Switch 40 45 + case 0: 41 + case 2: 42 + case 1: 43 + case 3: 44 + 41: Label + 46: 7(fvec4) Load 17(v1) + ReturnValue 46 + 42: Label + ReturnValue 49 43: Label - 48: 7(fvec4) Load 17(v1) - ReturnValue 48 + 51: 7(fvec4) Load 18(v2) + ReturnValue 51 44: Label - Store 52 51 - 53: 7(fvec4) Load 52 - ReturnValue 53 - 45: Label - 55: 7(fvec4) Load 18(v2) + 53: 7(fvec4) Load 17(v1) + 54: 7(fvec4) Load 18(v2) + 55: 7(fvec4) FMul 53 54 ReturnValue 55 - 46: Label - 57: 7(fvec4) Load 17(v1) - 58: 7(fvec4) Load 18(v2) - 59: 7(fvec4) FMul 57 58 - ReturnValue 59 - 47: Label - Store 62 37 - 63: 7(fvec4) Load 62 - ReturnValue 63 + 45: Label + ReturnValue 37 FunctionEnd diff --git a/glslang/Include/intermediate.h b/glslang/Include/intermediate.h index bf12fcf8..30cb6fb1 100644 --- a/glslang/Include/intermediate.h +++ b/glslang/Include/intermediate.h @@ -1231,6 +1231,7 @@ public: TOperator getFlowOp() const { return flowOp; } TIntermTyped* getExpression() const { return expression; } void setExpression(TIntermTyped* pExpression) { expression = pExpression; } + void updatePrecision(TPrecisionQualifier parentPrecision); protected: TOperator flowOp; TIntermTyped* expression; diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index 52ec6115..bb03aa0a 100755 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -2777,6 +2777,22 @@ TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TIntermTyped* expres return node; } +// Propagate precision from formal function return type to actual return type, +// and on to its subtree. +void TIntermBranch::updatePrecision(TPrecisionQualifier parentPrecision) +{ + TIntermTyped* exp = getExpression(); + if (exp == nullptr) + return; + + if (exp->getBasicType() == EbtInt || exp->getBasicType() == EbtUint || + exp->getBasicType() == EbtFloat || exp->getBasicType() == EbtFloat16) { + if (parentPrecision != EpqNone && exp->getQualifier().precision == EpqNone) { + exp->propagatePrecision(parentPrecision); + } + } +} + // // This is to be executed after the final root is put on top by the parsing // process. @@ -3284,9 +3300,11 @@ bool TIntermediate::promoteUnary(TIntermUnary& node) return true; } +// Propagate precision qualifiers *up* from children to parent. void TIntermUnary::updatePrecision() { - if (getBasicType() == EbtInt || getBasicType() == EbtUint || getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { + if (getBasicType() == EbtInt || getBasicType() == EbtUint || + getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { if (operand->getQualifier().precision > getQualifier().precision) getQualifier().precision = operand->getQualifier().precision; } @@ -3782,9 +3800,12 @@ bool TIntermediate::promoteAggregate(TIntermAggregate& node) return false; } +// Propagate precision qualifiers *up* from children to parent, and then +// back *down* again to the children's subtrees. void TIntermBinary::updatePrecision() { - if (getBasicType() == EbtInt || getBasicType() == EbtUint || getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { + if (getBasicType() == EbtInt || getBasicType() == EbtUint || + getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { getQualifier().precision = std::max(right->getQualifier().precision, left->getQualifier().precision); if (getQualifier().precision != EpqNone) { left->propagatePrecision(getQualifier().precision); @@ -3793,9 +3814,14 @@ void TIntermBinary::updatePrecision() } } +// Recursively propagate precision qualifiers *down* the subtree of the current node, +// until reaching a node that already has a precision qualifier or otherwise does +// not participate in precision propagation. void TIntermTyped::propagatePrecision(TPrecisionQualifier newPrecision) { - if (getQualifier().precision != EpqNone || (getBasicType() != EbtInt && getBasicType() != EbtUint && getBasicType() != EbtFloat && getBasicType() != EbtFloat16)) + if (getQualifier().precision != EpqNone || + (getBasicType() != EbtInt && getBasicType() != EbtUint && + getBasicType() != EbtFloat && getBasicType() != EbtFloat16)) return; getQualifier().precision = newPrecision; diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index acdb0a4b..3d0f3293 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -1415,23 +1415,28 @@ TIntermNode* TParseContext::handleReturnValue(const TSourceLoc& loc, TIntermType #endif functionReturnsValue = true; + TIntermBranch* branch = nullptr; if (currentFunctionType->getBasicType() == EbtVoid) { error(loc, "void function cannot return a value", "return", ""); - return intermediate.addBranch(EOpReturn, loc); + branch = intermediate.addBranch(EOpReturn, loc); } else if (*currentFunctionType != value->getType()) { TIntermTyped* converted = intermediate.addConversion(EOpReturn, *currentFunctionType, value); if (converted) { if (*currentFunctionType != converted->getType()) error(loc, "cannot convert return value to function return type", "return", ""); if (version < 420) - warn(loc, "type conversion on return values was not explicitly allowed until version 420", "return", ""); - return intermediate.addBranch(EOpReturn, converted, loc); + warn(loc, "type conversion on return values was not explicitly allowed until version 420", + "return", ""); + branch = intermediate.addBranch(EOpReturn, converted, loc); } else { error(loc, "type does not match, or is not convertible to, the function's return type", "return", ""); - return intermediate.addBranch(EOpReturn, value, loc); + branch = intermediate.addBranch(EOpReturn, value, loc); } } else - return intermediate.addBranch(EOpReturn, value, loc); + branch = intermediate.addBranch(EOpReturn, value, loc); + + branch->updatePrecision(currentFunctionType->getQualifier().precision); + return branch; } // See if the operation is being done in an illegal location.