Approach: Add a flag in `Builder` to indicate 'spec constant mode' and 'normal mode'. When the builder is in 'normal mode', nothing changed. When the builder is in 'spec constant mode', binary, unary and other instruction creation rountines will be redirected to `createSpecConstantOp()` to create instrution at module level with `OpSpecConstantOp <original opcode> <operands>`. 'spec constant mode' should be enabled if and only if we are creating spec constants. So a flager setter/recover guard is added when handling binary/unary nodes in `createSpvConstantsFromConstSubTree()`. Note when handling spec constants which are represented as ConstantUnion Node, we should not use `OpSpecConstantOp` to initialize the composite constant, so builder is set to 'normal mode'. Tests: Tests are added in Test/spv.specConstantOperations.vert, including: 1) Arithmetic, shift opeations for both scalar and composite type spec constants. 2) Size conversion from/to float and double for both scalar and vector. 3) Bitwise and/or/xor for both scalar and vector. 4) Unary negate/not for both scalar and vector. 5) Vector swizzles. 6) Comparisons for scalars. 7) == and != for composite type spec constants Issues: 1) To implement == and != for composite type spec constants, the Spec needs to allow OpAll, OpAny, OpFOrdEqual, OpFUnordEqual, OpOrdNotEqual, OpFUnordNotEqual. Currently none of them are allowed in the Spec.
192 lines
9.8 KiB
Plaintext
192 lines
9.8 KiB
Plaintext
spv.specConstantOperations.vert
|
|
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
|
|
|
|
|
|
Linked vertex stage:
|
|
|
|
|
|
// Module Version 10000
|
|
// Generated by (magic number): 80001
|
|
// Id's are bound by 163
|
|
|
|
Capability Shader
|
|
Capability Kernel
|
|
Capability Float64
|
|
1: ExtInstImport "GLSL.std.450"
|
|
MemoryModel Logical GLSL450
|
|
EntryPoint Vertex 4 "main"
|
|
Source GLSL 450
|
|
Name 4 "main"
|
|
Name 108 "int_float_double_vec2"
|
|
MemberName 108(int_float_double_vec2) 0 "i"
|
|
MemberName 108(int_float_double_vec2) 1 "f"
|
|
MemberName 108(int_float_double_vec2) 2 "d"
|
|
MemberName 108(int_float_double_vec2) 3 "v"
|
|
Decorate 7 SpecId 200
|
|
Decorate 9 SpecId 201
|
|
Decorate 11 SpecId 202
|
|
Decorate 12 SpecId 203
|
|
2: TypeVoid
|
|
3: TypeFunction 2
|
|
6: TypeFloat 32
|
|
7: 6(float) SpecConstant 1078530010
|
|
8: TypeInt 32 1
|
|
9: 8(int) SpecConstant 10
|
|
10: TypeInt 32 0
|
|
11: 10(int) SpecConstant 100
|
|
12: 8(int) SpecConstant 4294967286
|
|
13: TypeFloat 64
|
|
14: 13(float) SpecConstantOp 115 7
|
|
15: 6(float) SpecConstantOp 115 14
|
|
16: 8(int) SpecConstantOp 126 9
|
|
17: 8(int) SpecConstantOp 200 9
|
|
18: 8(int) Constant 2
|
|
19: 8(int) SpecConstantOp 128 9 18
|
|
20: 8(int) SpecConstantOp 128 9 18
|
|
21: 8(int) Constant 3
|
|
22: 8(int) SpecConstantOp 130 20 21
|
|
23: 8(int) Constant 4
|
|
24: 8(int) SpecConstantOp 130 19 23
|
|
25: 8(int) SpecConstantOp 132 12 18
|
|
26: 10(int) Constant 2
|
|
27: 10(int) SpecConstantOp 132 11 26
|
|
28: 8(int) Constant 5
|
|
29: 8(int) SpecConstantOp 135 25 28
|
|
30: 10(int) Constant 5
|
|
31: 10(int) SpecConstantOp 134 27 30
|
|
32: 8(int) SpecConstantOp 139 12 23
|
|
33: 10(int) Constant 4
|
|
34: 10(int) SpecConstantOp 137 11 33
|
|
35: 8(int) SpecConstantOp 132 12 21
|
|
36: 8(int) SpecConstantOp 135 35 28
|
|
37: 8(int) Constant 10
|
|
38: 8(int) SpecConstantOp 195 12 37
|
|
39: 8(int) Constant 20
|
|
40: 10(int) SpecConstantOp 194 11 39
|
|
41: 8(int) Constant 1
|
|
42: 8(int) SpecConstantOp 196 12 41
|
|
43: 10(int) SpecConstantOp 196 11 18
|
|
44: 8(int) Constant 256
|
|
45: 8(int) SpecConstantOp 197 12 44
|
|
46: 10(int) Constant 512
|
|
47: 10(int) SpecConstantOp 198 11 46
|
|
48: 8(int) SpecConstantOp 124 11
|
|
49: 8(int) SpecConstantOp 199 12 48
|
|
50: TypeBool
|
|
51: 50(bool) SpecConstantOp 177 9 12
|
|
52: 10(int) SpecConstantOp 124 12
|
|
53: 50(bool) SpecConstantOp 176 11 52
|
|
54: 10(int) SpecConstantOp 124 12
|
|
55: 50(bool) SpecConstantOp 176 54 11
|
|
56: TypeVector 8(int) 4
|
|
57: 8(int) Constant 30
|
|
58: 56(ivec4) SpecConstantComposite 39 57 9 9
|
|
59: TypeVector 10(int) 4
|
|
60: 10(int) Constant 4294967295
|
|
61: 10(int) Constant 4294967294
|
|
62: 59(ivec4) SpecConstantComposite 11 11 60 61
|
|
63: TypeVector 6(float) 4
|
|
64: 6(float) Constant 1067450368
|
|
65: 63(fvec4) SpecConstantComposite 7 64 7 64
|
|
66: TypeVector 13(float) 4
|
|
67: 66(fvec4) SpecConstantOp 115 65
|
|
68: 63(fvec4) SpecConstantOp 115 67
|
|
69: 56(ivec4) SpecConstantOp 200 58
|
|
70: 63(fvec4) SpecConstantOp 111 69
|
|
71: 56(ivec4) SpecConstantOp 126 58
|
|
72: 56(ivec4) ConstantComposite 18 18 18 18
|
|
73: 56(ivec4) SpecConstantOp 128 58 72
|
|
74: 56(ivec4) SpecConstantOp 128 58 72
|
|
75: 56(ivec4) ConstantComposite 21 21 21 21
|
|
76: 56(ivec4) SpecConstantOp 130 74 75
|
|
77: 56(ivec4) ConstantComposite 23 23 23 23
|
|
78: 56(ivec4) SpecConstantOp 130 76 77
|
|
79: 56(ivec4) SpecConstantOp 132 58 72
|
|
80: 56(ivec4) ConstantComposite 28 28 28 28
|
|
81: 56(ivec4) SpecConstantOp 135 79 80
|
|
82: 56(ivec4) SpecConstantOp 139 58 77
|
|
83: 56(ivec4) ConstantComposite 37 37 37 37
|
|
84: 56(ivec4) SpecConstantOp 195 58 83
|
|
85: 56(ivec4) SpecConstantOp 196 58 72
|
|
86: 8(int) Constant 1024
|
|
87: 56(ivec4) ConstantComposite 86 86 86 86
|
|
88: 56(ivec4) SpecConstantOp 197 58 87
|
|
89: 10(int) Constant 2048
|
|
90: 59(ivec4) ConstantComposite 89 89 89 89
|
|
91: 59(ivec4) SpecConstantOp 198 62 90
|
|
92: 56(ivec4) SpecConstantOp 124 62
|
|
93: 56(ivec4) SpecConstantOp 199 58 92
|
|
94: 10(int) Constant 0
|
|
95: 8(int) SpecConstantOp 81 58 0
|
|
96: TypeVector 8(int) 2
|
|
97: 96(ivec2) SpecConstantOp 79 58 58 1(GLSL.std.450) 0
|
|
98: TypeVector 8(int) 3
|
|
99: 98(ivec3) SpecConstantOp 79 58 58 2 1(GLSL.std.450) 0
|
|
100: 56(ivec4) SpecConstantOp 79 58 58 1(GLSL.std.450) 2 0 3
|
|
101: 59(ivec4) SpecConstantOp 124 58
|
|
102: TypeVector 50(bool) 4
|
|
103: 102(bvec4) SpecConstantOp 170 101 62
|
|
104: 50(bool) SpecConstantOp 155 103
|
|
105: 59(ivec4) SpecConstantOp 124 58
|
|
106: 50(bool) SpecConstantOp 154 0
|
|
107: TypeVector 6(float) 2
|
|
108(int_float_double_vec2): TypeStruct 8(int) 6(float) 13(float) 107(fvec2)
|
|
109: 6(float) Constant 1065353216
|
|
110: 107(fvec2) SpecConstantComposite 15 109
|
|
111:108(int_float_double_vec2) SpecConstantComposite 9 7 14 110
|
|
112: 107(fvec2) SpecConstantComposite 15 109
|
|
113:108(int_float_double_vec2) SpecConstantComposite 9 7 14 112
|
|
114: 8(int) SpecConstantOp 81 111 0
|
|
115: 8(int) SpecConstantOp 81 113 0
|
|
116: 50(bool) SpecConstantOp 170 114 115
|
|
117: 6(float) SpecConstantOp 81 111 1(GLSL.std.450)
|
|
118: 6(float) SpecConstantOp 81 113 1(GLSL.std.450)
|
|
119: 50(bool) SpecConstantOp 180 117 118
|
|
120: 50(bool) SpecConstantOp 167 116 119
|
|
121: 13(float) SpecConstantOp 81 111 2
|
|
122: 13(float) SpecConstantOp 81 113 2
|
|
123: 50(bool) SpecConstantOp 180 121 122
|
|
124: 50(bool) SpecConstantOp 167 120 123
|
|
125: 107(fvec2) SpecConstantOp 81 111 3
|
|
126: 107(fvec2) SpecConstantOp 81 113 3
|
|
127: TypeVector 50(bool) 2
|
|
128: 127(bvec2) SpecConstantOp 180 125 126
|
|
129: 50(bool) SpecConstantOp 155 128
|
|
130: 50(bool) SpecConstantOp 167 124 129
|
|
131: 8(int) SpecConstantOp 81 111 0
|
|
132: 8(int) SpecConstantOp 81 113 0
|
|
133: 6(float) SpecConstantOp 81 111 1(GLSL.std.450)
|
|
134: 6(float) SpecConstantOp 81 113 1(GLSL.std.450)
|
|
135: 50(bool) SpecConstantOp 182 133 134
|
|
136: 50(bool) SpecConstantOp 166 0 135
|
|
137: 13(float) SpecConstantOp 81 111 2
|
|
138: 13(float) SpecConstantOp 81 113 2
|
|
139: 50(bool) SpecConstantOp 182 137 138
|
|
140: 50(bool) SpecConstantOp 166 136 139
|
|
141: 107(fvec2) SpecConstantOp 81 111 3
|
|
142: 107(fvec2) SpecConstantOp 81 113 3
|
|
143: 127(bvec2) SpecConstantOp 182 141 142
|
|
144: 50(bool) SpecConstantOp 154 143
|
|
145: 50(bool) SpecConstantOp 166 140 144
|
|
146: TypeArray 6(float) 26
|
|
147: 146 SpecConstantComposite 7 7
|
|
148: 146 SpecConstantComposite 7 7
|
|
149: 6(float) SpecConstantOp 81 147 0
|
|
150: 6(float) SpecConstantOp 81 148 0
|
|
151: 50(bool) SpecConstantOp 180 149 150
|
|
152: 6(float) SpecConstantOp 81 147 1(GLSL.std.450)
|
|
153: 6(float) SpecConstantOp 81 148 1(GLSL.std.450)
|
|
154: 50(bool) SpecConstantOp 180 152 153
|
|
155: 50(bool) SpecConstantOp 167 151 154
|
|
156: 6(float) SpecConstantOp 81 147 0
|
|
157: 6(float) SpecConstantOp 81 148 0
|
|
158: 50(bool) SpecConstantOp 182 156 157
|
|
159: 6(float) SpecConstantOp 81 147 1(GLSL.std.450)
|
|
160: 6(float) SpecConstantOp 81 148 1(GLSL.std.450)
|
|
161: 50(bool) SpecConstantOp 182 159 160
|
|
162: 50(bool) SpecConstantOp 166 158 161
|
|
4(main): 2 Function None 3
|
|
5: Label
|
|
Return
|
|
FunctionEnd
|