Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code for PR #5560 #9

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions source/slang/slang-core-module-textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,19 @@ enum class DimType
Count,
};

// The WGSL texture attribute types for 'expr' are unsigned int, and anything else requires a conversion.
template <typename S>
// The WGSL texture attribute types for 'expr' are unsigned int, and anything else requires a
// conversion.
template<typename S>
static String wgslTextureAttributeConversion(DimType type, S expr)
{

switch(type)
switch (type)
{

case DimType::UInt:
return expr;


case DimType::Float:
{
// Conversion to float is exact for values <= 2^24.
Expand All @@ -213,8 +214,8 @@ static String wgslTextureAttributeConversion(DimType type, S expr)

case DimType::Int:
{
// We can assume two's complement and just do a bitcast, since texture dimensions can't be
// anywhere near big enough to yield a negative result.
// We can assume two's complement and just do a bitcast, since texture dimensions can't
// be anywhere near big enough to yield a negative result.
String castExpr("bitcast<i32>(");
castExpr.append(expr);
castExpr.append(")");
Expand All @@ -225,9 +226,7 @@ static String wgslTextureAttributeConversion(DimType type, S expr)
default:
SLANG_UNREACHABLE("Unexpected DimType enum value");
break;

};

}

void TextureTypeInfo::writeGetDimensionFunctions()
Expand Down Expand Up @@ -278,8 +277,11 @@ void TextureTypeInfo::writeGetDimensionFunctions()
params << t << "width";
metal << "(*($" << String(paramCount) << ") = $0.get_width("
<< String(metalMipLevel) << ")),";
wgsl << "($" << String(paramCount) << ") = " <<
wgslTextureAttributeConversion(dimType, String("textureDimensions($0") + (includeMipInfo ? ", $1" : "") + ")") << ";";
wgsl << "($" << String(paramCount) << ") = "
<< wgslTextureAttributeConversion(
dimType,
String("textureDimensions($0") + (includeMipInfo ? ", $1" : "") + ")")
<< ";";

sizeDimCount = 1;
break;
Expand All @@ -291,13 +293,15 @@ void TextureTypeInfo::writeGetDimensionFunctions()
metal << "(*($" << String(paramCount) << ") = $0.get_width("
<< String(metalMipLevel) << ")),";
wgsl << "var dim = textureDimensions($0" << (includeMipInfo ? ", $1" : "") << ");";
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.x") << ";";
wgsl << "($" << String(paramCount)
<< ") = " << wgslTextureAttributeConversion(dimType, "dim.x") << ";";

++paramCount;
params << t << "height";
metal << "(*($" << String(paramCount) << ") = $0.get_height("
<< String(metalMipLevel) << ")),";
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.y") << ";";
wgsl << "($" << String(paramCount)
<< ") = " << wgslTextureAttributeConversion(dimType, "dim.y") << ";";

sizeDimCount = 2;
break;
Expand All @@ -308,19 +312,22 @@ void TextureTypeInfo::writeGetDimensionFunctions()
metal << "(*($" << String(paramCount) << ") = $0.get_width("
<< String(metalMipLevel) << ")),";
wgsl << "var dim = textureDimensions($0" << (includeMipInfo ? ", $1" : "") << ");";
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.x") << ";";
wgsl << "($" << String(paramCount)
<< ") = " << wgslTextureAttributeConversion(dimType, "dim.x") << ";";

++paramCount;
params << t << "height,";
metal << "(*($" << String(paramCount) << ") = $0.get_height("
<< String(metalMipLevel) << ")),";
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.y") << ";";
wgsl << "($" << String(paramCount)
<< ") = " << wgslTextureAttributeConversion(dimType, "dim.y") << ";";

++paramCount;
params << t << "depth";
metal << "(*($" << String(paramCount) << ") = $0.get_depth("
<< String(metalMipLevel) << ")),";
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.z") << ";";
wgsl << "($" << String(paramCount)
<< ") = " << wgslTextureAttributeConversion(dimType, "dim.z") << ";";

sizeDimCount = 3;
break;
Expand All @@ -336,23 +343,29 @@ void TextureTypeInfo::writeGetDimensionFunctions()
++paramCount;
params << ", " << t << "elements";
metal << "(*($" << String(paramCount) << ") = $0.get_array_size()),";
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "textureNumLayers($0)") << ";";
wgsl << "($" << String(paramCount)
<< ") = " << wgslTextureAttributeConversion(dimType, "textureNumLayers($0)")
<< ";";
}

if (isMultisample)
{
++paramCount;
params << ", " << t << "sampleCount";
metal << "(*($" << String(paramCount) << ") = $0.get_num_samples()),";
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "textureNumSamples($0)") << ";";
wgsl << "($" << String(paramCount)
<< ") = " << wgslTextureAttributeConversion(dimType, "textureNumSamples($0)")
<< ";";
}

if (includeMipInfo)
{
++paramCount;
params << ", " << t << "numberOfLevels";
metal << "(*($" << String(paramCount) << ") = $0.get_num_mip_levels()),";
wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "textureNumLevels($0)") << ";";
wgsl << "($" << String(paramCount)
<< ") = " << wgslTextureAttributeConversion(dimType, "textureNumLevels($0)")
<< ";";
}

metal.reduceLength(metal.getLength() - 1); // drop the last comma
Expand Down
Loading