SPV legacy texturing: Smear result of Op*Dref* up to a vector to match

the expectations of old GLSL shadow*() lookups.
This commit is contained in:
John Kessenich 2015-09-14 22:08:12 -06:00
parent e770b3e6cf
commit 7355eebb18
3 changed files with 248 additions and 212 deletions

View File

@ -1214,6 +1214,23 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool fetch, b
}
}
// See if the result type is expecting a smeared result.
// This happens when a legacy shadow*() call is made, which
// gets a vec4 back instead of a float.
Id smearedType = resultType;
if (! isScalarType(resultType)) {
switch (opCode) {
case OpImageSampleDrefImplicitLod:
case OpImageSampleDrefExplicitLod:
case OpImageSampleProjDrefImplicitLod:
case OpImageSampleProjDrefExplicitLod:
resultType = getScalarTypeId(resultType);
break;
default:
break;
}
}
Instruction* textureInst = new Instruction(getUniqueId(), resultType, opCode);
for (int op = 0; op < optArgNum; ++op)
textureInst->addIdOperand(texArgs[op]);
@ -1224,7 +1241,14 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool fetch, b
setPrecision(textureInst->getResultId(), precision);
buildPoint->addInstruction(textureInst);
return textureInst->getResultId();
Id resultId = textureInst->getResultId();
// When a smear is needed, do it, as per what was computed
// above when resultType was changed to a scalar type.
if (resultType != smearedType)
resultId = smearScalar(precision, resultId, smearedType);
return resultId;
}
// Comments in header

View File

