81 行
2.2 KiB
Plaintext
81 行
2.2 KiB
Plaintext
<#@ 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" },
|
|
["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;
|
|
}
|
|
}
|
|
<#
|
|
}
|
|
#>
|
|
}
|
|
} |