From d5992f0039673a15097af4c3681bf2ec4da7a1af Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 5 Jan 2021 20:24:45 +0100 Subject: [PATCH] Fixed parsing issue with HLSL float literals --- .../Processors/HlslBokehBlurProcessor{TPixel}.cs | 2 +- .../SyntaxRewriters/ShaderSourceRewriter.cs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs index 0f175def..25d0d23b 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs @@ -494,7 +494,7 @@ namespace ComputeSharp.BokehBlur.Processors Float4 v = source[i, ids.X]; v.XYZ = Hlsl.Clamp(v.XYZ, 0, float.MaxValue); - v.XYZ = Hlsl.Pow(v.XYZ, 0.333333343f); + v.XYZ = Hlsl.Pow(v.XYZ, 1 / 3f); target[i, ids.X] = v; } diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 2331d5ea..0f089902 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -218,11 +218,15 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters // in HLSL, we can remove the suffix entirely. As for 64 bit values, we simply use the 'L' suffix. if (type.GetFullMetadataName().Equals(typeof(float).FullName)) { - return updatedNode.WithToken(Literal(updatedNode.Token.ValueText, 0f)); + string literal = updatedNode.Token.ValueText; + + if (!literal.Contains('.')) literal += ".0"; + + return updatedNode.WithToken(Literal(literal, 0f)); } else if (type.GetFullMetadataName().Equals(typeof(double).FullName)) { - return updatedNode.WithToken(Literal($"{updatedNode.Token.ValueText}L", 0d)); + return updatedNode.WithToken(Literal(updatedNode.Token.ValueText + "L", 0d)); } }