@ -8,7 +8,7 @@ Linked fragment stage:
// Module Version 99
// Generated by (magic number): 51a00bb
// Id's are bound by 282
// Id's are bound by 290
Source GLSL 130
Capability Shader
@ -31,21 +31,21 @@ Linked fragment stage:
Name 98 "texSampler3D"
Name 124 "texSamplerCube"
Name 139 "shadowSampler1D"
Name 156 "shadowSampler2D"
Name 199 "iCoords2D"
Name 204 "iLod"
Name 213 "gradX"
Name 216 "gradY"
Name 268 "gl_FragColor"
Name 271 "u"
Name 274 "blend"
Name 280 "scale"
Name 281 "t"
Name 158 "shadowSampler2D"
Name 207 "iCoords2D"
Name 212 "iLod"
Name 221 "gradX"
Name 224 "gradY"
Name 276 "gl_FragColor"
Name 279 "u"
Name 282 "blend"
Name 288 "scale"
Name 289 "t"
Decorate 47(coords2D) Smooth
Decorate 268(gl_FragColor) BuiltIn FragColor
Decorate 280(scale) NoStaticUse
Decorate 281(t) Smooth
Decorate 281(t) NoStaticUse
Decorate 276(gl_FragColor) BuiltIn FragColor
Decorate 288(scale) NoStaticUse
Decorate 289(t) Smooth
Decorate 289(t) NoStaticUse
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
@ -86,31 +86,31 @@ Linked fragment stage:
137: TypeSampledImage 136
138: TypePointer UniformConstant 137
139(shadowSampler1D): 138(ptr) Variable UniformConstant
153: TypeImage 6(float) 2D depth sampled format:Unknown
154: TypeSampledImage 153
155: TypePointer UniformConstant 154
156(shadowSampler2D): 155(ptr) Variable UniformConstant
196: TypeInt 32 1
197: TypeVector 196(int) 2
198: TypePointer Function 197(ivec2)
200: 196(int) Constant 0
201: 196(int) Constant 5
202: 197(ivec2) ConstantComposite 200 201
203: TypePointer Function 196(int)
205: 196(int) Constant 1
212: TypePointer Function 45(fvec2)
241: 196(int) Constant 3
242: 196(int) Constant 4294967289
243: 197(ivec2) ConstantComposite 241 242
267: TypePointer Output 22(fvec4)
268(gl_FragColor): 267(ptr) Variable Output
270: TypePointer UniformConstant 22(fvec4)
271(u): 270(ptr) Variable UniformConstant
273: TypePointer UniformConstant 6(float)
274(blend): 273(ptr) Variable UniformConstant
279: TypePointer UniformConstant 45(fvec2)
280(scale): 279(ptr) Variable UniformConstant
281(t): 46(ptr) Variable Input
155: TypeImage 6(float) 2D depth sampled format:Unknown
156: TypeSampledImage 155
157: TypePointer UniformConstant 156
158(shadowSampler2D): 157(ptr) Variable UniformConstant
204: TypeInt 32 1
205: TypeVector 204(int) 2
206: TypePointer Function 205(ivec2)
208: 204(int) Constant 0
209: 204(int) Constant 5
210: 205(ivec2) ConstantComposite 208 209
211: TypePointer Function 204(int)
213: 204(int) Constant 1
220: TypePointer Function 45(fvec2)
249: 204(int) Constant 3
250: 204(int) Constant 4294967289
251: 205(ivec2) ConstantComposite 249 250
275: TypePointer Output 22(fvec4)
276(gl_FragColor): 275(ptr) Variable Output
278: TypePointer UniformConstant 22(fvec4)
279(u): 278(ptr) Variable UniformConstant
281: TypePointer UniformConstant 6(float)
282(blend): 281(ptr) Variable UniformConstant
287: TypePointer UniformConstant 45(fvec2)
288(scale): 287(ptr) Variable UniformConstant
289(t): 46(ptr) Variable Input
4(main): 2 Function None 3
5: Label
8(blendscale): 7(ptr) Variable Function
@ -121,10 +121,10 @@ Linked fragment stage:
18(coords3D): 17(ptr) Variable Function
24(coords4D): 23(ptr) Variable Function
26(color): 23(ptr) Variable Function
199(iCoords2D): 198(ptr) Variable Function
204(iLod): 203(ptr) Variable Function
213(gradX): 212(ptr) Variable Function
216(gradY): 212(ptr) Variable Function
207(iCoords2D): 206(ptr) Variable Function
212(iLod): 211(ptr) Variable Function
221(gradX): 220(ptr) Variable Function
224(gradY): 220(ptr) Variable Function
Store 8(blendscale) 9
Store 10(bias) 11
Store 12(lod) 13
@ -240,134 +240,142 @@ Linked fragment stage:
140: 137 Load 139(shadowSampler1D)
141: 16(fvec3) Load 18(coords3D)
142: 6(float) CompositeExtract 141 2
143: 22(fvec4) ImageSampleDrefImplicitLod 140 141 142
144: 22(fvec4) Load 26(color)
145: 22(fvec4) FAdd 144 143
Store 26(color) 145
146: 137 Load 139(shadowSampler1D)
147: 16(fvec3) Load 18(coords3D)
148: 6(float) Load 10(bias)
149: 6(float) CompositeExtract 147 2
150: 22(fvec4) ImageSampleDrefImplicitLod 146 147 149 148
151: 22(fvec4) Load 26(color)
152: 22(fvec4) FAdd 151 150
Store 26(color) 152
157: 154 Load 156(shadowSampler2D)
158: 16(fvec3) Load 18(coords3D)
159: 6(float) CompositeExtract 158 2
160: 22(fvec4) ImageSampleDrefImplicitLod 157 158 159
161: 22(fvec4) Load 26(color)
162: 22(fvec4) FAdd 161 160
Store 26(color) 162
163: 154 Load 156(shadowSampler2D)
164: 16(fvec3) Load 18(coords3D)
165: 6(float) Load 10(bias)
166: 6(float) CompositeExtract 164 2
167: 22(fvec4) ImageSampleDrefImplicitLod 163 164 166 165
168: 22(fvec4) Load 26(color)
169: 22(fvec4) FAdd 168 167
Store 26(color) 169
170: 137 Load 139(shadowSampler1D)
171: 22(fvec4) Load 24(coords4D)
172: 6(float) CompositeExtract 171 3
173: 22(fvec4) ImageSampleProjDrefImplicitLod 170 171 172
174: 22(fvec4) Load 26(color)
175: 22(fvec4) FAdd 174 173
Store 26(color) 175
176: 137 Load 139(shadowSampler1D)
177: 22(fvec4) Load 24(coords4D)
178: 6(float) Load 10(bias)
179: 6(float) CompositeExtract 177 3
180: 22(fvec4) ImageSampleProjDrefImplicitLod 176 177 179 178
181: 22(fvec4) Load 26(color)
182: 22(fvec4) FAdd 181 180
Store 26(color) 182
183: 154 Load 156(shadowSampler2D)
184: 22(fvec4) Load 24(coords4D)
185: 6(float) CompositeExtract 184 3
186: 22(fvec4) ImageSampleProjDrefImplicitLod 183 184 185
143: 6(float) ImageSampleDrefImplicitLod 140 141 142
144: 22(fvec4) CompositeConstruct 143 143 143 143
145: 22(fvec4) Load 26(color)
146: 22(fvec4) FAdd 145 144
Store 26(color) 146
147: 137 Load 139(shadowSampler1D)
148: 16(fvec3) Load 18(coords3D)
149: 6(float) Load 10(bias)
150: 6(float) CompositeExtract 148 2
151: 6(float) ImageSampleDrefImplicitLod 147 148 150 149
152: 22(fvec4) CompositeConstruct 151 151 151 151
153: 22(fvec4) Load 26(color)
154: 22(fvec4) FAdd 153 152
Store 26(color) 154
159: 156 Load 158(shadowSampler2D)
160: 16(fvec3) Load 18(coords3D)
161: 6(float) CompositeExtract 160 2
162: 6(float) ImageSampleDrefImplicitLod 159 160 161
163: 22(fvec4) CompositeConstruct 162 162 162 162
164: 22(fvec4) Load 26(color)
165: 22(fvec4) FAdd 164 163
Store 26(color) 165
166: 156 Load 158(shadowSampler2D)
167: 16(fvec3) Load 18(coords3D)
168: 6(float) Load 10(bias)
169: 6(float) CompositeExtract 167 2
170: 6(float) ImageSampleDrefImplicitLod 166 167 169 168
171: 22(fvec4) CompositeConstruct 170 170 170 170
172: 22(fvec4) Load 26(color)
173: 22(fvec4) FAdd 172 171
Store 26(color) 173
174: 137 Load 139(shadowSampler1D)
175: 22(fvec4) Load 24(coords4D)
176: 6(float) CompositeExtract 175 3
177: 6(float) ImageSampleProjDrefImplicitLod 174 175 176
178: 22(fvec4) CompositeConstruct 177 177 177 177
179: 22(fvec4) Load 26(color)
180: 22(fvec4) FAdd 179 178
Store 26(color) 180
181: 137 Load 139(shadowSampler1D)
182: 22(fvec4) Load 24(coords4D)
183: 6(float) Load 10(bias)
184: 6(float) CompositeExtract 182 3
185: 6(float) ImageSampleProjDrefImplicitLod 181 182 184 183
186: 22(fvec4) CompositeConstruct 185 185 185 185
187: 22(fvec4) Load 26(color)
188: 22(fvec4) FAdd 187 186
Store 26(color) 188
189: 154 Load 156(shadowSampler2D)
189: 156 Load 158(shadowSampler2D)
190: 22(fvec4) Load 24(coords4D)
191: 6(float) Load 10(bias)
192: 6(float) CompositeExtract 190 3
193: 22(fvec4) ImageSampleProjDrefImplicitLod 189 190 192 191
191: 6(float) CompositeExtract 190 3
192: 6(float) ImageSampleProjDrefImplicitLod 189 190 191
193: 22(fvec4) CompositeConstruct 192 192 192 192
194: 22(fvec4) Load 26(color)
195: 22(fvec4) FAdd 194 193
Store 26(color) 195
Store 199(iCoords2D) 202
Store 204(iLod) 205
206: 70 Load 72(texSampler2D)
207: 197(ivec2) Load 199(iCoords2D)
208: 196(int) Load 204(iLod)
209: 22(fvec4) ImageFetch 206 207
210: 22(fvec4) Load 26(color)
211: 22(fvec4) FAdd 210 209
Store 26(color) 211
214: 45(fvec2) Load 47(coords2D)
215: 45(fvec2) DPdx 214
Store 213(gradX) 215
217: 45(fvec2) Load 47(coords2D)
218: 45(fvec2) DPdy 217
Store 216(gradY) 218
219: 70 Load 72(texSampler2D)
220: 45(fvec2) Load 47(coords2D)
221: 45(fvec2) Load 213(gradX)
222: 45(fvec2) Load 216(gradY)
223: 22(fvec4) ImageSampleExplicitLod 219 220 221 222
224: 22(fvec4) Load 26(color)
225: 22(fvec4) FAdd 224 223
Store 26(color) 225
226: 70 Load 72(texSampler2D)
227: 45(fvec2) Load 47(coords2D)
228: 6(float) Load 14(proj)
229: 6(float) CompositeExtract 227 0
230: 6(float) CompositeExtract 227 1
231: 16(fvec3) CompositeConstruct 229 230 228
232: 45(fvec2) Load 213(gradX)
233: 45(fvec2) Load 216(gradY)
234: 22(fvec4) ImageSampleProjExplicitLod 226 231 232 233
235: 22(fvec4) Load 26(color)
236: 22(fvec4) FAdd 235 234
Store 26(color) 236
237: 70 Load 72(texSampler2D)
238: 45(fvec2) Load 47(coords2D)
239: 45(fvec2) Load 213(gradX)
240: 45(fvec2) Load 216(gradY)
244: 22(fvec4) ImageSampleExplicitLod 237 238 239 240 243
245: 22(fvec4) Load 26(color)
246: 22(fvec4) FAdd 245 244
Store 26(color) 246
247: 70 Load 72(texSampler2D)
248: 16(fvec3) Load 18(coords3D)
249: 45(fvec2) Load 213(gradX)
250: 45(fvec2) Load 216(gradY)
251: 22(fvec4) ImageSampleProjExplicitLod 247 248 249 250 243
252: 22(fvec4) Load 26(color)
253: 22(fvec4) FAdd 252 251
Store 26(color) 253
254: 154 Load 156(shadowSampler2D)
255: 45(fvec2) Load 47(coords2D)
256: 6(float) Load 12(lod)
257: 6(float) CompositeExtract 255 0
258: 6(float) CompositeExtract 255 1
259: 16(fvec3) CompositeConstruct 257 258 256
260: 45(fvec2) Load 213(gradX)
261: 45(fvec2) Load 216(gradY)
262: 6(float) CompositeExtract 259 2
263: 6(float) ImageSampleDrefExplicitLod 254 259 262 260 261
264: 22(fvec4) Load 26(color)
265: 22(fvec4) CompositeConstruct 263 263 263 263
266: 22(fvec4) FAdd 264 265
Store 26(color) 266
269: 22(fvec4) Load 26(color)
272: 22(fvec4) Load 271(u)
275: 6(float) Load 274(blend)
276: 6(float) Load 8(blendscale)
277: 6(float) FMul 275 276
278: 22(fvec4) ExtInst 1(GLSL.std.450) 46(Mix) 269 272 277
Store 268(gl_FragColor) 278
196: 156 Load 158(shadowSampler2D)
197: 22(fvec4) Load 24(coords4D)
198: 6(float) Load 10(bias)
199: 6(float) CompositeExtract 197 3
200: 6(float) ImageSampleProjDrefImplicitLod 196 197 199 198
201: 22(fvec4) CompositeConstruct 200 200 200 200
202: 22(fvec4) Load 26(color)
203: 22(fvec4) FAdd 202 201
Store 26(color) 203
Store 207(iCoords2D) 210
Store 212(iLod) 213
214: 70 Load 72(texSampler2D)
215: 205(ivec2) Load 207(iCoords2D)
216: 204(int) Load 212(iLod)
217: 22(fvec4) ImageFetch 214 215
218: 22(fvec4) Load 26(color)
219: 22(fvec4) FAdd 218 217
Store 26(color) 219
222: 45(fvec2) Load 47(coords2D)
223: 45(fvec2) DPdx 222
Store 221(gradX) 223
225: 45(fvec2) Load 47(coords2D)
226: 45(fvec2) DPdy 225
Store 224(gradY) 226
227: 70 Load 72(texSampler2D)
228: 45(fvec2) Load 47(coords2D)
229: 45(fvec2) Load 221(gradX)
230: 45(fvec2) Load 224(gradY)
231: 22(fvec4) ImageSampleExplicitLod 227 228 229 230
232: 22(fvec4) Load 26(color)
233: 22(fvec4) FAdd 232 231
Store 26(color) 233
234: 70 Load 72(texSampler2D)
235: 45(fvec2) Load 47(coords2D)
236: 6(float) Load 14(proj)
237: 6(float) CompositeExtract 235 0
238: 6(float) CompositeExtract 235 1
239: 16(fvec3) CompositeConstruct 237 238 236
240: 45(fvec2) Load 221(gradX)
241: 45(fvec2) Load 224(gradY)
242: 22(fvec4) ImageSampleProjExplicitLod 234 239 240 241
243: 22(fvec4) Load 26(color)
244: 22(fvec4) FAdd 243 242
Store 26(color) 244
245: 70 Load 72(texSampler2D)
246: 45(fvec2) Load 47(coords2D)
247: 45(fvec2) Load 221(gradX)
248: 45(fvec2) Load 224(gradY)
252: 22(fvec4) ImageSampleExplicitLod 245 246 247 248 251
253: 22(fvec4) Load 26(color)
254: 22(fvec4) FAdd 253 252
Store 26(color) 254
255: 70 Load 72(texSampler2D)
256: 16(fvec3) Load 18(coords3D)
257: 45(fvec2) Load 221(gradX)
258: 45(fvec2) Load 224(gradY)
259: 22(fvec4) ImageSampleProjExplicitLod 255 256 257 258 251
260: 22(fvec4) Load 26(color)
261: 22(fvec4) FAdd 260 259
Store 26(color) 261
262: 156 Load 158(shadowSampler2D)
263: 45(fvec2) Load 47(coords2D)
264: 6(float) Load 12(lod)
265: 6(float) CompositeExtract 263 0
266: 6(float) CompositeExtract 263 1
267: 16(fvec3) CompositeConstruct 265 266 264
268: 45(fvec2) Load 221(gradX)
269: 45(fvec2) Load 224(gradY)
270: 6(float) CompositeExtract 267 2
271: 6(float) ImageSampleDrefExplicitLod 262 267 270 268 269
272: 22(fvec4) Load 26(color)
273: 22(fvec4) CompositeConstruct 271 271 271 271
274: 22(fvec4) FAdd 272 273
Store 26(color) 274
277: 22(fvec4) Load 26(color)
280: 22(fvec4) Load 279(u)
283: 6(float) Load 282(blend)
284: 6(float) Load 8(blendscale)
285: 6(float) FMul 283 284
286: 22(fvec4) ExtInst 1(GLSL.std.450) 46(Mix) 277 280 285
Store 276(gl_FragColor) 286
Return
FunctionEnd

