Added T4 templates for normalized 2D texture tests

このコミットが含まれているのは:
Sergio Pedri committed 2021-01-05 13:40:50 +01:00
1 親 e33c7b927a
コミット 9e0b7404b1
3ファイル変更
+502

検索条件に一致するファイルはありません

+27
ファイルの表示
@@ -5,6 +5,14 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<None Include="Texture2DTests.Pixels.g.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Texture2DTests.Pixels.tt</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Microsoft.Toolkit.HighPerformance" Version="7.0.0-preview4" />
@@ -20,4 +28,23 @@
PrivateAssets="contentfiles;build"/>
</ItemGroup>
<ItemGroup>
<None Update="Texture2DTests.Pixels.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Texture2DTests.Pixels.g.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Compile Update="Texture2DTests.Pixels.g.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Texture2DTests.Pixels.tt</DependentUpon>
</Compile>
</ItemGroup>
</Project>
+394
ファイルの表示
@@ -0,0 +1,394 @@
using System;
using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.Tests
{
public partial class Texture2DTests
{
[TestMethod]
[DataRow(typeof(Bgra32), typeof(Vector4))]
[DataRow(typeof(Bgra32), typeof(Float4))]
[DataRow(typeof(Bgra32), typeof(Double4))]
[DataRow(typeof(R16), typeof(float))]
[DataRow(typeof(R16), typeof(double))]
[DataRow(typeof(R8), typeof(float))]
[DataRow(typeof(R8), typeof(double))]
[DataRow(typeof(Rg16), typeof(Vector2))]
[DataRow(typeof(Rg16), typeof(Float2))]
[DataRow(typeof(Rg16), typeof(Double2))]
[DataRow(typeof(Rg32), typeof(Vector2))]
[DataRow(typeof(Rg32), typeof(Float2))]
[DataRow(typeof(Rg32), typeof(Double2))]
[DataRow(typeof(Rgba32), typeof(Vector4))]
[DataRow(typeof(Rgba32), typeof(Float4))]
[DataRow(typeof(Rgba32), typeof(Double4))]
[DataRow(typeof(Rgba64), typeof(Vector4))]
[DataRow(typeof(Rgba64), typeof(Float4))]
[DataRow(typeof(Rgba64), typeof(Double4))]
public void Dispatch_NormalizedTexture2D(Type t, Type tPixel)
{
if (t == typeof(Bgra32) && tPixel == typeof(Vector4))
{
using ReadOnlyTexture2D<Bgra32, Vector4> source = Gpu.Default.AllocateReadOnlyTexture2D<Bgra32, Vector4>(128, 128);
using ReadWriteTexture2D<Bgra32, Vector4> destination = Gpu.Default.AllocateReadWriteTexture2D<Bgra32, Vector4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Bgra32_Vector4(source, destination));
}
if (t == typeof(Bgra32) && tPixel == typeof(Float4))
{
using ReadOnlyTexture2D<Bgra32, Float4> source = Gpu.Default.AllocateReadOnlyTexture2D<Bgra32, Float4>(128, 128);
using ReadWriteTexture2D<Bgra32, Float4> destination = Gpu.Default.AllocateReadWriteTexture2D<Bgra32, Float4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Bgra32_Float4(source, destination));
}
if (t == typeof(Bgra32) && tPixel == typeof(Double4))
{
using ReadOnlyTexture2D<Bgra32, Double4> source = Gpu.Default.AllocateReadOnlyTexture2D<Bgra32, Double4>(128, 128);
using ReadWriteTexture2D<Bgra32, Double4> destination = Gpu.Default.AllocateReadWriteTexture2D<Bgra32, Double4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Bgra32_Double4(source, destination));
}
if (t == typeof(R16) && tPixel == typeof(float))
{
using ReadOnlyTexture2D<R16, float> source = Gpu.Default.AllocateReadOnlyTexture2D<R16, float>(128, 128);
using ReadWriteTexture2D<R16, float> destination = Gpu.Default.AllocateReadWriteTexture2D<R16, float>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_R16_float(source, destination));
}
if (t == typeof(R16) && tPixel == typeof(double))
{
using ReadOnlyTexture2D<R16, double> source = Gpu.Default.AllocateReadOnlyTexture2D<R16, double>(128, 128);
using ReadWriteTexture2D<R16, double> destination = Gpu.Default.AllocateReadWriteTexture2D<R16, double>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_R16_double(source, destination));
}
if (t == typeof(R8) && tPixel == typeof(float))
{
using ReadOnlyTexture2D<R8, float> source = Gpu.Default.AllocateReadOnlyTexture2D<R8, float>(128, 128);
using ReadWriteTexture2D<R8, float> destination = Gpu.Default.AllocateReadWriteTexture2D<R8, float>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_R8_float(source, destination));
}
if (t == typeof(R8) && tPixel == typeof(double))
{
using ReadOnlyTexture2D<R8, double> source = Gpu.Default.AllocateReadOnlyTexture2D<R8, double>(128, 128);
using ReadWriteTexture2D<R8, double> destination = Gpu.Default.AllocateReadWriteTexture2D<R8, double>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_R8_double(source, destination));
}
if (t == typeof(Rg16) && tPixel == typeof(Vector2))
{
using ReadOnlyTexture2D<Rg16, Vector2> source = Gpu.Default.AllocateReadOnlyTexture2D<Rg16, Vector2>(128, 128);
using ReadWriteTexture2D<Rg16, Vector2> destination = Gpu.Default.AllocateReadWriteTexture2D<Rg16, Vector2>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rg16_Vector2(source, destination));
}
if (t == typeof(Rg16) && tPixel == typeof(Float2))
{
using ReadOnlyTexture2D<Rg16, Float2> source = Gpu.Default.AllocateReadOnlyTexture2D<Rg16, Float2>(128, 128);
using ReadWriteTexture2D<Rg16, Float2> destination = Gpu.Default.AllocateReadWriteTexture2D<Rg16, Float2>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rg16_Float2(source, destination));
}
if (t == typeof(Rg16) && tPixel == typeof(Double2))
{
using ReadOnlyTexture2D<Rg16, Double2> source = Gpu.Default.AllocateReadOnlyTexture2D<Rg16, Double2>(128, 128);
using ReadWriteTexture2D<Rg16, Double2> destination = Gpu.Default.AllocateReadWriteTexture2D<Rg16, Double2>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rg16_Double2(source, destination));
}
if (t == typeof(Rg32) && tPixel == typeof(Vector2))
{
using ReadOnlyTexture2D<Rg32, Vector2> source = Gpu.Default.AllocateReadOnlyTexture2D<Rg32, Vector2>(128, 128);
using ReadWriteTexture2D<Rg32, Vector2> destination = Gpu.Default.AllocateReadWriteTexture2D<Rg32, Vector2>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rg32_Vector2(source, destination));
}
if (t == typeof(Rg32) && tPixel == typeof(Float2))
{
using ReadOnlyTexture2D<Rg32, Float2> source = Gpu.Default.AllocateReadOnlyTexture2D<Rg32, Float2>(128, 128);
using ReadWriteTexture2D<Rg32, Float2> destination = Gpu.Default.AllocateReadWriteTexture2D<Rg32, Float2>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rg32_Float2(source, destination));
}
if (t == typeof(Rg32) && tPixel == typeof(Double2))
{
using ReadOnlyTexture2D<Rg32, Double2> source = Gpu.Default.AllocateReadOnlyTexture2D<Rg32, Double2>(128, 128);
using ReadWriteTexture2D<Rg32, Double2> destination = Gpu.Default.AllocateReadWriteTexture2D<Rg32, Double2>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rg32_Double2(source, destination));
}
if (t == typeof(Rgba32) && tPixel == typeof(Vector4))
{
using ReadOnlyTexture2D<Rgba32, Vector4> source = Gpu.Default.AllocateReadOnlyTexture2D<Rgba32, Vector4>(128, 128);
using ReadWriteTexture2D<Rgba32, Vector4> destination = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba32_Vector4(source, destination));
}
if (t == typeof(Rgba32) && tPixel == typeof(Float4))
{
using ReadOnlyTexture2D<Rgba32, Float4> source = Gpu.Default.AllocateReadOnlyTexture2D<Rgba32, Float4>(128, 128);
using ReadWriteTexture2D<Rgba32, Float4> destination = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Float4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba32_Float4(source, destination));
}
if (t == typeof(Rgba32) && tPixel == typeof(Double4))
{
using ReadOnlyTexture2D<Rgba32, Double4> source = Gpu.Default.AllocateReadOnlyTexture2D<Rgba32, Double4>(128, 128);
using ReadWriteTexture2D<Rgba32, Double4> destination = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Double4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba32_Double4(source, destination));
}
if (t == typeof(Rgba64) && tPixel == typeof(Vector4))
{
using ReadOnlyTexture2D<Rgba64, Vector4> source = Gpu.Default.AllocateReadOnlyTexture2D<Rgba64, Vector4>(128, 128);
using ReadWriteTexture2D<Rgba64, Vector4> destination = Gpu.Default.AllocateReadWriteTexture2D<Rgba64, Vector4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba64_Vector4(source, destination));
}
if (t == typeof(Rgba64) && tPixel == typeof(Float4))
{
using ReadOnlyTexture2D<Rgba64, Float4> source = Gpu.Default.AllocateReadOnlyTexture2D<Rgba64, Float4>(128, 128);
using ReadWriteTexture2D<Rgba64, Float4> destination = Gpu.Default.AllocateReadWriteTexture2D<Rgba64, Float4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba64_Float4(source, destination));
}
if (t == typeof(Rgba64) && tPixel == typeof(Double4))
{
using ReadOnlyTexture2D<Rgba64, Double4> source = Gpu.Default.AllocateReadOnlyTexture2D<Rgba64, Double4>(128, 128);
using ReadWriteTexture2D<Rgba64, Double4> destination = Gpu.Default.AllocateReadWriteTexture2D<Rgba64, Double4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba64_Double4(source, destination));
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Bgra32_Vector4 : IComputeShader
{
public readonly ReadOnlyTexture2D<Bgra32, Vector4> source;
public readonly ReadWriteTexture2D<Bgra32, Vector4> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Bgra32_Float4 : IComputeShader
{
public readonly ReadOnlyTexture2D<Bgra32, Float4> source;
public readonly ReadWriteTexture2D<Bgra32, Float4> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Bgra32_Double4 : IComputeShader
{
public readonly ReadOnlyTexture2D<Bgra32, Double4> source;
public readonly ReadWriteTexture2D<Bgra32, Double4> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_R16_float : IComputeShader
{
public readonly ReadOnlyTexture2D<R16, float> source;
public readonly ReadWriteTexture2D<R16, float> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_R16_double : IComputeShader
{
public readonly ReadOnlyTexture2D<R16, double> source;
public readonly ReadWriteTexture2D<R16, double> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_R8_float : IComputeShader
{
public readonly ReadOnlyTexture2D<R8, float> source;
public readonly ReadWriteTexture2D<R8, float> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_R8_double : IComputeShader
{
public readonly ReadOnlyTexture2D<R8, double> source;
public readonly ReadWriteTexture2D<R8, double> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rg16_Vector2 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rg16, Vector2> source;
public readonly ReadWriteTexture2D<Rg16, Vector2> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rg16_Float2 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rg16, Float2> source;
public readonly ReadWriteTexture2D<Rg16, Float2> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rg16_Double2 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rg16, Double2> source;
public readonly ReadWriteTexture2D<Rg16, Double2> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rg32_Vector2 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rg32, Vector2> source;
public readonly ReadWriteTexture2D<Rg32, Vector2> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rg32_Float2 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rg32, Float2> source;
public readonly ReadWriteTexture2D<Rg32, Float2> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rg32_Double2 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rg32, Double2> source;
public readonly ReadWriteTexture2D<Rg32, Double2> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rgba32_Vector4 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rgba32, Vector4> source;
public readonly ReadWriteTexture2D<Rgba32, Vector4> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rgba32_Float4 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rgba32, Float4> source;
public readonly ReadWriteTexture2D<Rgba32, Float4> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rgba32_Double4 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rgba32, Double4> source;
public readonly ReadWriteTexture2D<Rgba32, Double4> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rgba64_Vector4 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rgba64, Vector4> source;
public readonly ReadWriteTexture2D<Rgba64, Vector4> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rgba64_Float4 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rgba64, Float4> source;
public readonly ReadWriteTexture2D<Rgba64, Float4> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
[AutoConstructor]
internal readonly partial struct Shader_Unorm_Rgba64_Double4 : IComputeShader
{
public readonly ReadOnlyTexture2D<Rgba64, Double4> source;
public readonly ReadWriteTexture2D<Rgba64, Double4> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
}
}
+81
ファイルの表示
@@ -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<string, string[]>
{
["Bgra32"] = new[] { "Vector4", "Float4", "Double4" },
["R16"] = new[] { "float", "double" },
["R8"] = new[] { "float", "double" },
["Rg16"] = new[] { "Vector2", "Float2", "Double2" },
["Rg32"] = new[] { "Vector2", "Float2", "Double2" },
["Rgba32"] = new[] { "Vector4", "Float4", "Double4" },
["Rgba64"] = new[] { "Vector4", "Float4", "Double4" }
};
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 Texture2DTests
{
[TestMethod]
<#
foreach (var (t, tPixel) in EnumerateTypes())
{
#>
[DataRow(typeof(<#=t#>), typeof(<#=tPixel#>))]
<#
}
#>
public void Dispatch_NormalizedTexture2D(Type t, Type tPixel)
{
<#
foreach (var (t, tPixel) in EnumerateTypes())
{
#>
if (t == typeof(<#=t#>) && tPixel == typeof(<#=tPixel#>))
{
using ReadOnlyTexture2D<<#=t#>, <#=tPixel#>> source = Gpu.Default.AllocateReadOnlyTexture2D<<#=t#>, <#=tPixel#>>(128, 128);
using ReadWriteTexture2D<<#=t#>, <#=tPixel#>> destination = Gpu.Default.AllocateReadWriteTexture2D<<#=t#>, <#=tPixel#>>(128, 128);
Gpu.Default.For(128, 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 ReadOnlyTexture2D<<#=t#>, <#=tPixel#>> source;
public readonly ReadWriteTexture2D<<#=t#>, <#=tPixel#>> destination;
public void Execute(ThreadIds ids)
{
destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2;
}
}
<#
}
#>
}
}