diff --git a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj index 92a907e5..aae52469 100644 --- a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj +++ b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj @@ -5,14 +5,6 @@ false - - - True - True - Texture2DTests.Pixels.tt - - - @@ -33,6 +25,10 @@ TextTemplatingFileGenerator Texture2DTests.Pixels.g.cs + + TextTemplatingFileGenerator + Texture3DTests.Pixels.g.cs + @@ -45,6 +41,11 @@ True Texture2DTests.Pixels.tt + + True + True + Texture3DTests.Pixels.tt + diff --git a/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs new file mode 100644 index 00000000..3c1e4955 --- /dev/null +++ b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs @@ -0,0 +1,254 @@ +using System; +using System.Numerics; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.Tests +{ + public partial class Texture3DTests + { + [TestMethod] + [DataRow(typeof(Bgra32), typeof(Vector4))] + [DataRow(typeof(Bgra32), typeof(Float4))] + [DataRow(typeof(R16), typeof(float))] + [DataRow(typeof(R8), typeof(float))] + [DataRow(typeof(Rg16), typeof(Vector2))] + [DataRow(typeof(Rg16), typeof(Float2))] + [DataRow(typeof(Rg32), typeof(Vector2))] + [DataRow(typeof(Rg32), typeof(Float2))] + [DataRow(typeof(Rgba32), typeof(Vector4))] + [DataRow(typeof(Rgba32), typeof(Float4))] + [DataRow(typeof(Rgba64), typeof(Vector4))] + [DataRow(typeof(Rgba64), typeof(Float4))] + public void Dispatch_NormalizedTexture3D(Type t, Type tPixel) + { + if (t == typeof(Bgra32) && tPixel == typeof(Vector4)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_Bgra32_Vector4(source, destination)); + } + if (t == typeof(Bgra32) && tPixel == typeof(Float4)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_Bgra32_Float4(source, destination)); + } + if (t == typeof(R16) && tPixel == typeof(float)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_R16_float(source, destination)); + } + if (t == typeof(R8) && tPixel == typeof(float)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_R8_float(source, destination)); + } + if (t == typeof(Rg16) && tPixel == typeof(Vector2)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg16_Vector2(source, destination)); + } + if (t == typeof(Rg16) && tPixel == typeof(Float2)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg16_Float2(source, destination)); + } + if (t == typeof(Rg32) && tPixel == typeof(Vector2)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg32_Vector2(source, destination)); + } + if (t == typeof(Rg32) && tPixel == typeof(Float2)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg32_Float2(source, destination)); + } + if (t == typeof(Rgba32) && tPixel == typeof(Vector4)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba32_Vector4(source, destination)); + } + if (t == typeof(Rgba32) && tPixel == typeof(Float4)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba32_Float4(source, destination)); + } + if (t == typeof(Rgba64) && tPixel == typeof(Vector4)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba64_Vector4(source, destination)); + } + if (t == typeof(Rgba64) && tPixel == typeof(Float4)) + { + using ReadOnlyTexture3D source = Gpu.Default.AllocateReadOnlyTexture3D(128, 128, 2); + using ReadWriteTexture3D destination = Gpu.Default.AllocateReadWriteTexture3D(128, 128, 2); + + Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba64_Float4(source, destination)); + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Bgra32_Vector4 : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Bgra32_Float4 : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_R16_float : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_R8_float : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rg16_Vector2 : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rg16_Float2 : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rg32_Vector2 : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rg32_Float2 : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rgba32_Vector4 : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rgba32_Float4 : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rgba64_Vector4 : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + + [AutoConstructor] + internal readonly partial struct Shader_Unorm_Rgba64_Float4 : IComputeShader + { + public readonly ReadOnlyTexture3D source; + public readonly ReadWriteTexture3D destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } + } +} \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt new file mode 100644 index 00000000..d72edd3c --- /dev/null +++ b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt @@ -0,0 +1,81 @@ +<#@ 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[] { "Vector4", "Float4" }, + ["R16"] = new[] { "float" }, + ["R8"] = new[] { "float" }, + ["Rg16"] = new[] { "Vector2", "Float2" }, + ["Rg32"] = new[] { "Vector2", "Float2" }, + ["Rgba32"] = new[] { "Vector4", "Float4" }, + ["Rgba64"] = new[] { "Vector4", "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 System.Numerics; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.Tests +{ + public partial class Texture3DTests + { + [TestMethod] +<# +foreach (var (t, tPixel) in EnumerateTypes()) +{ +#> + [DataRow(typeof(<#=t#>), typeof(<#=tPixel#>))] +<# +} +#> + public void Dispatch_NormalizedTexture3D(Type t, Type tPixel) + { +<# +foreach (var (t, tPixel) in EnumerateTypes()) +{ +#> + if (t == typeof(<#=t#>) && tPixel == typeof(<#=tPixel#>)) + { + using ReadOnlyTexture3D<<#=t#>, <#=tPixel#>> source = Gpu.Default.AllocateReadOnlyTexture3D<<#=t#>, <#=tPixel#>>(128, 128, 2); + using ReadWriteTexture3D<<#=t#>, <#=tPixel#>> destination = Gpu.Default.AllocateReadWriteTexture3D<<#=t#>, <#=tPixel#>>(128, 128, 2); + + Gpu.Default.For(128, 128, 2, 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 ReadOnlyTexture3D<<#=t#>, <#=tPixel#>> source; + public readonly ReadWriteTexture3D<<#=t#>, <#=tPixel#>> destination; + + public void Execute(ThreadIds ids) + { + destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + } + } +<# +} +#> + } +} \ No newline at end of file