View File

@ -5,7 +5,7 @@ Linked vertex stage:
// Module Version 99
// Generated by (magic number): 51a00bb
// Id's are bound by 141
// Id's are bound by 145
Source GLSL 130
Capability Shader
@ -24,12 +24,12 @@ Linked vertex stage:
Name 76 "texSampler3D"
Name 92 "texSamplerCube"
Name 102 "shadowSampler1D"
Name 113 "shadowSampler2D"
Name 136 "gl_Position"
Name 140 "gl_VertexID"
Decorate 136(gl_Position) BuiltIn Position
Decorate 140(gl_VertexID) BuiltIn VertexId
Decorate 140(gl_VertexID) NoStaticUse
Name 114 "shadowSampler2D"
Name 140 "gl_Position"
Name 144 "gl_VertexID"
Decorate 140(gl_Position) BuiltIn Position
Decorate 144(gl_VertexID) BuiltIn VertexId
Decorate 144(gl_VertexID) NoStaticUse
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
@ -70,15 +70,15 @@ Linked vertex stage:
100: TypeSampledImage 99
101: TypePointer UniformConstant 100
102(shadowSampler1D): 101(ptr) Variable UniformConstant
110: TypeImage 6(float) 2D depth sampled format:Unknown
111: TypeSampledImage 110
112: TypePointer UniformConstant 111
113(shadowSampler2D): 112(ptr) Variable UniformConstant
135: TypePointer Output 18(fvec4)
136(gl_Position): 135(ptr) Variable Output
138: TypeInt 32 1
139: TypePointer Input 138(int)
140(gl_VertexID): 139(ptr) Variable Input
111: TypeImage 6(float) 2D depth sampled format:Unknown
112: TypeSampledImage 111
113: TypePointer UniformConstant 112
114(shadowSampler2D): 113(ptr) Variable UniformConstant
139: TypePointer Output 18(fvec4)
140(gl_Position): 139(ptr) Variable Output
142: TypeInt 32 1
143: TypePointer Input 142(int)
144(gl_VertexID): 143(ptr) Variable Input
4(main): 2 Function None 3
5: Label
8(lod): 7(ptr) Variable Function
@ -158,35 +158,39 @@ Linked vertex stage:
104: 12(fvec3) Load 14(coords3D)
105: 6(float) Load 8(lod)
106: 6(float) CompositeExtract 104 2
107: 18(fvec4) ImageSampleDrefExplicitLod 103 104 106 105
108: 18(fvec4) Load 23(color)
109: 18(fvec4) FAdd 108 107
Store 23(color) 109
114: 111 Load 113(shadowSampler2D)
115: 12(fvec3) Load 14(coords3D)
116: 6(float) Load 8(lod)
117: 6(float) CompositeExtract 115 2
118: 18(fvec4) ImageSampleDrefExplicitLod 114 115 117 116
119: 18(fvec4) Load 23(color)
120: 18(fvec4) FAdd 119 118
Store 23(color) 120
121: 100 Load 102(shadowSampler1D)
122: 18(fvec4) Load 20(coords4D)
123: 6(float) Load 8(lod)
124: 6(float) CompositeExtract 122 3
125: 18(fvec4) ImageSampleProjDrefExplicitLod 121 122 124 123
126: 18(fvec4) Load 23(color)
127: 18(fvec4) FAdd 126 125
Store 23(color) 127
128: 111 Load 113(shadowSampler2D)
129: 18(fvec4) Load 20(coords4D)
130: 6(float) Load 8(lod)
131: 6(float) CompositeExtract 129 3
132: 18(fvec4) ImageSampleProjDrefExplicitLod 128 129 131 130
133: 18(fvec4) Load 23(color)
134: 18(fvec4) FAdd 133 132
Store 23(color) 134
107: 6(float) ImageSampleDrefExplicitLod 103 104 106 105
108: 18(fvec4) CompositeConstruct 107 107 107 107
109: 18(fvec4) Load 23(color)
110: 18(fvec4) FAdd 109 108
Store 23(color) 110
115: 112 Load 114(shadowSampler2D)
116: 12(fvec3) Load 14(coords3D)
117: 6(float) Load 8(lod)
118: 6(float) CompositeExtract 116 2
119: 6(float) ImageSampleDrefExplicitLod 115 116 118 117
120: 18(fvec4) CompositeConstruct 119 119 119 119
121: 18(fvec4) Load 23(color)
122: 18(fvec4) FAdd 121 120
Store 23(color) 122
123: 100 Load 102(shadowSampler1D)
124: 18(fvec4) Load 20(coords4D)
125: 6(float) Load 8(lod)
126: 6(float) CompositeExtract 124 3
127: 6(float) ImageSampleProjDrefExplicitLod 123 124 126 125
128: 18(fvec4) CompositeConstruct 127 127 127 127
129: 18(fvec4) Load 23(color)
130: 18(fvec4) FAdd 129 128
Store 23(color) 130
131: 112 Load 114(shadowSampler2D)
132: 18(fvec4) Load 20(coords4D)
133: 6(float) Load 8(lod)
134: 6(float) CompositeExtract 132 3
135: 6(float) ImageSampleProjDrefExplicitLod 131 132 134 133
136: 18(fvec4) CompositeConstruct 135 135 135 135
137: 18(fvec4) Load 23(color)
Store 136(gl_Position) 137
138: 18(fvec4) FAdd 137 136
Store 23(color) 138
141: 18(fvec4) Load 23(color)
Store 140(gl_Position) 141
Return
FunctionEnd