Fix part of #2070: Correctly handle promotion for <unary-op>(int).

This still only handles a scalar correctly, and some
vector cases need additional fixes.
This commit is contained in:
John Kessenich 2020-02-11 06:23:48 -07:00
parent 113d07a6eb
commit abfc4c2ceb
6 changed files with 413 additions and 64 deletions

View File

@ -17,8 +17,13 @@ gl_FragCoord origin is upper left
0:7 'inF0' ( in 1-component vector of uint) 0:7 'inF0' ( in 1-component vector of uint)
0:? Sequence 0:? Sequence
0:8 Branch: Return with expression 0:8 Branch: Return with expression
0:8 Construct float ( temp 1-component vector of float)
0:8 direct index ( temp float)
0:8 unpackHalf2x16 ( temp 2-component vector of float)
0:8 Construct uint ( in uint)
0:8 'inF0' ( in 1-component vector of uint)
0:8 Constant: 0:8 Constant:
0:8 0.000000 0:8 0 (const int)
0:12 Function Definition: PixelShaderFunction2(vu2; ( temp 2-component vector of float) 0:12 Function Definition: PixelShaderFunction2(vu2; ( temp 2-component vector of float)
0:12 Function Parameters: 0:12 Function Parameters:
0:12 'inF0' ( in 2-component vector of uint) 0:12 'inF0' ( in 2-component vector of uint)
@ -149,8 +154,13 @@ gl_FragCoord origin is upper left
0:7 'inF0' ( in 1-component vector of uint) 0:7 'inF0' ( in 1-component vector of uint)
0:? Sequence 0:? Sequence
0:8 Branch: Return with expression 0:8 Branch: Return with expression
0:8 Construct float ( temp 1-component vector of float)
0:8 direct index ( temp float)
0:8 unpackHalf2x16 ( temp 2-component vector of float)
0:8 Construct uint ( in uint)
0:8 'inF0' ( in 1-component vector of uint)
0:8 Constant: 0:8 Constant:
0:8 0.000000 0:8 0 (const int)
0:12 Function Definition: PixelShaderFunction2(vu2; ( temp 2-component vector of float) 0:12 Function Definition: PixelShaderFunction2(vu2; ( temp 2-component vector of float)
0:12 Function Parameters: 0:12 Function Parameters:
0:12 'inF0' ( in 2-component vector of uint) 0:12 'inF0' ( in 2-component vector of uint)
@ -261,12 +271,12 @@ gl_FragCoord origin is upper left
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80008 // Generated by (magic number): 80008
// Id's are bound by 103 // Id's are bound by 106
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 101 EntryPoint Fragment 4 "main" 104
ExecutionMode 4 OriginUpperLeft ExecutionMode 4 OriginUpperLeft
Source HLSL 500 Source HLSL 500
Name 4 "main" Name 4 "main"
@ -281,8 +291,8 @@ gl_FragCoord origin is upper left
Name 35 "PixelShaderFunction(vu4;" Name 35 "PixelShaderFunction(vu4;"
Name 34 "inF0" Name 34 "inF0"
Name 38 "@main(" Name 38 "@main("
Name 101 "@entryPointOutput" Name 104 "@entryPointOutput"
Decorate 101(@entryPointOutput) Location 0 Decorate 104(@entryPointOutput) Location 0
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeInt 32 0 6: TypeInt 32 0
@ -303,17 +313,17 @@ gl_FragCoord origin is upper left
33: TypeFunction 32(fvec4) 31(ptr) 33: TypeFunction 32(fvec4) 31(ptr)
37: TypeFunction 32(fvec4) 37: TypeFunction 32(fvec4)
42: 6(int) Constant 0 42: 6(int) Constant 0
46: 8(float) Constant 0 55: 6(int) Constant 1
53: 6(int) Constant 1 71: 6(int) Constant 2
69: 6(int) Constant 2 91: 6(int) Constant 3
89: 6(int) Constant 3 99: 8(float) Constant 0
97: 32(fvec4) ConstantComposite 46 46 46 46 100: 32(fvec4) ConstantComposite 99 99 99 99
100: TypePointer Output 32(fvec4) 103: TypePointer Output 32(fvec4)
101(@entryPointOutput): 100(ptr) Variable Output 104(@entryPointOutput): 103(ptr) Variable Output
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
102: 32(fvec4) FunctionCall 38(@main() 105: 32(fvec4) FunctionCall 38(@main()
Store 101(@entryPointOutput) 102 Store 104(@entryPointOutput) 105
Return Return
FunctionEnd FunctionEnd
11(PixelShaderFunctionS(u1;): 8(float) Function None 9 11(PixelShaderFunctionS(u1;): 8(float) Function None 9
@ -327,63 +337,66 @@ gl_FragCoord origin is upper left
14(PixelShaderFunction1(vu1;): 8(float) Function None 9 14(PixelShaderFunction1(vu1;): 8(float) Function None 9
13(inF0): 7(ptr) FunctionParameter 13(inF0): 7(ptr) FunctionParameter
15: Label 15: Label
ReturnValue 46 46: 6(int) Load 13(inF0)
47: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 46
48: 8(float) CompositeExtract 47 0
ReturnValue 48
FunctionEnd FunctionEnd
21(PixelShaderFunction2(vu2;): 18(fvec2) Function None 19 21(PixelShaderFunction2(vu2;): 18(fvec2) Function None 19
20(inF0): 17(ptr) FunctionParameter 20(inF0): 17(ptr) FunctionParameter
22: Label 22: Label
49: 7(ptr) AccessChain 20(inF0) 42 51: 7(ptr) AccessChain 20(inF0) 42
50: 6(int) Load 49 52: 6(int) Load 51
51: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 50 53: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 52
52: 8(float) CompositeExtract 51 0 54: 8(float) CompositeExtract 53 0
54: 7(ptr) AccessChain 20(inF0) 53 56: 7(ptr) AccessChain 20(inF0) 55
55: 6(int) Load 54 57: 6(int) Load 56
56: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 55 58: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 57
57: 8(float) CompositeExtract 56 0 59: 8(float) CompositeExtract 58 0
58: 18(fvec2) CompositeConstruct 52 57 60: 18(fvec2) CompositeConstruct 54 59
ReturnValue 58 ReturnValue 60
FunctionEnd FunctionEnd
28(PixelShaderFunction3(vu3;): 25(fvec3) Function None 26 28(PixelShaderFunction3(vu3;): 25(fvec3) Function None 26
27(inF0): 24(ptr) FunctionParameter 27(inF0): 24(ptr) FunctionParameter
29: Label 29: Label
61: 7(ptr) AccessChain 27(inF0) 42 63: 7(ptr) AccessChain 27(inF0) 42
62: 6(int) Load 61 64: 6(int) Load 63
63: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 62 65: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 64
64: 8(float) CompositeExtract 63 0 66: 8(float) CompositeExtract 65 0
65: 7(ptr) AccessChain 27(inF0) 53 67: 7(ptr) AccessChain 27(inF0) 55
66: 6(int) Load 65 68: 6(int) Load 67
67: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 66 69: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 68
68: 8(float) CompositeExtract 67 0 70: 8(float) CompositeExtract 69 0
70: 7(ptr) AccessChain 27(inF0) 69 72: 7(ptr) AccessChain 27(inF0) 71
71: 6(int) Load 70 73: 6(int) Load 72
72: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 71 74: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 73
73: 8(float) CompositeExtract 72 0 75: 8(float) CompositeExtract 74 0
74: 25(fvec3) CompositeConstruct 64 68 73 76: 25(fvec3) CompositeConstruct 66 70 75
ReturnValue 74 ReturnValue 76
FunctionEnd FunctionEnd
35(PixelShaderFunction(vu4;): 32(fvec4) Function None 33 35(PixelShaderFunction(vu4;): 32(fvec4) Function None 33
34(inF0): 31(ptr) FunctionParameter 34(inF0): 31(ptr) FunctionParameter
36: Label 36: Label
77: 7(ptr) AccessChain 34(inF0) 42 79: 7(ptr) AccessChain 34(inF0) 42
78: 6(int) Load 77 80: 6(int) Load 79
79: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 78 81: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 80
80: 8(float) CompositeExtract 79 0 82: 8(float) CompositeExtract 81 0
81: 7(ptr) AccessChain 34(inF0) 53 83: 7(ptr) AccessChain 34(inF0) 55
82: 6(int) Load 81 84: 6(int) Load 83
83: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 82 85: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 84
84: 8(float) CompositeExtract 83 0 86: 8(float) CompositeExtract 85 0
85: 7(ptr) AccessChain 34(inF0) 69 87: 7(ptr) AccessChain 34(inF0) 71
86: 6(int) Load 85 88: 6(int) Load 87
87: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 86 89: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 88
88: 8(float) CompositeExtract 87 0 90: 8(float) CompositeExtract 89 0
90: 7(ptr) AccessChain 34(inF0) 89 92: 7(ptr) AccessChain 34(inF0) 91
91: 6(int) Load 90 93: 6(int) Load 92
92: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 91 94: 18(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 93
93: 8(float) CompositeExtract 92 0 95: 8(float) CompositeExtract 94 0
94: 32(fvec4) CompositeConstruct 80 84 88 93 96: 32(fvec4) CompositeConstruct 82 86 90 95
ReturnValue 94 ReturnValue 96
FunctionEnd FunctionEnd
38(@main(): 32(fvec4) Function None 37 38(@main(): 32(fvec4) Function None 37
39: Label 39: Label
ReturnValue 97 ReturnValue 100
FunctionEnd FunctionEnd

View File

@ -0,0 +1,312 @@
hlsl.singleArgIntPromo.vert
Shader version: 500
0:? Sequence
0:2 Function Definition: @main( ( temp float)
0:2 Function Parameters:
0:? Sequence
0:3 Sequence
0:3 move second child to first child ( temp int)
0:3 'd' ( temp int)
0:3 Constant:
0:3 4 (const int)
0:4 Sequence
0:4 move second child to first child ( temp 2-component vector of int)
0:4 'd2' ( temp 2-component vector of int)
0:? Construct ivec2 ( temp 2-component vector of int)
0:4 Constant:
0:4 5 (const int)
0:4 'd' ( temp int)
0:5 Sequence
0:5 move second child to first child ( temp float)
0:5 'f1' ( temp float)
0:5 Constant:
0:5 2.321928
0:6 Sequence
0:6 move second child to first child ( temp 2-component vector of float)
0:6 'f2' ( temp 2-component vector of float)
0:6 log ( temp 2-component vector of float)
0:6 Convert int to float ( temp 2-component vector of float)
0:6 'd2' ( temp 2-component vector of int)
0:7 Sequence
0:7 move second child to first child ( temp 3-component vector of float)
0:7 'f3' ( temp 3-component vector of float)
0:? Constant:
0:? 1.945910
0:? 0.693147
0:? 1.098612
0:8 Sequence
0:8 move second child to first child ( temp 2-component vector of float)
0:8 'f22' ( temp 2-component vector of float)
0:8 Constant:
0:8 0.000000
0:8 0.000000
0:10 Sequence
0:10 move second child to first child ( temp int)
0:10 'a' ( temp int)
0:10 Constant:
0:10 5 (const int)
0:11 Sequence
0:11 move second child to first child ( temp mediump float)
0:11 'b' ( temp mediump float)
0:11 direct index ( temp mediump float)
0:11 unpackHalf2x16 ( temp mediump 2-component vector of float)
0:11 Convert int to uint ( temp mediump uint)
0:11 'a' ( temp mediump int)
0:11 Constant:
0:11 0 (const int)
0:12 multiply second child into first child ( temp mediump float)
0:12 'b' ( temp mediump float)
0:12 'b' ( temp mediump float)
0:13 Sequence
0:13 move second child to first child ( temp uint)
0:13 'c' ( temp uint)
0:13 packHalf2x16 ( temp uint)
0:13 Construct vec2 ( temp 2-component vector of float)
0:13 'b' ( temp mediump float)
0:13 Constant:
0:13 0.000000
0:15 Branch: Return with expression
0:15 add ( temp float)
0:15 add ( temp float)
0:15 add ( temp float)
0:15 add ( temp float)
0:15 'f1' ( temp float)
0:15 direct index ( temp float)
0:15 'f2' ( temp 2-component vector of float)
0:15 Constant:
0:15 0 (const int)
0:15 direct index ( temp float)
0:15 'f3' ( temp 3-component vector of float)
0:15 Constant:
0:15 2 (const int)
0:15 direct index ( temp float)
0:15 'f22' ( temp 2-component vector of float)
0:15 Constant:
0:15 1 (const int)
0:15 Convert uint to float ( temp float)
0:15 'c' ( temp uint)
0:2 Function Definition: main( ( temp void)
0:2 Function Parameters:
0:? Sequence
0:2 move second child to first child ( temp float)
0:? '@entryPointOutput' (layout( location=0) out float)
0:2 Function Call: @main( ( temp float)
0:? Linker Objects
0:? '@entryPointOutput' (layout( location=0) out float)
Linked vertex stage:
Shader version: 500
0:? Sequence
0:2 Function Definition: @main( ( temp float)
0:2 Function Parameters:
0:? Sequence
0:3 Sequence
0:3 move second child to first child ( temp int)
0:3 'd' ( temp int)
0:3 Constant:
0:3 4 (const int)
0:4 Sequence
0:4 move second child to first child ( temp 2-component vector of int)
0:4 'd2' ( temp 2-component vector of int)
0:? Construct ivec2 ( temp 2-component vector of int)
0:4 Constant:
0:4 5 (const int)
0:4 'd' ( temp int)
0:5 Sequence
0:5 move second child to first child ( temp float)
0:5 'f1' ( temp float)
0:5 Constant:
0:5 2.321928
0:6 Sequence
0:6 move second child to first child ( temp 2-component vector of float)
0:6 'f2' ( temp 2-component vector of float)
0:6 log ( temp 2-component vector of float)
0:6 Convert int to float ( temp 2-component vector of float)
0:6 'd2' ( temp 2-component vector of int)
0:7 Sequence
0:7 move second child to first child ( temp 3-component vector of float)
0:7 'f3' ( temp 3-component vector of float)
0:? Constant:
0:? 1.945910
0:? 0.693147
0:? 1.098612
0:8 Sequence
0:8 move second child to first child ( temp 2-component vector of float)
0:8 'f22' ( temp 2-component vector of float)
0:8 Constant:
0:8 0.000000
0:8 0.000000
0:10 Sequence
0:10 move second child to first child ( temp int)
0:10 'a' ( temp int)
0:10 Constant:
0:10 5 (const int)
0:11 Sequence
0:11 move second child to first child ( temp mediump float)
0:11 'b' ( temp mediump float)
0:11 direct index ( temp mediump float)
0:11 unpackHalf2x16 ( temp mediump 2-component vector of float)
0:11 Convert int to uint ( temp mediump uint)
0:11 'a' ( temp mediump int)
0:11 Constant:
0:11 0 (const int)
0:12 multiply second child into first child ( temp mediump float)
0:12 'b' ( temp mediump float)
0:12 'b' ( temp mediump float)
0:13 Sequence
0:13 move second child to first child ( temp uint)
0:13 'c' ( temp uint)
0:13 packHalf2x16 ( temp uint)
0:13 Construct vec2 ( temp 2-component vector of float)
0:13 'b' ( temp mediump float)
0:13 Constant:
0:13 0.000000
0:15 Branch: Return with expression
0:15 add ( temp float)
0:15 add ( temp float)
0:15 add ( temp float)
0:15 add ( temp float)
0:15 'f1' ( temp float)
0:15 direct index ( temp float)
0:15 'f2' ( temp 2-component vector of float)
0:15 Constant:
0:15 0 (const int)
0:15 direct index ( temp float)
0:15 'f3' ( temp 3-component vector of float)
0:15 Constant:
0:15 2 (const int)
0:15 direct index ( temp float)
0:15 'f22' ( temp 2-component vector of float)
0:15 Constant:
0:15 1 (const int)
0:15 Convert uint to float ( temp float)
0:15 'c' ( temp uint)
0:2 Function Definition: main( ( temp void)
0:2 Function Parameters:
0:? Sequence
0:2 move second child to first child ( temp float)
0:? '@entryPointOutput' (layout( location=0) out float)
0:2 Function Call: @main( ( temp float)
0:? Linker Objects
0:? '@entryPointOutput' (layout( location=0) out float)
// Module Version 10000
// Generated by (magic number): 80008
// Id's are bound by 75
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 73
Source HLSL 500
Name 4 "main"
Name 8 "@main("
Name 12 "d"
Name 16 "d2"
Name 21 "f1"
Name 25 "f2"
Name 31 "f3"
Name 36 "f22"
Name 39 "a"
Name 40 "b"
Name 51 "c"
Name 73 "@entryPointOutput"
Decorate 40(b) RelaxedPrecision
Decorate 41 RelaxedPrecision
Decorate 43 RelaxedPrecision
Decorate 44 RelaxedPrecision
Decorate 46 RelaxedPrecision
Decorate 47 RelaxedPrecision
Decorate 48 RelaxedPrecision
Decorate 49 RelaxedPrecision
Decorate 52 RelaxedPrecision
Decorate 73(@entryPointOutput) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeFunction 6(float)
10: TypeInt 32 1
11: TypePointer Function 10(int)
13: 10(int) Constant 4
14: TypeVector 10(int) 2
15: TypePointer Function 14(ivec2)
17: 10(int) Constant 5
20: TypePointer Function 6(float)
22: 6(float) Constant 1075092088
23: TypeVector 6(float) 2
24: TypePointer Function 23(fvec2)
29: TypeVector 6(float) 3
30: TypePointer Function 29(fvec3)
32: 6(float) Constant 1073288085
33: 6(float) Constant 1060205080
34: 6(float) Constant 1066180436
35: 29(fvec3) ConstantComposite 32 33 34
37: 6(float) Constant 0
38: 23(fvec2) ConstantComposite 37 37
42: TypeInt 32 0
45: 42(int) Constant 0
50: TypePointer Function 42(int)
59: 42(int) Constant 2
63: 42(int) Constant 1
72: TypePointer Output 6(float)
73(@entryPointOutput): 72(ptr) Variable Output
4(main): 2 Function None 3
5: Label
74: 6(float) FunctionCall 8(@main()
Store 73(@entryPointOutput) 74
Return
FunctionEnd
8(@main(): 6(float) Function None 7
9: Label
12(d): 11(ptr) Variable Function
16(d2): 15(ptr) Variable Function
21(f1): 20(ptr) Variable Function
25(f2): 24(ptr) Variable Function
31(f3): 30(ptr) Variable Function
36(f22): 24(ptr) Variable Function
39(a): 11(ptr) Variable Function
40(b): 20(ptr) Variable Function
51(c): 50(ptr) Variable Function
Store 12(d) 13
18: 10(int) Load 12(d)
19: 14(ivec2) CompositeConstruct 17 18
Store 16(d2) 19
Store 21(f1) 22
26: 14(ivec2) Load 16(d2)
27: 23(fvec2) ConvertSToF 26
28: 23(fvec2) ExtInst 1(GLSL.std.450) 28(Log) 27
Store 25(f2) 28
Store 31(f3) 35
Store 36(f22) 38
Store 39(a) 17
41: 10(int) Load 39(a)
43: 42(int) Bitcast 41
44: 23(fvec2) ExtInst 1(GLSL.std.450) 62(UnpackHalf2x16) 43
46: 6(float) CompositeExtract 44 0
Store 40(b) 46
47: 6(float) Load 40(b)
48: 6(float) Load 40(b)
49: 6(float) FMul 48 47
Store 40(b) 49
52: 6(float) Load 40(b)
53: 23(fvec2) CompositeConstruct 52 37
54: 42(int) ExtInst 1(GLSL.std.450) 58(PackHalf2x16) 53
Store 51(c) 54
55: 6(float) Load 21(f1)
56: 20(ptr) AccessChain 25(f2) 45
57: 6(float) Load 56
58: 6(float) FAdd 55 57
60: 20(ptr) AccessChain 31(f3) 59
61: 6(float) Load 60
62: 6(float) FAdd 58 61
64: 20(ptr) AccessChain 36(f22) 63
65: 6(float) Load 64
66: 6(float) FAdd 62 65
67: 42(int) Load 51(c)
68: 6(float) ConvertUToF 67
69: 6(float) FAdd 66 68
ReturnValue 69
FunctionEnd

View File

@ -0,0 +1,16 @@
float main(): SV_Target0
{
int d = 4;
int2 d2 = int2(5,d);
float f1 = log2(5);
float2 f2 = log(d2);
float3 f3 = log(int3(7,2,3));
float2 f22 = log(int2(5,d)); // This case does not work yet, due to a different bug that turns this into 2 args.
int a = 5;
min16float b = min16float(f16tof32(a));
b *= b;
uint c = f32tof16(b);
return f1 + f2.x + f3.z + f22.y + c;
}

View File

@ -3237,10 +3237,17 @@ bool TIntermediate::promoteUnary(TIntermUnary& node)
return false; return false;
break; break;
default: default:
if (operand->getBasicType() != EbtFloat) // HLSL uses this path for initial function signature finding for built-ins
// taking a single argument, which generally don't participate in
// operator-based type promotion (type conversion will occur later).
// For now, scalar argument cases are relying on the setType() call below.
if (getSource() == EShSourceHlsl)
break;
// GLSL only allows integer arguments for the cases identified above in the
// case statements.
if (operand->getBasicType() != EbtFloat)
return false; return false;
} }

View File

@ -350,6 +350,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.semicolons.frag", "main"}, {"hlsl.semicolons.frag", "main"},
{"hlsl.shapeConv.frag", "main"}, {"hlsl.shapeConv.frag", "main"},
{"hlsl.shapeConvRet.frag", "main"}, {"hlsl.shapeConvRet.frag", "main"},
{"hlsl.singleArgIntPromo.vert", "main"},
{"hlsl.self_cast.frag", "main"}, {"hlsl.self_cast.frag", "main"},
{"hlsl.snorm.uav.comp", "main"}, {"hlsl.snorm.uav.comp", "main"},
{"hlsl.specConstant.frag", "main"}, {"hlsl.specConstant.frag", "main"},