@@ -189,18 +189,19 @@ enum class DimType
189
189
Count,
190
190
};
191
191
192
- // The WGSL texture attribute types for 'expr' are unsigned int, and anything else requires a conversion.
193
- template <typename S>
192
+ // The WGSL texture attribute types for 'expr' are unsigned int, and anything else requires a
193
+ // conversion.
194
+ template <typename S>
194
195
static String wgslTextureAttributeConversion (DimType type, S expr)
195
196
{
196
197
197
- switch (type)
198
+ switch (type)
198
199
{
199
-
200
+
200
201
case DimType::UInt:
201
202
return expr;
202
-
203
-
203
+
204
+
204
205
case DimType::Float:
205
206
{
206
207
// Conversion to float is exact for values <= 2^24.
@@ -213,8 +214,8 @@ static String wgslTextureAttributeConversion(DimType type, S expr)
213
214
214
215
case DimType::Int:
215
216
{
216
- // We can assume two's complement and just do a bitcast, since texture dimensions can't be
217
- // anywhere near big enough to yield a negative result.
217
+ // We can assume two's complement and just do a bitcast, since texture dimensions can't
218
+ // be anywhere near big enough to yield a negative result.
218
219
String castExpr (" bitcast<i32>(" );
219
220
castExpr.append (expr);
220
221
castExpr.append (" )" );
@@ -225,9 +226,7 @@ static String wgslTextureAttributeConversion(DimType type, S expr)
225
226
default :
226
227
SLANG_UNREACHABLE (" Unexpected DimType enum value" );
227
228
break ;
228
-
229
229
};
230
-
231
230
}
232
231
233
232
void TextureTypeInfo::writeGetDimensionFunctions ()
@@ -278,8 +277,11 @@ void TextureTypeInfo::writeGetDimensionFunctions()
278
277
params << t << " width" ;
279
278
metal << " (*($" << String (paramCount) << " ) = $0.get_width("
280
279
<< String (metalMipLevel) << " ))," ;
281
- wgsl << " ($" << String (paramCount) << " ) = " <<
282
- wgslTextureAttributeConversion (dimType, String (" textureDimensions($0" ) + (includeMipInfo ? " , $1" : " " ) + " )" ) << " ;" ;
280
+ wgsl << " ($" << String (paramCount) << " ) = "
281
+ << wgslTextureAttributeConversion (
282
+ dimType,
283
+ String (" textureDimensions($0" ) + (includeMipInfo ? " , $1" : " " ) + " )" )
284
+ << " ;" ;
283
285
284
286
sizeDimCount = 1 ;
285
287
break ;
@@ -291,13 +293,15 @@ void TextureTypeInfo::writeGetDimensionFunctions()
291
293
metal << " (*($" << String (paramCount) << " ) = $0.get_width("
292
294
<< String (metalMipLevel) << " ))," ;
293
295
wgsl << " var dim = textureDimensions($0" << (includeMipInfo ? " , $1" : " " ) << " );" ;
294
- wgsl << " ($" << String (paramCount) << " ) = " << wgslTextureAttributeConversion (dimType, " dim.x" ) << " ;" ;
296
+ wgsl << " ($" << String (paramCount)
297
+ << " ) = " << wgslTextureAttributeConversion (dimType, " dim.x" ) << " ;" ;
295
298
296
299
++paramCount;
297
300
params << t << " height" ;
298
301
metal << " (*($" << String (paramCount) << " ) = $0.get_height("
299
302
<< String (metalMipLevel) << " ))," ;
300
- wgsl << " ($" << String (paramCount) << " ) = " << wgslTextureAttributeConversion (dimType, " dim.y" ) << " ;" ;
303
+ wgsl << " ($" << String (paramCount)
304
+ << " ) = " << wgslTextureAttributeConversion (dimType, " dim.y" ) << " ;" ;
301
305
302
306
sizeDimCount = 2 ;
303
307
break ;
@@ -308,19 +312,22 @@ void TextureTypeInfo::writeGetDimensionFunctions()
308
312
metal << " (*($" << String (paramCount) << " ) = $0.get_width("
309
313
<< String (metalMipLevel) << " ))," ;
310
314
wgsl << " var dim = textureDimensions($0" << (includeMipInfo ? " , $1" : " " ) << " );" ;
311
- wgsl << " ($" << String (paramCount) << " ) = " << wgslTextureAttributeConversion (dimType, " dim.x" ) << " ;" ;
315
+ wgsl << " ($" << String (paramCount)
316
+ << " ) = " << wgslTextureAttributeConversion (dimType, " dim.x" ) << " ;" ;
312
317
313
318
++paramCount;
314
319
params << t << " height," ;
315
320
metal << " (*($" << String (paramCount) << " ) = $0.get_height("
316
321
<< String (metalMipLevel) << " ))," ;
317
- wgsl << " ($" << String (paramCount) << " ) = " << wgslTextureAttributeConversion (dimType, " dim.y" ) << " ;" ;
322
+ wgsl << " ($" << String (paramCount)
323
+ << " ) = " << wgslTextureAttributeConversion (dimType, " dim.y" ) << " ;" ;
318
324
319
325
++paramCount;
320
326
params << t << " depth" ;
321
327
metal << " (*($" << String (paramCount) << " ) = $0.get_depth("
322
328
<< String (metalMipLevel) << " ))," ;
323
- wgsl << " ($" << String (paramCount) << " ) = " << wgslTextureAttributeConversion (dimType, " dim.z" ) << " ;" ;
329
+ wgsl << " ($" << String (paramCount)
330
+ << " ) = " << wgslTextureAttributeConversion (dimType, " dim.z" ) << " ;" ;
324
331
325
332
sizeDimCount = 3 ;
326
333
break ;
@@ -336,23 +343,29 @@ void TextureTypeInfo::writeGetDimensionFunctions()
336
343
++paramCount;
337
344
params << " , " << t << " elements" ;
338
345
metal << " (*($" << String (paramCount) << " ) = $0.get_array_size())," ;
339
- wgsl << " ($" << String (paramCount) << " ) = " << wgslTextureAttributeConversion (dimType, " textureNumLayers($0)" ) << " ;" ;
346
+ wgsl << " ($" << String (paramCount)
347
+ << " ) = " << wgslTextureAttributeConversion (dimType, " textureNumLayers($0)" )
348
+ << " ;" ;
340
349
}
341
350
342
351
if (isMultisample)
343
352
{
344
353
++paramCount;
345
354
params << " , " << t << " sampleCount" ;
346
355
metal << " (*($" << String (paramCount) << " ) = $0.get_num_samples())," ;
347
- wgsl << " ($" << String (paramCount) << " ) = " << wgslTextureAttributeConversion (dimType, " textureNumSamples($0)" ) << " ;" ;
356
+ wgsl << " ($" << String (paramCount)
357
+ << " ) = " << wgslTextureAttributeConversion (dimType, " textureNumSamples($0)" )
358
+ << " ;" ;
348
359
}
349
360
350
361
if (includeMipInfo)
351
362
{
352
363
++paramCount;
353
364
params << " , " << t << " numberOfLevels" ;
354
365
metal << " (*($" << String (paramCount) << " ) = $0.get_num_mip_levels())," ;
355
- wgsl << " ($" << String (paramCount) << " ) = " << wgslTextureAttributeConversion (dimType, " textureNumLevels($0)" ) << " ;" ;
366
+ wgsl << " ($" << String (paramCount)
367
+ << " ) = " << wgslTextureAttributeConversion (dimType, " textureNumLevels($0)" )
368
+ << " ;" ;
356
369
}
357
370
358
371
metal.reduceLength (metal.getLength () - 1 ); // drop the last comma
0 commit comments