From 429dca7b1636f326432d96ae997ad03dc0c5d1de Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 1 Sep 2022 00:52:17 +0200 Subject: [PATCH] Add Texture1D tests --- .../Texture1DTests.Pixels.g.cs | 157 ++++++++++++++++++ .../Texture1DTests.Pixels.tt | 84 ++++++++++ 2 files changed, 241 insertions(+) create mode 100644 tests/ComputeSharp.Tests/Texture1DTests.Pixels.g.cs create mode 100644 tests/ComputeSharp.Tests/Texture1DTests.Pixels.tt diff --git a/tests/ComputeSharp.Tests/Texture1DTests.Pixels.g.cs b/tests/ComputeSharp.Tests/Texture1DTests.Pixels.g.cs new file mode 100644 index 00000000..35a34f40 --- /dev/null +++ b/tests/ComputeSharp.Tests/Texture1DTests.Pixels.g.cs @@ -0,0 +1,157 @@ +using System; +using ComputeSharp.Tests.Attributes; +using ComputeSharp.Tests.Extensions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.Tests; + +[TestClass] +[TestCategory("Texture1D")] +public partial class Texture1DTests +{ + [CombinatorialTestMethod] + [AllDevices] + [Data(typeof(Bgra32), typeof(Float4))] + [Data(typeof(R16), typeof(float))] + [Data(typeof(R8), typeof(float))] + [Data(typeof(Rg16), typeof(Float2))] + [Data(typeof(Rg32), typeof(Float2))] + [Data(typeof(Rgba32), typeof(Float4))] + [Data(typeof(Rgba64), typeof(Float4))] + public void Dispatch_NormalizedTexture1D(Device device, Type t, Type tPixel) + { + if (t == typeof(Bgra32) && tPixel == typeof(Float4)) + { + using ReadOnlyTexture1D source = device.Get().AllocateReadOnlyTexture1D(128); + using ReadWriteTexture1D destination = device.Get().AllocateReadWriteTexture1D(128); + + device.Get().For(128, new Shader_Unorm_Bgra32_Float4(source, destination)); + } + if (t == typeof(R16) && tPixel == typeof(float)) + { + using ReadOnlyTexture1D source = device.Get().AllocateReadOnlyTexture1D(128); + using ReadWriteTexture1D destination = device.Get().AllocateReadWriteTexture1D(128); + + device.Get().For(128, new Shader_Unorm_R16_float(source, destination)); + } + if (t == typeof(R8) && tPixel == typeof(float)) + { + using ReadOnlyTexture1D source = device.Get().AllocateReadOnlyTexture1D(128); + using ReadWriteTexture1D destination = device.Get().AllocateReadWriteTexture1D(128); + + device.Get().For(128, new Shader_Unorm_R8_float(source, destination)); + } + if (t == typeof(Rg16) && tPixel == typeof(Float2)) + { + using ReadOnlyTexture1D source = device.Get().AllocateReadOnlyTexture1D(128); + using ReadWriteTexture1D destination = device.Get().AllocateReadWriteTexture1D(128); + + device.Get().For(128, new Shader_Unorm_Rg16_Float2(source, destination)); + } + if (t == typeof(Rg32) && tPixel == typeof(Float2)) + { + using ReadOnlyTexture1D source = device.Get().AllocateReadOnlyTexture1D(128); + using ReadWriteTexture1D destination = device.Get().AllocateReadWriteTexture1D(128); + + device.Get().For(128, new Shader_Unorm_Rg32_Float2(source, destination)); + } + if (t == typeof(Rgba32) && tPixel == typeof(Float4)) + { + using ReadOnlyTexture1D source = device.Get().AllocateReadOnlyTexture1D(128); + using ReadWriteTexture1D destination = device.Get().AllocateReadWriteTexture1D(128); + + device.Get().For(128, new Shader_Unorm_Rgba32_Float4(source, destination)); + } + if (t == typeof(Rgba64) && tPixel == typeof(Float4)) + { + using ReadOnlyTexture1D source = device.Get().AllocateReadOnlyTexture1D(128); + using ReadWriteTexture1D destination = device.Get().AllocateReadWriteTexture1D(128); + + device.Get().For(128, new Shader_Unorm_Rgba64_Float4(source, destination)); + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Bgra32_Float4 : IComputeShader + { + public readonly ReadOnlyTexture1D source; + public readonly ReadWriteTexture1D destination; + + public void Execute() + { + destination[ThreadIds.X] = (source[ThreadIds.X] + destination[ThreadIds.X]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_R16_float : IComputeShader + { + public readonly ReadOnlyTexture1D source; + public readonly ReadWriteTexture1D destination; + + public void Execute() + { + destination[ThreadIds.X] = (source[ThreadIds.X] + destination[ThreadIds.X]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_R8_float : IComputeShader + { + public readonly ReadOnlyTexture1D source; + public readonly ReadWriteTexture1D destination; + + public void Execute() + { + destination[ThreadIds.X] = (source[ThreadIds.X] + destination[ThreadIds.X]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rg16_Float2 : IComputeShader + { + public readonly ReadOnlyTexture1D source; + public readonly ReadWriteTexture1D destination; + + public void Execute() + { + destination[ThreadIds.X] = (source[ThreadIds.X] + destination[ThreadIds.X]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rg32_Float2 : IComputeShader + { + public readonly ReadOnlyTexture1D source; + public readonly ReadWriteTexture1D destination; + + public void Execute() + { + destination[ThreadIds.X] = (source[ThreadIds.X] + destination[ThreadIds.X]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rgba32_Float4 : IComputeShader + { + public readonly ReadOnlyTexture1D source; + public readonly ReadWriteTexture1D destination; + + public void Execute() + { + destination[ThreadIds.X] = (source[ThreadIds.X] + destination[ThreadIds.X]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rgba64_Float4 : IComputeShader + { + public readonly ReadOnlyTexture1D source; + public readonly ReadWriteTexture1D destination; + + public void Execute() + { + destination[ThreadIds.X] = (source[ThreadIds.X] + destination[ThreadIds.X]) / 2; + } + } +} diff --git a/tests/ComputeSharp.Tests/Texture1DTests.Pixels.tt b/tests/ComputeSharp.Tests/Texture1DTests.Pixels.tt new file mode 100644 index 00000000..fd768705 --- /dev/null +++ b/tests/ComputeSharp.Tests/Texture1DTests.Pixels.tt @@ -0,0 +1,84 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".g.cs"#> +<# +var typesMap = new Dictionary +{ + ["Bgra32"] = new[] { "Float4" }, + ["R16"] = new[] { "float" }, + ["R8"] = new[] { "float" }, + ["Rg16"] = new[] { "Float2" }, + ["Rg32"] = new[] { "Float2" }, + ["Rgba32"] = new[] { "Float4" }, + ["Rgba64"] = new[] { "Float4" } +}; + +IEnumerable<(string T, string TPixel)> EnumerateTypes() +{ + foreach (var pair in typesMap) + foreach (var tPixel in pair.Value) + yield return (pair.Key, tPixel); +} +#> +using System; +using ComputeSharp.Tests.Attributes; +using ComputeSharp.Tests.Extensions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.Tests; + +[TestClass] +[TestCategory("Texture1D")] +public partial class Texture1DTests +{ + [CombinatorialTestMethod] + [AllDevices] +<# +foreach (var (t, tPixel) in EnumerateTypes()) +{ +#> + [Data(typeof(<#=t#>), typeof(<#=tPixel#>))] +<# +} +#> + public void Dispatch_NormalizedTexture1D(Device device, Type t, Type tPixel) + { +<# +foreach (var (t, tPixel) in EnumerateTypes()) +{ +#> + if (t == typeof(<#=t#>) && tPixel == typeof(<#=tPixel#>)) + { + using ReadOnlyTexture1D<<#=t#>, <#=tPixel#>> source = device.Get().AllocateReadOnlyTexture1D<<#=t#>, <#=tPixel#>>(128); + using ReadWriteTexture1D<<#=t#>, <#=tPixel#>> destination = device.Get().AllocateReadWriteTexture1D<<#=t#>, <#=tPixel#>>(128); + + device.Get().For(128, new Shader_Unorm_<#=t#>_<#=tPixel#>(source, destination)); + } +<# +} +#> + } +<# + +foreach (var (t, tPixel) in EnumerateTypes()) +{ +#> + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_<#=t#>_<#=tPixel#> : IComputeShader + { + public readonly ReadOnlyTexture1D<<#=t#>, <#=tPixel#>> source; + public readonly ReadWriteTexture1D<<#=t#>, <#=tPixel#>> destination; + + public void Execute() + { + destination[ThreadIds.X] = (source[ThreadIds.X] + destination[ThreadIds.X]) / 2; + } + } +<# +} +#> +}