Merge pull request #253 from amdrexu/bugfix2

SPV: Handle matrix's OpFConvert vector by vector.
This commit is contained in:
John Kessenich 2016-05-16 16:49:20 -06:00
commit 7a27de6dd1
3 changed files with 163 additions and 133 deletions

View File

@ -137,7 +137,7 @@ protected:
spv::Id createBinaryMatrixOperation(spv::Op, spv::Decoration precision, spv::Decoration noContraction, spv::Id typeId, spv::Id left, spv::Id right);
spv::Id createUnaryOperation(glslang::TOperator op, spv::Decoration precision, spv::Decoration noContraction, spv::Id typeId, spv::Id operand,glslang::TBasicType typeProxy);
spv::Id createUnaryMatrixOperation(spv::Op, spv::Decoration precision, spv::Decoration noContraction, spv::Id typeId, spv::Id operand,glslang::TBasicType typeProxy);
spv::Id createConversion(glslang::TOperator op, spv::Decoration precision, spv::Id destTypeId, spv::Id operand);
spv::Id createConversion(glslang::TOperator op, spv::Decoration precision, spv::Decoration noContraction, spv::Id destTypeId, spv::Id operand, glslang::TBasicType typeProxy);
spv::Id makeSmearedConstant(spv::Id constant, int vectorSize);
spv::Id createAtomicOperation(glslang::TOperator op, spv::Decoration precision, spv::Id typeId, std::vector<spv::Id>& operands, glslang::TBasicType typeProxy);
spv::Id createInvocationsOperation(glslang::TOperator, spv::Id typeId, spv::Id operand);
@ -1071,7 +1071,7 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI
// it could be a conversion
if (! result)
result = createConversion(node->getOp(), precision, convertGlslangToSpvType(node->getType()), operand);
result = createConversion(node->getOp(), precision, noContraction, convertGlslangToSpvType(node->getType()), operand, node->getOperand()->getBasicType());
// if not, then possibly an operation
if (! result)
@ -3331,7 +3331,7 @@ spv::Id TGlslangToSpvTraverser::createUnaryMatrixOperation(spv::Op op, spv::Deco
return builder.setPrecision(builder.createCompositeConstruct(typeId, results), precision);
}
spv::Id TGlslangToSpvTraverser::createConversion(glslang::TOperator op, spv::Decoration precision, spv::Id destType, spv::Id operand)
spv::Id TGlslangToSpvTraverser::createConversion(glslang::TOperator op, spv::Decoration precision, spv::Decoration noContraction, spv::Id destType, spv::Id operand, glslang::TBasicType typeProxy)
{
spv::Op convOp = spv::OpNop;
spv::Id zero = 0;
@ -3400,6 +3400,8 @@ spv::Id TGlslangToSpvTraverser::createConversion(glslang::TOperator op, spv::Dec
case glslang::EOpConvDoubleToFloat:
case glslang::EOpConvFloatToDouble:
convOp = spv::OpFConvert;
if (builder.isMatrixType(destType))
return createUnaryMatrixOperation(convOp, precision, noContraction, destType, operand, typeProxy);
break;
case glslang::EOpConvFloatToInt:

View File

@ -1,30 +1,34 @@
spv.matrix.frag
Warning, version 420 is not yet complete; most version-specific features are present, but some are missing.
Linked fragment stage:
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 240
// Id's are bound by 261
Capability Shader
Capability Float64
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 12 14 28 140 148 166
EntryPoint Fragment 4 "main" 12 14 28 161 169 187
ExecutionMode 4 OriginUpperLeft
Source GLSL 140
Source GLSL 420
Name 4 "main"
Name 10 "sum34"
Name 12 "m1"
Name 14 "m2"
Name 28 "f"
Name 138 "sum3"
Name 140 "v4"
Name 145 "sum4"
Name 148 "v3"
Name 153 "m43"
Name 158 "m4"
Name 166 "color"
Name 140 "dm"
Name 159 "sum3"
Name 161 "v4"
Name 166 "sum4"
Name 169 "v3"
Name 174 "m43"
Name 179 "m4"
Name 187 "color"
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
@ -37,27 +41,32 @@ Linked fragment stage:
27: TypePointer Input 6(float)
28(f): 27(ptr) Variable Input
81: 6(float) Constant 1065353216
136: TypeVector 6(float) 3
137: TypePointer Function 136(fvec3)
139: TypePointer Input 7(fvec4)
140(v4): 139(ptr) Variable Input
144: TypePointer Function 7(fvec4)
147: TypePointer Input 136(fvec3)
148(v3): 147(ptr) Variable Input
151: TypeMatrix 136(fvec3) 4
152: TypePointer Function 151
156: TypeMatrix 7(fvec4) 4
157: TypePointer Function 156
165: TypePointer Output 7(fvec4)
166(color): 165(ptr) Variable Output
187: 6(float) Constant 0
136: TypeFloat 64
137: TypeVector 136(float) 4
138: TypeMatrix 137(fvec4) 3
139: TypePointer Function 138
157: TypeVector 6(float) 3
158: TypePointer Function 157(fvec3)
160: TypePointer Input 7(fvec4)
161(v4): 160(ptr) Variable Input
165: TypePointer Function 7(fvec4)
168: TypePointer Input 157(fvec3)
169(v3): 168(ptr) Variable Input
172: TypeMatrix 157(fvec3) 4
173: TypePointer Function 172
177: TypeMatrix 7(fvec4) 4
178: TypePointer Function 177
186: TypePointer Output 7(fvec4)
187(color): 186(ptr) Variable Output
208: 6(float) Constant 0
4(main): 2 Function None 3
5: Label
10(sum34): 9(ptr) Variable Function
138(sum3): 137(ptr) Variable Function
145(sum4): 144(ptr) Variable Function
153(m43): 152(ptr) Variable Function
158(m4): 157(ptr) Variable Function
140(dm): 139(ptr) Variable Function
159(sum3): 158(ptr) Variable Function
166(sum4): 165(ptr) Variable Function
174(m43): 173(ptr) Variable Function
179(m4): 178(ptr) Variable Function
13: 8 Load 12(m1)
15: 8 Load 14(m2)
16: 7(fvec4) CompositeExtract 13 0
@ -185,102 +194,120 @@ Linked fragment stage:
134: 7(fvec4) FSub 133 128
135: 8 CompositeConstruct 130 132 134
Store 10(sum34) 135
141: 7(fvec4) Load 140(v4)
142: 8 Load 14(m2)
143: 136(fvec3) VectorTimesMatrix 141 142
Store 138(sum3) 143
146: 8 Load 14(m2)
149: 136(fvec3) Load 148(v3)
150: 7(fvec4) MatrixTimesVector 146 149
Store 145(sum4) 150
154: 8 Load 10(sum34)
155: 151 Transpose 154
Store 153(m43) 155
159: 8 Load 12(m1)
160: 151 Load 153(m43)
161: 156 MatrixTimesMatrix 159 160
Store 158(m4) 161
162: 7(fvec4) Load 140(v4)
163: 156 Load 158(m4)
164: 7(fvec4) VectorTimesMatrix 162 163
Store 145(sum4) 164
167: 7(fvec4) Load 145(sum4)
Store 166(color) 167
168: 8 Load 10(sum34)
169: 7(fvec4) CompositeConstruct 81 81 81 81
170: 7(fvec4) CompositeExtract 168 0
171: 7(fvec4) FAdd 170 169
172: 7(fvec4) CompositeExtract 168 1
173: 7(fvec4) FAdd 172 169
174: 7(fvec4) CompositeExtract 168 2
175: 7(fvec4) FAdd 174 169
176: 8 CompositeConstruct 171 173 175
Store 10(sum34) 176
177: 8 Load 10(sum34)
178: 7(fvec4) CompositeConstruct 81 81 81 81
179: 7(fvec4) CompositeExtract 177 0
180: 7(fvec4) FSub 179 178
181: 7(fvec4) CompositeExtract 177 1
182: 7(fvec4) FSub 181 178
183: 7(fvec4) CompositeExtract 177 2
184: 7(fvec4) FSub 183 178
185: 8 CompositeConstruct 180 182 184
Store 10(sum34) 185
186: 6(float) Load 28(f)
188: 7(fvec4) CompositeConstruct 186 187 187 187
189: 7(fvec4) CompositeConstruct 187 186 187 187
190: 7(fvec4) CompositeConstruct 187 187 186 187
191: 8 CompositeConstruct 188 189 190
192: 8 Load 10(sum34)
193: 7(fvec4) CompositeExtract 192 0
194: 7(fvec4) CompositeExtract 191 0
195: 7(fvec4) FAdd 193 194
196: 7(fvec4) CompositeExtract 192 1
197: 7(fvec4) CompositeExtract 191 1
198: 7(fvec4) FAdd 196 197
199: 7(fvec4) CompositeExtract 192 2
200: 7(fvec4) CompositeExtract 191 2
201: 7(fvec4) FAdd 199 200
202: 8 CompositeConstruct 195 198 201
Store 10(sum34) 202
203: 136(fvec3) Load 148(v3)
204: 6(float) Load 28(f)
205: 136(fvec3) Load 148(v3)
206: 6(float) Load 28(f)
207: 136(fvec3) Load 148(v3)
208: 6(float) Load 28(f)
209: 6(float) CompositeExtract 203 0
210: 6(float) CompositeExtract 203 1
211: 6(float) CompositeExtract 203 2
212: 6(float) CompositeExtract 205 0
213: 6(float) CompositeExtract 205 1
214: 6(float) CompositeExtract 205 2
215: 6(float) CompositeExtract 207 0
216: 6(float) CompositeExtract 207 1
217: 6(float) CompositeExtract 207 2
218: 7(fvec4) CompositeConstruct 209 210 211 204
219: 7(fvec4) CompositeConstruct 212 213 214 206
220: 7(fvec4) CompositeConstruct 215 216 217 208
221: 8 CompositeConstruct 218 219 220
222: 8 Load 10(sum34)
223: 7(fvec4) CompositeExtract 222 0
224: 7(fvec4) CompositeExtract 221 0
225: 7(fvec4) FAdd 223 224
226: 7(fvec4) CompositeExtract 222 1
227: 7(fvec4) CompositeExtract 221 1
228: 7(fvec4) FAdd 226 227
229: 7(fvec4) CompositeExtract 222 2
230: 7(fvec4) CompositeExtract 221 2
231: 7(fvec4) FAdd 229 230
232: 8 CompositeConstruct 225 228 231
Store 10(sum34) 232
233: 136(fvec3) Load 138(sum3)
234: 151 Load 153(m43)
235: 7(fvec4) VectorTimesMatrix 233 234
236: 7(fvec4) Load 145(sum4)
237: 7(fvec4) FAdd 235 236
238: 7(fvec4) Load 166(color)
239: 7(fvec4) FAdd 238 237
Store 166(color) 239
141: 8 Load 10(sum34)
142: 137(fvec4) CompositeExtract 141 0
143: 137(fvec4) FConvert 142
144: 137(fvec4) CompositeExtract 141 1
145: 137(fvec4) FConvert 144
146: 137(fvec4) CompositeExtract 141 2
147: 137(fvec4) FConvert 146
148: 138 CompositeConstruct 143 145 147
Store 140(dm) 148
149: 138 Load 140(dm)
150: 7(fvec4) CompositeExtract 149 0
151: 7(fvec4) FConvert 150
152: 7(fvec4) CompositeExtract 149 1
153: 7(fvec4) FConvert 152
154: 7(fvec4) CompositeExtract 149 2
155: 7(fvec4) FConvert 154
156: 8 CompositeConstruct 151 153 155
Store 10(sum34) 156
162: 7(fvec4) Load 161(v4)
163: 8 Load 14(m2)
164: 157(fvec3) VectorTimesMatrix 162 163
Store 159(sum3) 164
167: 8 Load 14(m2)
170: 157(fvec3) Load 169(v3)
171: 7(fvec4) MatrixTimesVector 167 170
Store 166(sum4) 171
175: 8 Load 10(sum34)
176: 172 Transpose 175
Store 174(m43) 176
180: 8 Load 12(m1)
181: 172 Load 174(m43)
182: 177 MatrixTimesMatrix 180 181
Store 179(m4) 182
183: 7(fvec4) Load 161(v4)
184: 177 Load 179(m4)
185: 7(fvec4) VectorTimesMatrix 183 184
Store 166(sum4) 185
188: 7(fvec4) Load 166(sum4)
Store 187(color) 188
189: 8 Load 10(sum34)
190: 7(fvec4) CompositeConstruct 81 81 81 81
191: 7(fvec4) CompositeExtract 189 0
192: 7(fvec4) FAdd 191 190
193: 7(fvec4) CompositeExtract 189 1
194: 7(fvec4) FAdd 193 190
195: 7(fvec4) CompositeExtract 189 2
196: 7(fvec4) FAdd 195 190
197: 8 CompositeConstruct 192 194 196
Store 10(sum34) 197
198: 8 Load 10(sum34)
199: 7(fvec4) CompositeConstruct 81 81 81 81
200: 7(fvec4) CompositeExtract 198 0
201: 7(fvec4) FSub 200 199
202: 7(fvec4) CompositeExtract 198 1
203: 7(fvec4) FSub 202 199
204: 7(fvec4) CompositeExtract 198 2
205: 7(fvec4) FSub 204 199
206: 8 CompositeConstruct 201 203 205
Store 10(sum34) 206
207: 6(float) Load 28(f)
209: 7(fvec4) CompositeConstruct 207 208 208 208
210: 7(fvec4) CompositeConstruct 208 207 208 208
211: 7(fvec4) CompositeConstruct 208 208 207 208
212: 8 CompositeConstruct 209 210 211
213: 8 Load 10(sum34)
214: 7(fvec4) CompositeExtract 213 0
215: 7(fvec4) CompositeExtract 212 0
216: 7(fvec4) FAdd 214 215
217: 7(fvec4) CompositeExtract 213 1
218: 7(fvec4) CompositeExtract 212 1
219: 7(fvec4) FAdd 217 218
220: 7(fvec4) CompositeExtract 213 2
221: 7(fvec4) CompositeExtract 212 2
222: 7(fvec4) FAdd 220 221
223: 8 CompositeConstruct 216 219 222
Store 10(sum34) 223
224: 157(fvec3) Load 169(v3)
225: 6(float) Load 28(f)
226: 157(fvec3) Load 169(v3)
227: 6(float) Load 28(f)
228: 157(fvec3) Load 169(v3)
229: 6(float) Load 28(f)
230: 6(float) CompositeExtract 224 0
231: 6(float) CompositeExtract 224 1
232: 6(float) CompositeExtract 224 2
233: 6(float) CompositeExtract 226 0
234: 6(float) CompositeExtract 226 1
235: 6(float) CompositeExtract 226 2
236: 6(float) CompositeExtract 228 0
237: 6(float) CompositeExtract 228 1
238: 6(float) CompositeExtract 228 2
239: 7(fvec4) CompositeConstruct 230 231 232 225
240: 7(fvec4) CompositeConstruct 233 234 235 227
241: 7(fvec4) CompositeConstruct 236 237 238 229
242: 8 CompositeConstruct 239 240 241
243: 8 Load 10(sum34)
244: 7(fvec4) CompositeExtract 243 0
245: 7(fvec4) CompositeExtract 242 0
246: 7(fvec4) FAdd 244 245
247: 7(fvec4) CompositeExtract 243 1
248: 7(fvec4) CompositeExtract 242 1
249: 7(fvec4) FAdd 247 248
250: 7(fvec4) CompositeExtract 243 2
251: 7(fvec4) CompositeExtract 242 2
252: 7(fvec4) FAdd 250 251
253: 8 CompositeConstruct 246 249 252
Store 10(sum34) 253
254: 157(fvec3) Load 159(sum3)
255: 172 Load 174(m43)
256: 7(fvec4) VectorTimesMatrix 254 255
257: 7(fvec4) Load 166(sum4)
258: 7(fvec4) FAdd 256 257
259: 7(fvec4) Load 187(color)
260: 7(fvec4) FAdd 259 258
Store 187(color) 260
Return
FunctionEnd

View File

@ -1,4 +1,4 @@
#version 140
#version 420
in mat3x4 m1;
in mat3x4 m2;
@ -11,6 +11,7 @@ out vec4 color;
void main()
{
mat3x4 sum34;
dmat3x4 dm;
vec3 sum3;
vec4 sum4;
@ -22,6 +23,8 @@ void main()
sum34 += f / m1;
sum34 += f;
sum34 -= f;
dm = dmat3x4(sum34);
sum34 = mat3x4(dm);
sum3 = v4 * m2;
sum4 = m2 * v3;
@ -33,10 +36,8 @@ void main()
color = sum4;
//spv if (m1 != sum34)
++sum34;
// else
--sum34;
++sum34;
--sum34;
sum34 += mat3x4(f);
sum34 += mat3x4(v3, f, v3, f, v3, f);