SPV: RelaxedPrecision: Generalize fix #2293 to cover more operations.

This simplifies and enforces use of precision in many more places,
to help avoid accidental loss of RelaxedPrecision through intermediate
operations. Known fixes are:
- ?:
- function return values with mis-matched precision
- precision of function return values when a copy was needed to fix types
This commit is contained in:
John Kessenich
2020-06-30 01:27:08 -06:00
parent 27e915ed4f
commit 435dd8028b
10 changed files with 835 additions and 670 deletions

View File

@@ -1,12 +1,12 @@
spv.precision.frag
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 127
// Id's are bound by 146
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 23 59 61 73 116
EntryPoint Fragment 4 "main" 23 62 64 76 119
ExecutionMode 4 OriginUpperLeft
Source ESSL 310
Name 4 "main"
@@ -15,72 +15,83 @@ spv.precision.frag
Name 19 "boolfun(vb2;"
Name 18 "bv2"
Name 23 "highfin"
Name 38 "sum"
Name 40 "uniform_medium"
Name 42 "uniform_high"
Name 48 "uniform_low"
Name 53 "arg1"
Name 55 "arg2"
Name 57 "d"
Name 59 "lowfin"
Name 61 "mediumfin"
Name 65 "global_highp"
Name 69 "local_highp"
Name 73 "mediumfout"
Name 104 "ub2"
Name 105 "param"
Name 114 "S"
MemberName 114(S) 0 "a"
MemberName 114(S) 1 "b"
Name 116 "s"
Name 41 "sum"
Name 43 "uniform_medium"
Name 45 "uniform_high"
Name 51 "uniform_low"
Name 56 "arg1"
Name 58 "arg2"
Name 60 "d"
Name 62 "lowfin"
Name 64 "mediumfin"
Name 68 "global_highp"
Name 72 "local_highp"
Name 76 "mediumfout"
Name 107 "ub2"
Name 108 "param"
Name 117 "S"
MemberName 117(S) 0 "a"
MemberName 117(S) 1 "b"
Name 119 "s"
Decorate 12(foo(vf3;) RelaxedPrecision
Decorate 11(mv3) RelaxedPrecision
Decorate 38(sum) RelaxedPrecision
Decorate 40(uniform_medium) RelaxedPrecision
Decorate 41 RelaxedPrecision
Decorate 46 RelaxedPrecision
Decorate 48(uniform_low) RelaxedPrecision
Decorate 27 RelaxedPrecision
Decorate 28 RelaxedPrecision
Decorate 41(sum) RelaxedPrecision
Decorate 43(uniform_medium) RelaxedPrecision
Decorate 44 RelaxedPrecision
Decorate 49 RelaxedPrecision
Decorate 50 RelaxedPrecision
Decorate 51 RelaxedPrecision
Decorate 53(arg1) RelaxedPrecision
Decorate 55(arg2) RelaxedPrecision
Decorate 57(d) RelaxedPrecision
Decorate 59(lowfin) RelaxedPrecision
Decorate 60 RelaxedPrecision
Decorate 61(mediumfin) RelaxedPrecision
Decorate 62 RelaxedPrecision
Decorate 51(uniform_low) RelaxedPrecision
Decorate 52 RelaxedPrecision
Decorate 53 RelaxedPrecision
Decorate 54 RelaxedPrecision
Decorate 56(arg1) RelaxedPrecision
Decorate 58(arg2) RelaxedPrecision
Decorate 60(d) RelaxedPrecision
Decorate 62(lowfin) RelaxedPrecision
Decorate 63 RelaxedPrecision
Decorate 73(mediumfout) RelaxedPrecision
Decorate 74 RelaxedPrecision
Decorate 75 RelaxedPrecision
Decorate 76 RelaxedPrecision
Decorate 64(mediumfin) RelaxedPrecision
Decorate 65 RelaxedPrecision
Decorate 66 RelaxedPrecision
Decorate 76(mediumfout) RelaxedPrecision
Decorate 77 RelaxedPrecision
Decorate 78 RelaxedPrecision
Decorate 79 RelaxedPrecision
Decorate 83 RelaxedPrecision
Decorate 85 RelaxedPrecision
Decorate 87 RelaxedPrecision
Decorate 80 RelaxedPrecision
Decorate 81 RelaxedPrecision
Decorate 82 RelaxedPrecision
Decorate 86 RelaxedPrecision
Decorate 88 RelaxedPrecision
Decorate 90 RelaxedPrecision
Decorate 91 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 110 RelaxedPrecision
Decorate 112 RelaxedPrecision
Decorate 103 RelaxedPrecision
Decorate 104 RelaxedPrecision
Decorate 105 RelaxedPrecision
Decorate 113 RelaxedPrecision
MemberDecorate 114(S) 1 RelaxedPrecision
Decorate 120 RelaxedPrecision
Decorate 124 RelaxedPrecision
Decorate 125 RelaxedPrecision
Decorate 126 RelaxedPrecision
Decorate 115 RelaxedPrecision
Decorate 116 RelaxedPrecision
MemberDecorate 117(S) 1 RelaxedPrecision
Decorate 123 RelaxedPrecision
Decorate 127 RelaxedPrecision
Decorate 128 RelaxedPrecision
Decorate 129 RelaxedPrecision
Decorate 130 RelaxedPrecision
Decorate 131 RelaxedPrecision
Decorate 132 RelaxedPrecision
Decorate 135 RelaxedPrecision
Decorate 139 RelaxedPrecision
Decorate 140 RelaxedPrecision
Decorate 143 RelaxedPrecision
Decorate 144 RelaxedPrecision
Decorate 145 RelaxedPrecision
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
@@ -95,134 +106,161 @@ spv.precision.frag
21: TypeVector 6(float) 4
22: TypePointer Input 21(fvec4)
23(highfin): 22(ptr) Variable Input
29: 14(bool) ConstantFalse
30: 14(bool) ConstantTrue
31: 15(bvec2) ConstantComposite 29 30
36: TypeInt 32 1
37: TypePointer Function 36(int)
39: TypePointer Private 36(int)
40(uniform_medium): 39(ptr) Variable Private
42(uniform_high): 39(ptr) Variable Private
48(uniform_low): 39(ptr) Variable Private
52: TypePointer Function 6(float)
54: 6(float) Constant 1078774989
56: 6(float) Constant 1232730691
58: TypePointer Input 6(float)
59(lowfin): 58(ptr) Variable Input
61(mediumfin): 58(ptr) Variable Input
64: TypePointer Private 6(float)
65(global_highp): 64(ptr) Variable Private
68: TypePointer Function 21(fvec4)
72: TypePointer Output 21(fvec4)
73(mediumfout): 72(ptr) Variable Output
82: 36(int) Constant 4
84: TypeVector 36(int) 2
92: TypeInt 32 0
93: 92(int) Constant 0
103: TypePointer Private 15(bvec2)
104(ub2): 103(ptr) Variable Private
111: 6(float) Constant 1065353216
114(S): TypeStruct 6(float) 6(float)
115: TypePointer Input 114(S)
116(s): 115(ptr) Variable Input
117: 36(int) Constant 0
122: 36(int) Constant 1
26: TypePointer Function 9(fvec2)
32: 14(bool) ConstantFalse
33: 14(bool) ConstantTrue
34: 15(bvec2) ConstantComposite 32 33
39: TypeInt 32 1
40: TypePointer Function 39(int)
42: TypePointer Private 39(int)
43(uniform_medium): 42(ptr) Variable Private
45(uniform_high): 42(ptr) Variable Private
51(uniform_low): 42(ptr) Variable Private
55: TypePointer Function 6(float)
57: 6(float) Constant 1078774989
59: 6(float) Constant 1232730691
61: TypePointer Input 6(float)
62(lowfin): 61(ptr) Variable Input
64(mediumfin): 61(ptr) Variable Input
67: TypePointer Private 6(float)
68(global_highp): 67(ptr) Variable Private
71: TypePointer Function 21(fvec4)
75: TypePointer Output 21(fvec4)
76(mediumfout): 75(ptr) Variable Output
85: 39(int) Constant 4
87: TypeVector 39(int) 2
95: TypeInt 32 0
96: 95(int) Constant 0
106: TypePointer Private 15(bvec2)
107(ub2): 106(ptr) Variable Private
114: 6(float) Constant 1065353216
117(S): TypeStruct 6(float) 6(float)
118: TypePointer Input 117(S)
119(s): 118(ptr) Variable Input
120: 39(int) Constant 0
125: 39(int) Constant 1
133: 6(float) Constant 1082549862
138: 6(float) Constant 1073741824
142: 6(float) Constant 1077936128
4(main): 2 Function None 3
5: Label
38(sum): 37(ptr) Variable Function
53(arg1): 52(ptr) Variable Function
55(arg2): 52(ptr) Variable Function
57(d): 52(ptr) Variable Function
69(local_highp): 68(ptr) Variable Function
105(param): 16(ptr) Variable Function
41: 36(int) Load 40(uniform_medium)
43: 36(int) Load 42(uniform_high)
44: 36(int) IAdd 41 43
Store 38(sum) 44
45: 36(int) Load 42(uniform_high)
46: 36(int) Load 38(sum)
47: 36(int) IAdd 46 45
Store 38(sum) 47
49: 36(int) Load 48(uniform_low)
50: 36(int) Load 38(sum)
51: 36(int) IAdd 50 49
Store 38(sum) 51
Store 53(arg1) 54
Store 55(arg2) 56
60: 6(float) Load 59(lowfin)
62: 6(float) Load 61(mediumfin)
63: 6(float) ExtInst 1(GLSL.std.450) 67(Distance) 60 62
Store 57(d) 63
66: 21(fvec4) Load 23(highfin)
67: 6(float) ExtInst 1(GLSL.std.450) 66(Length) 66
Store 65(global_highp) 67
70: 6(float) Load 65(global_highp)
71: 21(fvec4) CompositeConstruct 70 70 70 70
Store 69(local_highp) 71
74: 6(float) Load 57(d)
75: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 74
76: 21(fvec4) CompositeConstruct 75 75 75 75
77: 6(float) Load 55(arg2)
78: 21(fvec4) CompositeConstruct 77 77 77 77
79: 21(fvec4) FAdd 76 78
80: 21(fvec4) Load 69(local_highp)
81: 21(fvec4) FAdd 79 80
Store 73(mediumfout) 81
83: 36(int) Load 48(uniform_low)
85: 84(ivec2) CompositeConstruct 83 83
86: 36(int) Load 42(uniform_high)
87: 84(ivec2) CompositeConstruct 86 86
88: 84(ivec2) IMul 85 87
89: 36(int) Load 42(uniform_high)
90: 84(ivec2) CompositeConstruct 89 89
91: 84(ivec2) IAdd 88 90
94: 36(int) CompositeExtract 91 0
95: 36(int) IAdd 82 94
96: 36(int) Load 38(sum)
97: 36(int) IAdd 96 95
Store 38(sum) 97
98: 36(int) Load 38(sum)
99: 6(float) ConvertSToF 98
100: 21(fvec4) CompositeConstruct 99 99 99 99
101: 21(fvec4) Load 73(mediumfout)
102: 21(fvec4) FAdd 101 100
Store 73(mediumfout) 102
106: 15(bvec2) Load 104(ub2)
Store 105(param) 106
107: 14(bool) FunctionCall 19(boolfun(vb2;) 105(param)
SelectionMerge 109 None
BranchConditional 107 108 109
108: Label
110: 21(fvec4) Load 73(mediumfout)
112: 21(fvec4) CompositeConstruct 111 111 111 111
113: 21(fvec4) FAdd 110 112
Store 73(mediumfout) 113
Branch 109
109: Label
118: 58(ptr) AccessChain 116(s) 117
119: 6(float) Load 118
120: 21(fvec4) Load 73(mediumfout)
121: 21(fvec4) VectorTimesScalar 120 119
Store 73(mediumfout) 121
123: 58(ptr) AccessChain 116(s) 122
124: 6(float) Load 123
125: 21(fvec4) Load 73(mediumfout)
126: 21(fvec4) VectorTimesScalar 125 124
Store 73(mediumfout) 126
41(sum): 40(ptr) Variable Function
56(arg1): 55(ptr) Variable Function
58(arg2): 55(ptr) Variable Function
60(d): 55(ptr) Variable Function
72(local_highp): 71(ptr) Variable Function
108(param): 16(ptr) Variable Function
135: 71(ptr) Variable Function
44: 39(int) Load 43(uniform_medium)
46: 39(int) Load 45(uniform_high)
47: 39(int) IAdd 44 46
Store 41(sum) 47
48: 39(int) Load 45(uniform_high)
49: 39(int) Load 41(sum)
50: 39(int) IAdd 49 48
Store 41(sum) 50
52: 39(int) Load 51(uniform_low)
53: 39(int) Load 41(sum)
54: 39(int) IAdd 53 52
Store 41(sum) 54
Store 56(arg1) 57
Store 58(arg2) 59
63: 6(float) Load 62(lowfin)
65: 6(float) Load 64(mediumfin)
66: 6(float) ExtInst 1(GLSL.std.450) 67(Distance) 63 65
Store 60(d) 66
69: 21(fvec4) Load 23(highfin)
70: 6(float) ExtInst 1(GLSL.std.450) 66(Length) 69
Store 68(global_highp) 70
73: 6(float) Load 68(global_highp)
74: 21(fvec4) CompositeConstruct 73 73 73 73
Store 72(local_highp) 74
77: 6(float) Load 60(d)
78: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 77
79: 21(fvec4) CompositeConstruct 78 78 78 78
80: 6(float) Load 58(arg2)
81: 21(fvec4) CompositeConstruct 80 80 80 80
82: 21(fvec4) FAdd 79 81
83: 21(fvec4) Load 72(local_highp)
84: 21(fvec4) FAdd 82 83
Store 76(mediumfout) 84
86: 39(int) Load 51(uniform_low)
88: 87(ivec2) CompositeConstruct 86 86
89: 39(int) Load 45(uniform_high)
90: 87(ivec2) CompositeConstruct 89 89
91: 87(ivec2) IMul 88 90
92: 39(int) Load 45(uniform_high)
93: 87(ivec2) CompositeConstruct 92 92
94: 87(ivec2) IAdd 91 93
97: 39(int) CompositeExtract 94 0
98: 39(int) IAdd 85 97
99: 39(int) Load 41(sum)
100: 39(int) IAdd 99 98
Store 41(sum) 100
101: 39(int) Load 41(sum)
102: 6(float) ConvertSToF 101
103: 21(fvec4) CompositeConstruct 102 102 102 102
104: 21(fvec4) Load 76(mediumfout)
105: 21(fvec4) FAdd 104 103
Store 76(mediumfout) 105
109: 15(bvec2) Load 107(ub2)
Store 108(param) 109
110: 14(bool) FunctionCall 19(boolfun(vb2;) 108(param)
SelectionMerge 112 None
BranchConditional 110 111 112
111: Label
113: 21(fvec4) Load 76(mediumfout)
115: 21(fvec4) CompositeConstruct 114 114 114 114
116: 21(fvec4) FAdd 113 115
Store 76(mediumfout) 116
Branch 112
112: Label
121: 61(ptr) AccessChain 119(s) 120
122: 6(float) Load 121
123: 21(fvec4) Load 76(mediumfout)
124: 21(fvec4) VectorTimesScalar 123 122
Store 76(mediumfout) 124
126: 61(ptr) AccessChain 119(s) 125
127: 6(float) Load 126
128: 21(fvec4) Load 76(mediumfout)
129: 21(fvec4) VectorTimesScalar 128 127
Store 76(mediumfout) 129
130: 6(float) Load 64(mediumfin)
131: 6(float) Load 64(mediumfin)
132: 6(float) FMul 130 131
134: 14(bool) FOrdGreaterThan 132 133
SelectionMerge 137 None
BranchConditional 134 136 141
136: Label
139: 21(fvec4) Load 76(mediumfout)
140: 21(fvec4) VectorTimesScalar 139 138
Store 135 140
Branch 137
141: Label
143: 21(fvec4) Load 76(mediumfout)
144: 21(fvec4) VectorTimesScalar 143 142
Store 135 144
Branch 137
137: Label
145: 21(fvec4) Load 135
Store 76(mediumfout) 145
Return
FunctionEnd
12(foo(vf3;): 9(fvec2) Function None 10
11(mv3): 8(ptr) FunctionParameter
13: Label
27: 26(ptr) Variable Function
24: 21(fvec4) Load 23(highfin)
25: 9(fvec2) VectorShuffle 24 24 0 1
ReturnValue 25
Store 27 25
28: 9(fvec2) Load 27
ReturnValue 28
FunctionEnd
19(boolfun(vb2;): 14(bool) Function None 17
18(bv2): 16(ptr) FunctionParameter
20: Label
28: 15(bvec2) Load 18(bv2)
32: 15(bvec2) LogicalEqual 28 31
33: 14(bool) All 32
ReturnValue 33
31: 15(bvec2) Load 18(bv2)
35: 15(bvec2) LogicalEqual 31 34
36: 14(bool) All 35
ReturnValue 36
FunctionEnd