From 9aa8395e70f11261aa51286fc6d314b9897989a4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 4 Jun 2024 18:23:15 -0700 Subject: [PATCH] Add runtime test for float literal values --- .../Assets/Green32x32.png | Bin 0 -> 123 bytes .../ComputeSharp.D2D1.Tests.csproj | 3 ++ .../ShaderRewriterTests.cs | 29 ++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/ComputeSharp.D2D1.Tests/Assets/Green32x32.png diff --git a/tests/ComputeSharp.D2D1.Tests/Assets/Green32x32.png b/tests/ComputeSharp.D2D1.Tests/Assets/Green32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..7cacfc9d3caa422ff8aef878eca3dd5dd8e226ce GIT binary patch literal 123 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?4jBOuH;Rhv&5D5&e{ z;uumf=j}N|Mg|6s!y9COZ0Ff=WAZfzwcp~ir!WImAOVXIC#HIKNujkMF;7=Nmvv4F FO#o3u90&ja literal 0 HcmV?d00001 diff --git a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj index 6b7b3491..a42cbe0a 100644 --- a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj +++ b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj @@ -96,6 +96,9 @@ PreserveNewest + + PreserveNewest + diff --git a/tests/ComputeSharp.D2D1.Tests/ShaderRewriterTests.cs b/tests/ComputeSharp.D2D1.Tests/ShaderRewriterTests.cs index 36a6220f..b1fab05a 100644 --- a/tests/ComputeSharp.D2D1.Tests/ShaderRewriterTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/ShaderRewriterTests.cs @@ -1,4 +1,5 @@ using ComputeSharp.D2D1.Interop; +using ComputeSharp.D2D1.Tests.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; #pragma warning disable CA1822 @@ -179,4 +180,32 @@ public partial class ShaderRewriterTests mask2x3_r_or.M11 ? 1 : 0); } } + + // See https://github.com/Sergio0694/ComputeSharp/issues/780 + [TestMethod] + public void ProblematicFloatLiteralValue_IsRewrittenCorrectly() + { + D2D1TestRunner.RunAndCompareShader( + new ProblematicFloatLiteralValueShader(131072.65f), + 32, + 32, + "Green32x32.png"); + } + + [D2DInputCount(0)] + [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] + [D2DOutputBuffer(D2D1BufferPrecision.Float32)] + [D2DGeneratedPixelShaderDescriptor] + internal readonly partial struct ProblematicFloatLiteralValueShader(float x) : ID2D1PixelShader + { + public float4 Execute() + { + if (x != 131072.65f) + { + return 0; + } + + return new float4(0.0f, 1.0f, 0.0f, 1.0f); + } + } } \ No newline at end of file