Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5da6978

Browse files
authoredNov 14, 2024
Merge pull request #9 from slangbot/format-5560-aleino/wgpu
Format code for PR shader-slang#5560
2 parents d7aa424 + 0c2a379 commit 5da6978

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed
 

‎source/slang/slang-core-module-textures.cpp

+33-20
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,19 @@ enum class DimType
189189
Count,
190190
};
191191

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>
194195
static String wgslTextureAttributeConversion(DimType type, S expr)
195196
{
196197

197-
switch(type)
198+
switch (type)
198199
{
199-
200+
200201
case DimType::UInt:
201202
return expr;
202-
203-
203+
204+
204205
case DimType::Float:
205206
{
206207
// Conversion to float is exact for values <= 2^24.
@@ -213,8 +214,8 @@ static String wgslTextureAttributeConversion(DimType type, S expr)
213214

214215
case DimType::Int:
215216
{
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.
218219
String castExpr("bitcast<i32>(");
219220
castExpr.append(expr);
220221
castExpr.append(")");
@@ -225,9 +226,7 @@ static String wgslTextureAttributeConversion(DimType type, S expr)
225226
default:
226227
SLANG_UNREACHABLE("Unexpected DimType enum value");
227228
break;
228-
229229
};
230-
231230
}
232231

233232
void TextureTypeInfo::writeGetDimensionFunctions()
@@ -278,8 +277,11 @@ void TextureTypeInfo::writeGetDimensionFunctions()
278277
params << t << "width";
279278
metal << "(*($" << String(paramCount) << ") = $0.get_width("
280279
<< 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+
<< ";";
283285

284286
sizeDimCount = 1;
285287
break;
@@ -291,13 +293,15 @@ void TextureTypeInfo::writeGetDimensionFunctions()
291293
metal << "(*($" << String(paramCount) << ") = $0.get_width("
292294
<< String(metalMipLevel) << ")),";
293295
wgsl << "var dim = textureDimensions($0" << (includeMipInfo ? ", $1" : "") << ");";
294-
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.x") << ";";
296+
wgsl << "($" << String(paramCount)
297+
<< ") = " << wgslTextureAttributeConversion(dimType, "dim.x") << ";";
295298

296299
++paramCount;
297300
params << t << "height";
298301
metal << "(*($" << String(paramCount) << ") = $0.get_height("
299302
<< String(metalMipLevel) << ")),";
300-
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.y") << ";";
303+
wgsl << "($" << String(paramCount)
304+
<< ") = " << wgslTextureAttributeConversion(dimType, "dim.y") << ";";
301305

302306
sizeDimCount = 2;
303307
break;
@@ -308,19 +312,22 @@ void TextureTypeInfo::writeGetDimensionFunctions()
308312
metal << "(*($" << String(paramCount) << ") = $0.get_width("
309313
<< String(metalMipLevel) << ")),";
310314
wgsl << "var dim = textureDimensions($0" << (includeMipInfo ? ", $1" : "") << ");";
311-
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.x") << ";";
315+
wgsl << "($" << String(paramCount)
316+
<< ") = " << wgslTextureAttributeConversion(dimType, "dim.x") << ";";
312317

313318
++paramCount;
314319
params << t << "height,";
315320
metal << "(*($" << String(paramCount) << ") = $0.get_height("
316321
<< String(metalMipLevel) << ")),";
317-
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.y") << ";";
322+
wgsl << "($" << String(paramCount)
323+
<< ") = " << wgslTextureAttributeConversion(dimType, "dim.y") << ";";
318324

319325
++paramCount;
320326
params << t << "depth";
321327
metal << "(*($" << String(paramCount) << ") = $0.get_depth("
322328
<< String(metalMipLevel) << ")),";
323-
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.z") << ";";
329+
wgsl << "($" << String(paramCount)
330+
<< ") = " << wgslTextureAttributeConversion(dimType, "dim.z") << ";";
324331

325332
sizeDimCount = 3;
326333
break;
@@ -336,23 +343,29 @@ void TextureTypeInfo::writeGetDimensionFunctions()
336343
++paramCount;
337344
params << ", " << t << "elements";
338345
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+
<< ";";
340349
}
341350

342351
if (isMultisample)
343352
{
344353
++paramCount;
345354
params << ", " << t << "sampleCount";
346355
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+
<< ";";
348359
}
349360

350361
if (includeMipInfo)
351362
{
352363
++paramCount;
353364
params << ", " << t << "numberOfLevels";
354365
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+
<< ";";
356369
}
357370

358371
metal.reduceLength(metal.getLength() - 1); // drop the last comma

0 commit comments

Comments
 (0)
Please sign in to comment.