diff --git a/tests/ComputeSharp.Tests/BufferTests.cs b/tests/ComputeSharp.Tests/BufferTests.cs index a4833d8f..7860f8e9 100644 --- a/tests/ComputeSharp.Tests/BufferTests.cs +++ b/tests/ComputeSharp.Tests/BufferTests.cs @@ -371,4 +371,40 @@ public partial class BufferTests destination[ThreadIds.X] = source[ThreadIds.X]; } } + + [CombinatorialTestMethod] + [AllDevices] + public void Dispatch_ReadWriteBuffer_DoublePrecision(Device device) + { + if (!device.Get().IsDoublePrecisionSupportAvailable()) + { + Assert.Inconclusive(); + } + + double[] array = Enumerable.Range(0, 128).Select(static i => (double)i).ToArray(); + + using ReadWriteBuffer buffer = device.Get().AllocateReadWriteBuffer(array); + + device.Get().For(128, new DoublePrecisionSupportShader(buffer, 2.0)); + + double[] result = buffer.ToArray(); + + for (int i = 0; i < 128; i++) + { + Assert.IsTrue(Math.Abs(result[i] - (array[i] * 2.0 + 3.14)) < 0.00001); + } + } + + [AutoConstructor] + public readonly partial struct DoublePrecisionSupportShader : IComputeShader + { + public readonly ReadWriteBuffer buffer; + public readonly double factor; + + /// + public void Execute() + { + buffer[ThreadIds.X] = buffer[ThreadIds.X] * factor + 3.14; + } + } } diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs index 09cc75fa..22493747 100644 --- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs @@ -193,6 +193,27 @@ namespace ComputeSharp.Tests { ReflectionServices.GetShaderInfo(out var info); } + + [TestMethod] + public void DoublePrecisionSupport() + { + ReflectionServices.GetShaderInfo(out var info); + + Assert.IsTrue(info.RequiresDoublePrecisionSupport); + } + + [AutoConstructor] + public readonly partial struct DoublePrecisionSupportShader : IComputeShader + { + public readonly ReadWriteBuffer buffer; + public readonly double factor; + + /// + public void Execute() + { + buffer[ThreadIds.X] *= factor + 3.14; + } + } } }