diff --git a/source/slang/slang-core-module-textures.cpp b/source/slang/slang-core-module-textures.cpp index ec9748c1b2..d7d8ed3b27 100644 --- a/source/slang/slang-core-module-textures.cpp +++ b/source/slang/slang-core-module-textures.cpp @@ -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 +// The WGSL texture attribute types for 'expr' are unsigned int, and anything else requires a +// conversion. +template 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. @@ -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("); castExpr.append(expr); castExpr.append(")"); @@ -225,9 +226,7 @@ static String wgslTextureAttributeConversion(DimType type, S expr) default: SLANG_UNREACHABLE("Unexpected DimType enum value"); break; - }; - } void TextureTypeInfo::writeGetDimensionFunctions() @@ -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; @@ -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; @@ -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; @@ -336,7 +343,9 @@ 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) @@ -344,7 +353,9 @@ void TextureTypeInfo::writeGetDimensionFunctions() ++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) @@ -352,7 +363,9 @@ void TextureTypeInfo::writeGetDimensionFunctions() ++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