Merge pull request #93 from Sergio0694/experiment/ci

CI improvements
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2021-02-16 13:46:46 +01:00
コミット eb5cf26d8f
47ファイル変更
+1666 -782

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

+128 -1
ファイルの表示
@@ -3,6 +3,83 @@ name: .NET
on: [push, pull_request]
jobs:
# Build the ComputeSharp project directly. This is the project that
# would be built when running any of the local samples or unit tests.
build-project:
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Build
run: dotnet build src\ComputeSharp\ComputeSharp.csproj -c Release
shell: cmd
# Run all the unit tests referencing the ComputeSharp project directly.
run-tests:
if: success()
needs: [build-project]
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Run ComputeSharp.Tests
run: dotnet test tests\ComputeSharp.Tests\ComputeSharp.Tests.csproj -v n -l "console;verbosity=detailed"
shell: cmd
- name: Run ComputeSharp.Tests.Internals
run: dotnet test tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj -v n -l "console;verbosity=detailed"
shell: cmd
- name: Run ComputeSharp.Tests.Internals.SourceGenerators
run: dotnet test tests\ComputeSharp.Tests.Internals.SourceGenerators\ComputeSharp.Tests.Internals.SourceGenerators.csproj -v n -l "console;verbosity=detailed"
shell: cmd
# Run all the local samples to ensure they build and run with no errors.
run-samples:
if: success()
needs: [run-tests]
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Build ComputeSharp.Sample.Local
run: dotnet build samples\ComputeSharp.Sample.Local\ComputeSharp.Sample.Local.csproj -c Release
shell: cmd
- name: Run ComputeSharp.Sample.Local
run: dotnet samples\ComputeSharp.Sample.Local\bin\Release\net5.0\ComputeSharp.Sample.Local.dll
shell: cmd
- name: Build ComputeSharp.ImageProcessing.csproj
run: dotnet build samples\ComputeSharp.ImageProcessing\ComputeSharp.ImageProcessing.csproj -c Release
shell: cmd
- name: Run ComputeSharp.ImageProcessing.csproj
run: dotnet samples\ComputeSharp.ImageProcessing\bin\Release\net5.0\ComputeSharp.ImageProcessing.dll
shell: cmd
- name: Build ComputeSharp.Benchmark.csproj
run: dotnet build samples\ComputeSharp.Benchmark\ComputeSharp.Benchmark.csproj -c Release
shell: cmd
# Buils the .msbuildproj project to generate the NuGet package.
# This workflow also uploads the resulting package as an artifact.
build-package:
runs-on: windows-latest
steps:
@@ -22,4 +99,54 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: ComputeSharp.nupkg
path: src\ComputeSharp.Package\bin\Release\*.nupkg
path: src\ComputeSharp.Package\bin\Release\*.nupkg
# Download the NuGet package generated in the previous job and use it
# to build and run the sample project referencing it. This is used as
# a test to ensure the NuGet package works in a consuming project.
verify-package:
if: success()
needs: [build-package]
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Download package artifact
uses: actions/download-artifact@v2
with:
name: ComputeSharp.nupkg
path: src\ComputeSharp.Package\bin\Release\ComputeSharp.nupkg
- name: Build ComputeSharp.Sample.NuGet
run: dotnet build samples\ComputeSharp.Sample.NuGet\ComputeSharp.Sample.NuGet.csproj -c Release
shell: cmd
- name: Run ComputeSharp.Sample.NuGet
run: dotnet samples\ComputeSharp.Sample.NuGet\bin\Release\net5.0\ComputeSharp.Sample.NuGet.dll
shell: cmd
# Run the extra tests to validate a number of build and publishing configurations.
# This is used to ensure the native dependencies can always be loaded correctly
# regardless of whether the app is shipping with R2R, self-contained, etc.
verify-libs:
if: success()
needs: [verify-package]
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Run ComputeSharp.Tests.NativeLibrariesResolver
run: dotnet test tests\ComputeSharp.Tests.NativeLibrariesResolver\ComputeSharp.Tests.NativeLibrariesResolver.csproj -v n -l "console;verbosity=detailed"
shell: cmd
+1
ファイルの表示
@@ -3,5 +3,6 @@
<packageSources>
<add key="ComputeSharp-Local" value="src\ComputeSharp.Package\bin\Release" />
<add key="Toolkit-CI" value="https://pkgs.dev.azure.com/dotnet/WindowsCommunityToolkit/_packaging/WindowsCommunityToolkit-MainLatest/nuget/v3/index.json" />
<add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
</packageSources>
</configuration>
+1 -1
ファイルの表示
@@ -18,7 +18,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1.1514" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
</ItemGroup>
+18 -1
ファイルの表示
@@ -26,7 +26,7 @@ namespace ComputeSharp.BokehBlur.Processors
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
/// </summary>
public HlslBokehBlurProcessor()
: this(DefaultRadius, DefaultComponents)
: this(Gpu.Default, DefaultRadius, DefaultComponents)
{
}
@@ -36,11 +36,28 @@ namespace ComputeSharp.BokehBlur.Processors
/// <param name="radius">The size of the area to sample.</param>
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
public HlslBokehBlurProcessor(int radius, int components)
: this(Gpu.Default, radius, components)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="radius">The size of the area to sample.</param>
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
public HlslBokehBlurProcessor(GraphicsDevice device, int radius, int components)
{
GraphicsDevice = device;
Radius = radius;
Components = components;
}
/// <summary>
/// Gets the <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.
/// </summary>
public GraphicsDevice GraphicsDevice { get; }
/// <summary>
/// Gets the radius.
/// </summary>
+16 -10
ファイルの表示
@@ -20,6 +20,11 @@ namespace ComputeSharp.BokehBlur.Processors
/// <remarks>This processor is based on the code from Mike Pound, see <a href="https://github.com/mikepound/convolve">github.com/mikepound/convolve</a>.</remarks>
public sealed partial class Implementation : ImageProcessor<ImageSharpRgba32>
{
/// <summary>
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
/// </summary>
private readonly GraphicsDevice GraphicsDevice;
/// <summary>
/// The kernel radius.
/// </summary>
@@ -65,6 +70,7 @@ namespace ComputeSharp.BokehBlur.Processors
public Implementation(HlslBokehBlurProcessor definition, Configuration configuration, Image<ImageSharpRgba32> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{
GraphicsDevice = definition.GraphicsDevice;
Radius = definition.Radius;
KernelSize = Radius * 2 + 1;
ComponentsCount = definition.Components;
@@ -256,14 +262,14 @@ namespace ComputeSharp.BokehBlur.Processors
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
using ReadWriteTexture2D<Rgba32, Vector4> texture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
using ReadWriteTexture2D<Vector4> temporary = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height, AllocationMode.Clear);
using ReadWriteTexture2D<Vector4> reals = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
using ReadWriteTexture2D<Vector4> imaginaries = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
using ReadOnlyBuffer<Complex64> kernel = Gpu.Default.AllocateReadOnlyBuffer<Complex64>(KernelSize);
using ReadWriteTexture2D<Rgba32, Vector4> texture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
using ReadWriteTexture2D<Vector4> temporary = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height, AllocationMode.Clear);
using ReadWriteTexture2D<Vector4> reals = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
using ReadWriteTexture2D<Vector4> imaginaries = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
using ReadOnlyBuffer<Complex64> kernel = GraphicsDevice.AllocateReadOnlyBuffer<Complex64>(KernelSize);
// Preliminary gamma highlight pass
Gpu.Default.For<GammaHighlightProcessor>(source.Height, new(texture));
GraphicsDevice.For<GammaHighlightProcessor>(source.Height, new(texture));
// Perform two 1D convolutions for each component in the current instance
for (int j = 0; j < Kernels.Length; j++)
@@ -272,19 +278,19 @@ namespace ComputeSharp.BokehBlur.Processors
kernel.CopyFrom(Kernels[j]);
Gpu.Default.For<VerticalConvolutionProcessor>(
GraphicsDevice.For<VerticalConvolutionProcessor>(
source.Width,
source.Height,
new(texture, reals, imaginaries, kernel));
Gpu.Default.For<HorizontalConvolutionAndAccumulatePartialsProcessor>(
GraphicsDevice.For<HorizontalConvolutionAndAccumulatePartialsProcessor>(
source.Width,
source.Height,
new(parameters.Z, parameters.W, reals, imaginaries, temporary, kernel));
}
// Apply the inverse gamma exposure pass
Gpu.Default.For<InverseGammaHighlightProcessor>(source.Height, new(temporary, texture));
GraphicsDevice.For<InverseGammaHighlightProcessor>(source.Height, new(temporary, texture));
// Write the final pixel data
texture.CopyTo(span);
@@ -409,7 +415,7 @@ namespace ComputeSharp.BokehBlur.Processors
{
Float4 v = source[i, ThreadIds.X];
v.XYZ = Hlsl.Clamp(v.XYZ, 0, float.MaxValue);
v = Hlsl.Clamp(v, 0, float.MaxValue);
v.XYZ = Hlsl.Pow(v.XYZ, 1 / 3f);
target[i, ThreadIds.X] = v;
+26 -3
ファイルの表示
@@ -20,25 +20,48 @@ namespace ComputeSharp.BokehBlur.Processors
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
/// </summary>
public HlslGaussianBlurProcessor() : this(DefaultSigma, 9) { }
public HlslGaussianBlurProcessor()
: this(Gpu.Default, DefaultSigma, 9)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
/// </summary>
/// <param name="radius">The radius value representing the size of the area to sample.</param>
public HlslGaussianBlurProcessor(int radius) : this(radius / 3F, radius) { }
public HlslGaussianBlurProcessor(int radius)
: this(Gpu.Default, radius / 3F, radius)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="radius">The radius value representing the size of the area to sample.</param>
public HlslGaussianBlurProcessor(GraphicsDevice device, int radius)
: this(device, radius / 3F, radius)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="sigma"> The sigma value representing the weight of the blur. </param>
/// <param name="radius">The radius value representing the size of the area to sample (this should be at least twice the sigma value)</param>
public HlslGaussianBlurProcessor(float sigma, int radius)
public HlslGaussianBlurProcessor(GraphicsDevice device, float sigma, int radius)
{
GraphicsDevice = device;
Sigma = sigma;
Radius = radius;
}
/// <summary>
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
/// </summary>
private readonly GraphicsDevice GraphicsDevice;
/// <summary>
/// Gets the sigma value representing the weight of the blur.
/// </summary>
+12 -5
ファイルの表示
@@ -17,6 +17,11 @@ namespace ComputeSharp.BokehBlur.Processors
/// </summary>
internal sealed partial class Implementation : ImageProcessor<ImageSharpRgba32>
{
/// <summary>
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
/// </summary>
private readonly GraphicsDevice GraphicsDevice;
/// <summary>
/// The 1D kernel to apply.
/// </summary>
@@ -33,6 +38,8 @@ namespace ComputeSharp.BokehBlur.Processors
: base(configuration, source, sourceRectangle)
{
int kernelSize = definition.Radius * 2 + 1;
GraphicsDevice = definition.GraphicsDevice;
Kernel = CreateGaussianBlurKernel(kernelSize, definition.Sigma);
}
@@ -94,12 +101,12 @@ namespace ComputeSharp.BokehBlur.Processors
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
using ReadWriteTexture2D<Rgba32, Vector4> sourceTexture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
using ReadWriteTexture2D<Rgba32, Vector4> firstPassTexture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(source.Width, source.Height);
using ReadOnlyBuffer<float> kernelBuffer = Gpu.Default.AllocateReadOnlyBuffer(Kernel);
using ReadWriteTexture2D<Rgba32, Vector4> sourceTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
using ReadWriteTexture2D<Rgba32, Vector4> firstPassTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(source.Width, source.Height);
using ReadOnlyBuffer<float> kernelBuffer = GraphicsDevice.AllocateReadOnlyBuffer(Kernel);
Gpu.Default.For<VerticalConvolutionProcessor>(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
Gpu.Default.For<HorizontalConvolutionProcessor>(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer));
GraphicsDevice.For<VerticalConvolutionProcessor>(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
GraphicsDevice.For<HorizontalConvolutionProcessor>(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer));
sourceTexture.CopyTo(span);
}
+13 -10
ファイルの表示
@@ -18,24 +18,19 @@ namespace ComputeSharp.Sample
array[i] = i + 1;
}
// Print the initial matrix
Console.WriteLine("===================== BEFORE =====================");
PrintMatrix(array, width, height);
Console.WriteLine("==================================================");
Console.WriteLine();
using ReadWriteBuffer<float> gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array);
// Run the shader
Gpu.Default.For(100, new MainKernel(gpuBuffer));
// Print the initial matrix
PrintMatrix(array, width, height, "BEFORE");
// Get the data back
gpuBuffer.CopyTo(array);
// Print the updated matrix
Console.WriteLine("===================== AFTER ======================");
PrintMatrix(array, width, height);
Console.WriteLine("==================================================");
PrintMatrix(array, width, height, "AFTER");
}
/// <summary>
@@ -59,8 +54,14 @@ namespace ComputeSharp.Sample
/// <param name="array">The input <see langword="float"/> array representing the matrix to print.</param>
/// <param name="width">The width of the array to print.</param>
/// <param name="height">The height of the array to print.</param>
private static void PrintMatrix(float[] array, int width, int height)
/// <param name="name">The name of the matrix to print.</param>
private static void PrintMatrix(float[] array, int width, int height, string name)
{
int pad = 48 - name.Length;
string title = $"{new string('=', pad / 2)} {name} {new string('=', (pad + 1) / 2)}";
Console.WriteLine(title);
int length = width * height;
int numberWidth = array.Max().ToString(CultureInfo.InvariantCulture).Length;
ref float r = ref array[0];
@@ -73,6 +74,8 @@ namespace ComputeSharp.Sample
if (i < length - 1) Console.Write(", ");
if (i > 0 && (i + 1) % width == 0) Console.WriteLine();
}
Console.WriteLine(new string('=', 50));
}
}
}
+15
ファイルの表示
@@ -1,6 +1,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using ComputeSharp.Graphics.Helpers;
using Microsoft.Toolkit.Diagnostics;
using HRESULT = System.Int32;
@@ -20,10 +21,24 @@ namespace ComputeSharp.Core.Extensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Assert(this HRESULT result)
{
#if DEBUG
bool hasErrorsOrWarnings = DeviceHelper.FlushAllID3D12InfoQueueMessagesAndCheckForErrorsOrWarnings();
if (result < 0)
{
ThrowHelper.ThrowWin32Exception(result);
}
if (hasErrorsOrWarnings)
{
ThrowHelper.ThrowWin32Exception("Warning or error detected by ID3D12InfoQueue");
}
#else
if (result < 0)
{
ThrowHelper.ThrowWin32Exception(result);
}
#endif
}
}
}
+33 -7
ファイルの表示
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.Contracts;
using ComputeSharp.Core.Extensions;
using ComputeSharp.Graphics.Helpers;
using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop;
using static TerraFX.Interop.D3D12_COMMAND_QUEUE_FLAGS;
@@ -11,7 +12,7 @@ using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_TYPE;
using static TerraFX.Interop.D3D12_FEATURE;
using static TerraFX.Interop.D3D12_FENCE_FLAGS;
using static TerraFX.Interop.D3D12_MEMORY_POOL;
using static TerraFX.Interop.D3D12_HEAP_FLAGS;
using static TerraFX.Interop.D3D12_MESSAGE_ID;
using static TerraFX.Interop.D3D12_HEAP_TYPE;
using static TerraFX.Interop.D3D12_RESOURCE_FLAGS;
using static TerraFX.Interop.D3D12_RESOURCE_STATES;
@@ -27,6 +28,34 @@ namespace ComputeSharp.Graphics.Extensions
/// </summary>
internal static unsafe class ID3D12DeviceExtensions
{
/// <summary>
/// Creates a new <see cref="ID3D12InfoQueue"/> for a given device.
/// </summary>
/// <param name="d3D12Device">The target <see cref="ID3D12Device"/> to use to create the info queue.</param>
/// <returns>A pointer to the newly created <see cref="ID3D12InfoQueue"/> instance.</returns>
/// <exception cref="Exception">Thrown when the creation of the info queue fails.</exception>
public static ComPtr<ID3D12InfoQueue> CreateInfoQueue(this ref ID3D12Device d3D12Device)
{
ComPtr<ID3D12InfoQueue> d3D12InfoQueue = default;
d3D12Device.QueryInterface(FX.__uuidof<ID3D12InfoQueue>(), d3D12InfoQueue.GetVoidAddressOf()).Assert();
D3D12_MESSAGE_ID* d3D12MessageIds = stackalloc D3D12_MESSAGE_ID[3]
{
D3D12_MESSAGE_ID_CREATEDEVICE_DEBUG_LAYER_STARTUP_OPTIONS,
D3D12_MESSAGE_ID_MAP_INVALID_NULLRANGE,
D3D12_MESSAGE_ID_UNMAP_INVALID_NULLRANGE
};
D3D12_INFO_QUEUE_FILTER d3D12InfoQueueFilter = default;
d3D12InfoQueueFilter.DenyList.NumIDs = 3;
d3D12InfoQueueFilter.DenyList.pIDList = d3D12MessageIds;
d3D12InfoQueue.Get()->PushRetrievalFilter(&d3D12InfoQueueFilter).Assert();
return d3D12InfoQueue.Move();
}
/// <summary>
/// Creates a new <see cref="ID3D12CommandQueue"/> of the specified type, for a given device.
/// </summary>
@@ -112,7 +141,6 @@ namespace ComputeSharp.Graphics.Extensions
ulong sizeInBytes,
bool isCacheCoherentUMA)
{
D3D12_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
(D3D12_HEAP_TYPE d3D12HeapType,
D3D12_RESOURCE_FLAGS d3D12ResourceFlags,
D3D12_RESOURCE_STATES d3D12ResourceStates) = resourceType switch
@@ -148,7 +176,7 @@ namespace ComputeSharp.Graphics.Extensions
d3D12Device.CreateCommittedResource(
&d3D12HeapProperties,
d3D12HeapFlags,
D3D12FeatureHelper.GetD3D12HeapFlags(allocationMode),
&d3D12ResourceDescription,
d3D12ResourceStates,
null,
@@ -180,7 +208,6 @@ namespace ComputeSharp.Graphics.Extensions
bool isCacheCoherentUMA,
out D3D12_RESOURCE_STATES d3D12ResourceStates)
{
D3D12_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
(d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
@@ -213,7 +240,7 @@ namespace ComputeSharp.Graphics.Extensions
d3D12Device.CreateCommittedResource(
&d3D12HeapProperties,
d3D12HeapFlags,
D3D12FeatureHelper.GetD3D12HeapFlags(allocationMode),
&d3D12ResourceDescription,
d3D12ResourceStates,
null,
@@ -247,7 +274,6 @@ namespace ComputeSharp.Graphics.Extensions
bool isCacheCoherentUMA,
out D3D12_RESOURCE_STATES d3D12ResourceStates)
{
D3D12_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
(d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
@@ -280,7 +306,7 @@ namespace ComputeSharp.Graphics.Extensions
d3D12Device.CreateCommittedResource(
&d3D12HeapProperties,
d3D12HeapFlags,
D3D12FeatureHelper.GetD3D12HeapFlags(allocationMode),
&d3D12ResourceDescription,
d3D12ResourceStates,
null,
+18
ファイルの表示
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using ComputeSharp.Core.Extensions;
using ComputeSharp.Graphics.Resources.Interop;
@@ -38,5 +39,22 @@ namespace ComputeSharp.Graphics.Extensions
{
d3D12Resource.Unmap(0, null);
}
/// <summary>
/// Assigns a name to a given <see cref="ID3D12Resource"/>.
/// </summary>
/// <param name="d3D12Resource">The target <see cref="ID3D12Resource"/> to map.</param>
/// <param name="wrapper">The wrapper object to get the name from.</param>
/// <exception cref="Exception">Thrown when the mapping operation fails.</exception>
[Conditional("DEBUG")]
public static void SetName(this ref ID3D12Resource d3D12Resource, object wrapper)
{
string name = wrapper.ToString()!;
fixed (char* p = name)
{
d3D12Resource.SetName((ushort*)p).Assert();
}
}
}
}
+66
ファイルの表示
@@ -0,0 +1,66 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using TerraFX.Interop;
using static TerraFX.Interop.D3D12_FEATURE;
using FX = TerraFX.Interop.Windows;
namespace ComputeSharp.Graphics.Helpers
{
/// <summary>
/// A helper <see langword="class"/> exposing some runtime or OS dependent D3D12 features.
/// </summary>
internal static class D3D12FeatureHelper
{
/// <summary>
/// The currently supported <see cref="D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_CREATE_NOT_ZEROED"/> flag (or fallback).
/// </summary>
private static readonly D3D12_HEAP_FLAGS D3D12_HEAP_FLAG_CREATE_NOT_ZEROED = GetD3D12_HEAP_FLAG_CREATE_NOT_ZEROED();
/// <summary>
/// Gets the <see cref="D3D12_HEAP_FLAGS"/> value for a given <see cref="AllocationMode"/> setting.
/// </summary>
/// <param name="allocationMode">The allocation mode to use for creating new resources.</param>
/// <returns>The <see cref="D3D12_HEAP_FLAGS"/> matching <paramref name="allocationMode"/> that is currently supported</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static D3D12_HEAP_FLAGS GetD3D12HeapFlags(AllocationMode allocationMode)
{
if (allocationMode == AllocationMode.Default)
{
return D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
}
return D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_NONE;
}
/// <summary>
/// Initializes the <see cref="D3D12_HEAP_FLAG_CREATE_NOT_ZEROED"/> field.
/// </summary>
/// <returns>The currently supported <see cref="D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_CREATE_NOT_ZEROED"/> flag.</returns>
private static unsafe D3D12_HEAP_FLAGS GetD3D12_HEAP_FLAG_CREATE_NOT_ZEROED()
{
lock (DeviceHelper.DevicesCache)
{
foreach (KeyValuePair<Luid, GraphicsDevice> pair in DeviceHelper.DevicesCache)
{
D3D12_FEATURE_DATA_D3D12_OPTIONS7 d3D12Options7;
int result = pair.Value.D3D12Device->CheckFeatureSupport(
D3D12_FEATURE_D3D12_OPTIONS7,
&d3D12Options7,
(uint)sizeof(D3D12_FEATURE_DATA_D3D12_OPTIONS7));
if (result == FX.S_OK)
{
return D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
}
break;
}
return D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_NONE;
}
}
}
}
+21 -1
ファイルの表示
@@ -1,4 +1,7 @@
using System.Collections.Generic;
#if DEBUG
using ComputeSharp.Graphics.Extensions;
#endif
using TerraFX.Interop;
namespace ComputeSharp.Graphics.Helpers
@@ -9,7 +12,14 @@ namespace ComputeSharp.Graphics.Helpers
/// <summary>
/// The local cache of <see cref="GraphicsDevice"/> instances that are currently usable.
/// </summary>
private static readonly Dictionary<Luid, GraphicsDevice> DevicesCache = new();
internal static readonly Dictionary<Luid, GraphicsDevice> DevicesCache = new();
#if DEBUG
/// <summary>
/// The local map of <see cref="ID3D12InfoQueue"/> instances for the existing devices.
/// </summary>
private static readonly Dictionary<Luid, ComPtr<ID3D12InfoQueue>> D3D12InfoQueueMap = new();
#endif
/// <summary>
/// Retrieves a <see cref="GraphicsDevice"/> instance for an <see cref="ID3D12Device"/> object.
@@ -28,6 +38,10 @@ namespace ComputeSharp.Graphics.Helpers
device = new GraphicsDevice(d3D12Device, dxgiDescription1);
DevicesCache.Add(luid, device);
#if DEBUG
D3D12InfoQueueMap.Add(luid, d3D12Device.Get()->CreateInfoQueue());
#endif
}
return device;
@@ -43,6 +57,12 @@ namespace ComputeSharp.Graphics.Helpers
lock (DevicesCache)
{
DevicesCache.Remove(device.Luid);
#if DEBUG
D3D12InfoQueueMap.Remove(device.Luid, out ComPtr<ID3D12InfoQueue> queue);
queue.Dispose();
#endif
}
}
}
+82
ファイルの表示
@@ -0,0 +1,82 @@
#if DEBUG
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using TerraFX.Interop;
using static TerraFX.Interop.D3D12_MESSAGE_SEVERITY;
namespace ComputeSharp.Graphics.Helpers
{
/// <inheritdoc/>
internal static partial class DeviceHelper
{
/// <summary>
/// Flushes all the pending debug messages for all existing <see cref="ID3D12Device"/> instances to the console/debugger.
/// It also checks whether or not there are any error messages being logged that didn't result in an actual crash yet.
/// </summary>
/// <return>Whether or not there are any logged errors or warnings.</return>
public static unsafe bool FlushAllID3D12InfoQueueMessagesAndCheckForErrorsOrWarnings()
{
bool hasErrorsOrWarnings = false;
lock (DevicesCache)
{
int j = 0;
StringBuilder builder = new(1024);
foreach (var pair in D3D12InfoQueueMap)
{
var device = DevicesCache[pair.Key];
var queue = pair.Value;
ulong messages = queue.Get()->GetNumStoredMessagesAllowedByRetrievalFilter();
for (ulong i = 0; i < messages; i++)
{
nuint length;
queue.Get()->GetMessage(i, null, &length);
D3D12_MESSAGE* message = (D3D12_MESSAGE*)Marshal.AllocHGlobal((nint)length);
queue.Get()->GetMessage(i, message, &length);
builder.Clear();
builder.AppendLine($"[D3D12 message #{i} for \"{device}\" (HW: {device.IsHardwareAccelerated}, UMA: {device.IsCacheCoherentUMA})]");
builder.AppendLine($"[Category]: {Enum.GetName(message->Category)}");
builder.AppendLine($"[Severity]: {Enum.GetName(message->Severity)}");
builder.AppendLine($"[ID]: {Enum.GetName(message->ID)}");
builder.Append($"[Description]: \"{new string(message->pDescription)}\"");
Marshal.FreeHGlobal((IntPtr)message);
if (message->Severity is D3D12_MESSAGE_SEVERITY_ERROR or D3D12_MESSAGE_SEVERITY_CORRUPTION or D3D12_MESSAGE_SEVERITY_WARNING)
{
hasErrorsOrWarnings = true;
}
string text = builder.ToString();
if (Debugger.IsAttached)
{
Debug.WriteLine(text);
}
else
{
Console.WriteLine(text);
}
}
queue.Get()->ClearStoredMessages();
j++;
}
}
return hasErrorsOrWarnings;
}
}
}
#endif
+15 -26
ファイルの表示
@@ -8,29 +8,6 @@ namespace ComputeSharp.Graphics.Helpers
/// </summary>
internal static class MemoryHelper
{
/// <summary>
/// Copies the content of a source memory area to a target one.
/// </summary>
/// <param name="source">The source memory area to read from.</param>
/// <param name="destination">The pointer for the destination memory area.</param>
/// <param name="offset">The destination offset to start writing data to.</param>
/// <param name="length">The number of items to copy.</param>
/// <param name="elementSizeInBytes">The size in bytes of each item to copy.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void Copy(
void* source,
void* destination,
uint offset,
uint length,
uint elementSizeInBytes)
{
Buffer.MemoryCopy(
source,
(byte*)destination + offset * elementSizeInBytes,
ulong.MaxValue,
elementSizeInBytes * length);
}
/// <summary>
/// Copies the content of a source memory area to a target one, accounting for padding.
/// The destination memory area has padding for each element, while the source does not.
@@ -40,19 +17,31 @@ namespace ComputeSharp.Graphics.Helpers
/// <param name="offset">The destination offset to start writing data to.</param>
/// <param name="length">The number of items to copy.</param>
/// <param name="elementPitchInBytes">The padded size of each element.</param>
/// <param name="isPaddingInSourceToo">Indicates whether or not the source is padded too.</param>
public static unsafe void Copy<T>(
void* source,
void* destination,
uint offset,
uint length,
uint elementPitchInBytes)
uint elementPitchInBytes,
bool isPaddingInSourceToo)
where T : unmanaged
{
destination = (byte*)destination + offset * elementPitchInBytes;
for (int i = 0; i < length; i++)
if (isPaddingInSourceToo)
{
*(T*)&((byte*)destination)[i * elementPitchInBytes] = ((T*)source)[i];
for (int i = 0; i < length; i++)
{
*(T*)&((byte*)destination)[i * elementPitchInBytes] = *(T*)&((byte*)source)[i * elementPitchInBytes];
}
}
else
{
for (int i = 0; i < length; i++)
{
*(T*)&((byte*)destination)[i * elementPitchInBytes] = ((T*)source)[i];
}
}
}
+2
ファイルの表示
@@ -80,6 +80,8 @@ namespace ComputeSharp.Resources
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, D3D12CpuDescriptorHandle);
break;
}
this.d3D12Resource.Get()->SetName(this);
}
/// <summary>
+47 -17
ファイルの表示
@@ -101,15 +101,29 @@ namespace ComputeSharp.Resources
Guard.IsInRange(destinationOffset, 0, destination.Length, nameof(destinationOffset));
Guard.IsLessThanOrEqualTo(destinationOffset + length, destination.Length, nameof(length));
ulong
byteDestinationOffset = (uint)destinationOffset * (uint)sizeof(T),
byteOffset = (uint)offset * (uint)sizeof(T),
byteLength = (uint)length * (uint)sizeof(T);
if (GraphicsDevice.IsCacheCoherentUMA)
{
using ID3D12ResourceMap resource = D3D12Resource->Map();
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
MemoryHelper.Copy(
resource.Pointer,
(uint)offset,
(uint)length,
(uint)sizeof(T),
destination.MappedData + destinationOffset);
}
else
{
ulong
byteDestinationOffset = (uint)destinationOffset * (uint)sizeof(T),
byteOffset = (uint)offset * (uint)sizeof(T),
byteLength = (uint)length * (uint)sizeof(T);
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(destination.D3D12Resource, byteDestinationOffset, D3D12Resource, byteOffset, byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(destination.D3D12Resource, byteDestinationOffset, D3D12Resource, byteOffset, byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
}
}
/// <inheritdoc/>
@@ -183,15 +197,29 @@ namespace ComputeSharp.Resources
Guard.IsInRange(sourceOffset, 0, source.Length, nameof(sourceOffset));
Guard.IsLessThanOrEqualTo(sourceOffset + length, source.Length, nameof(length));
ulong
byteSourceOffset = (uint)sourceOffset * (uint)sizeof(T),
byteOffset = (uint)offset * (uint)sizeof(T),
byteLength = (uint)length * (uint)sizeof(T);
if (GraphicsDevice.IsCacheCoherentUMA)
{
using ID3D12ResourceMap resource = D3D12Resource->Map();
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
MemoryHelper.Copy(
source.MappedData,
(uint)sourceOffset,
(uint)length,
(uint)sizeof(T),
(T*)resource.Pointer + offset);
}
else
{
ulong
byteSourceOffset = (uint)sourceOffset * (uint)sizeof(T),
byteOffset = (uint)offset * (uint)sizeof(T),
byteLength = (uint)length * (uint)sizeof(T);
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, byteOffset, source.D3D12Resource, byteSourceOffset, byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, byteOffset, source.D3D12Resource, byteSourceOffset, byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
}
}
/// <inheritdoc/>
@@ -199,12 +227,14 @@ namespace ComputeSharp.Resources
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDeviceMismatch(source.GraphicsDevice);
ThrowIfDisposed();
source.ThrowIfDeviceMismatch(GraphicsDevice);
source.ThrowIfDisposed();
if (!source.IsPaddingPresent &&
source.GraphicsDevice == GraphicsDevice)
Guard.IsLessThanOrEqualTo(source.Length, Length, nameof(Length));
if (!source.IsPaddingPresent)
{
// Directly copy the input buffer
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
+2
ファイルの表示
@@ -111,6 +111,8 @@ namespace ComputeSharp.Resources
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE2D, D3D12CpuDescriptorHandle);
break;
}
this.d3D12Resource.Get()->SetName(this);
}
/// <summary>
+2
ファイルの表示
@@ -115,6 +115,8 @@ namespace ComputeSharp.Resources
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE3D, D3D12CpuDescriptorHandle);
break;
}
this.d3D12Resource.Get()->SetName(this);
}
/// <summary>
+7
ファイルの表示
@@ -48,6 +48,8 @@ namespace ComputeSharp.Resources
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, allocationMode, sizeInBytes, device.IsCacheCoherentUMA);
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.d3D12Resource.Get()->SetName(this);
}
/// <summary>
@@ -65,6 +67,11 @@ namespace ComputeSharp.Resources
/// </summary>
internal ID3D12Resource* D3D12Resource => this.d3D12Resource;
/// <summary>
/// Gets the pointer to the start of the mapped buffer data.
/// </summary>
internal T* MappedData => this.mappedData;
/// <inheritdoc/>
public Memory<T> Memory
{
+2
ファイルの表示
@@ -65,6 +65,8 @@ namespace ComputeSharp.Resources
this.d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(resourceType, allocationMode, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.d3D12Resource.Get()->SetName(this);
}
/// <summary>
+2
ファイルの表示
@@ -68,6 +68,8 @@ namespace ComputeSharp.Resources
this.d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(resourceType, allocationMode, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.d3D12Resource.Get()->SetName(this);
}
/// <summary>
+29 -11
ファイルの表示
@@ -3,7 +3,6 @@ using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using ComputeSharp.Core.Helpers;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Commands;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Graphics.Resources.Enums;
@@ -11,7 +10,6 @@ using ComputeSharp.Graphics.Resources.Interop;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Debug;
using Microsoft.Toolkit.Diagnostics;
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
using FX = TerraFX.Interop.Windows;
namespace ComputeSharp
@@ -114,7 +112,8 @@ namespace ComputeSharp
resource.Pointer,
(uint)offset,
(uint)size,
(uint)GetPaddedSize());
(uint)GetPaddedSize(),
isPaddingInSourceToo: false);
}
else
{
@@ -133,18 +132,37 @@ namespace ComputeSharp
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDeviceMismatch(source.GraphicsDevice);
ThrowIfDisposed();
source.ThrowIfDeviceMismatch(GraphicsDevice);
source.ThrowIfDisposed();
if (source is ConstantBuffer<T> &&
source.GraphicsDevice == GraphicsDevice)
{
// Directly copy the input buffer, if possible
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
Guard.IsLessThanOrEqualTo(source.Length, Length, nameof(Length));
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, 0, source.D3D12Resource, 0,(ulong)SizeInBytes);
copyCommandList.ExecuteAndWaitForCompletion();
if (source is ConstantBuffer<T> buffer)
{
using ID3D12ResourceMap sourceMap = buffer.D3D12Resource->Map();
using ID3D12ResourceMap destinationMap = D3D12Resource->Map();
if (IsPaddingPresent)
{
MemoryHelper.Copy<T>(
sourceMap.Pointer,
destinationMap.Pointer,
0,
(uint)source.Length,
(uint)GetPaddedSize(),
isPaddingInSourceToo: true);
}
else
{
MemoryHelper.Copy(
sourceMap.Pointer,
0,
(uint)source.Length,
(uint)sizeof(T),
destinationMap.Pointer);
}
}
else CopyFromWithCpuBuffer(source);
}
+1 -1
ファイルの表示
@@ -48,7 +48,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" PrivateAssets="all" Pack="false" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" Pack="false" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3-beta1.21109.6" PrivateAssets="all" Pack="false" />
</ItemGroup>
</Project>
+12
ファイルの表示
@@ -0,0 +1,12 @@
using System;
namespace ComputeSharp.Tests.Attributes
{
/// <summary>
/// An attribute to use with <see cref="CombinatorialAttribute"/> targeting all supported devices.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class AllDevicesAttribute : Attribute
{
}
}
+118
ファイルの表示
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.Tests.Attributes
{
/// <summary>
/// A custom <see cref="TestMethodAttribute"/> implementation that also acts as a combinatorial <see cref="ITestDataSource"/>
/// instance. It has dedicated paths for target devices and resource types, and arbitrary inputs for the test methods.
/// </summary>
/// <remarks>
/// Use this attribute in combination with <see cref="DeviceAttribute"/>, <see cref="AllDevicesAttribute"/>,
/// <see cref="ResourceAttribute"/> or <see cref="DataAttribute"/>, not other existing MSTest attributes.
/// </remarks>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITestDataSource
{
/// <inheritdoc/>
IEnumerable<object[]> ITestDataSource.GetData(MethodInfo methodInfo)
{
Device[] devices;
if (methodInfo.GetCustomAttribute<AllDevicesAttribute>() is not null)
{
devices = Enum.GetValues<Device>();
}
else if (methodInfo.GetCustomAttributes<DeviceAttribute>().ToArray() is { Length: > 0 } values)
{
devices = values.Select(static value => value.Device).ToArray();
}
else
{
devices = Array.Empty<Device>();
}
Type[] resources = methodInfo.GetCustomAttributes<ResourceAttribute>().Select(static value => value.Type).ToArray();
object[][] data = methodInfo.GetCustomAttributes<DataAttribute>().Select(static value => value.Data).ToArray();
if (devices.Length > 0)
{
foreach (Device device in devices)
{
if (resources.Length > 0)
{
foreach (Type type in resources)
{
if (data.Length == 0)
{
yield return new object[] { device, type };
}
else
{
foreach (object[] items in data)
{
yield return new object[] { device, type }.Concat(items).ToArray();
}
}
}
}
else
{
if (data.Length == 0)
{
yield return new object[] { device };
}
else
{
foreach (object[] items in data)
{
yield return new object[] { device }.Concat(items).ToArray();
}
}
}
}
}
else if (resources.Length > 0)
{
foreach (Type type in resources)
{
if (data.Length == 0)
{
yield return new object[] { type };
}
else
{
foreach (object[] items in data)
{
yield return new object[] { type }.Concat(items).ToArray();
}
}
}
}
else
{
if (data.Length == 0)
{
yield return Array.Empty<object>();
}
else
{
foreach (object[] items in data)
{
yield return items;
}
}
}
}
/// <inheritdoc/>
string ITestDataSource.GetDisplayName(MethodInfo methodInfo, object[] data)
{
return $"{methodInfo.Name} ({string.Join(", ", data)})";
}
}
}
+21
ファイルの表示
@@ -0,0 +1,21 @@
using System;
namespace ComputeSharp.Tests.Attributes
{
/// <summary>
/// An attribute to use with <see cref="CombinatorialAttribute"/> adding arbitrary input data.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class DataAttribute : Attribute
{
public DataAttribute(params object[] data)
{
Data = data;
}
/// <summary>
/// Gets the input data for the current attribute.
/// </summary>
public object[] Data { get; }
}
}
+22
ファイルの表示
@@ -0,0 +1,22 @@
using System;
using ComputeSharp.Tests.Extensions;
namespace ComputeSharp.Tests.Attributes
{
/// <summary>
/// An attribute to use with <see cref="CombinatorialAttribute"/> adding a specific <see cref="Extensions.Device"/> input.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class DeviceAttribute : Attribute
{
public DeviceAttribute(Device device)
{
Device = device;
}
/// <summary>
/// Gets the <see cref="Extensions.Device"/> target to use.
/// </summary>
public Device Device { get; }
}
}
+18
ファイルの表示
@@ -0,0 +1,18 @@
using System;
namespace ComputeSharp.Tests.Attributes
{
/// <summary>
/// An attribute to use with <see cref="CombinatorialAttribute"/> targeting a specific resource type.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class ResourceAttribute : Attribute
{
public ResourceAttribute(Type type)
{
Type = type;
}
public Type Type { get; }
}
}
+108 -121
ファイルの表示
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using ComputeSharp.Resources;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -10,45 +11,47 @@ namespace ComputeSharp.Tests
[TestCategory("Buffer")]
public partial class BufferTests
{
[TestMethod]
[DataRow(typeof(ConstantBuffer<>))]
[DataRow(typeof(ReadOnlyBuffer<>))]
[DataRow(typeof(ReadWriteBuffer<>))]
public void Allocate_Uninitialized_Ok(Type bufferType)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ConstantBuffer<>))]
[Resource(typeof(ReadOnlyBuffer<>))]
[Resource(typeof(ReadWriteBuffer<>))]
public void Allocate_Uninitialized_Ok(Device device, Type bufferType)
{
using Buffer<float> buffer = Gpu.Default.AllocateBuffer<float>(bufferType, 128);
using Buffer<float> buffer = device.Get().AllocateBuffer<float>(bufferType, 128);
Assert.IsNotNull(buffer);
Assert.AreEqual(buffer.Length, 128);
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
Assert.AreSame(buffer.GraphicsDevice, device.Get());
}
[TestMethod]
[DataRow(typeof(ConstantBuffer<>), -247824)]
[DataRow(typeof(ConstantBuffer<>), -1)]
[DataRow(typeof(ReadOnlyBuffer<>), -247824)]
[DataRow(typeof(ReadOnlyBuffer<>), -1)]
[DataRow(typeof(ReadWriteBuffer<>), -247824)]
[DataRow(typeof(ReadWriteBuffer<>), -1)]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ConstantBuffer<>))]
[Resource(typeof(ReadOnlyBuffer<>))]
[Resource(typeof(ReadWriteBuffer<>))]
[Data(-247824)]
[Data(-1)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Allocate_Uninitialized_Fail(Type bufferType, int length)
public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int length)
{
using Buffer<float> buffer = Gpu.Default.AllocateBuffer<float>(bufferType, length);
using Buffer<float> buffer = device.Get().AllocateBuffer<float>(bufferType, length);
}
[TestMethod]
[DataRow(typeof(ConstantBuffer<>))]
[DataRow(typeof(ReadOnlyBuffer<>))]
[DataRow(typeof(ReadWriteBuffer<>))]
public void Allocate_FromArray(Type bufferType)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ConstantBuffer<>))]
[Resource(typeof(ReadOnlyBuffer<>))]
[Resource(typeof(ReadWriteBuffer<>))]
public void Allocate_FromArray(Device device, Type bufferType)
{
float[] data = Enumerable.Range(0, 128).Select(static i => (float)i).ToArray();
using Buffer<float> buffer = Gpu.Default.AllocateBuffer(bufferType, data);
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, data);
Assert.IsNotNull(buffer);
Assert.AreEqual(buffer.Length, 128);
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
Assert.AreSame(buffer.GraphicsDevice, device.Get());
float[] result = buffer.ToArray();
@@ -57,26 +60,24 @@ namespace ComputeSharp.Tests
Assert.IsTrue(data.SequenceEqual(result));
}
[TestMethod]
[DataRow(typeof(ConstantBuffer<>), typeof(ConstantBuffer<>))]
[DataRow(typeof(ConstantBuffer<>), typeof(ReadOnlyBuffer<>))]
[DataRow(typeof(ConstantBuffer<>), typeof(ReadWriteBuffer<>))]
[DataRow(typeof(ReadOnlyBuffer<>), typeof(ConstantBuffer<>))]
[DataRow(typeof(ReadOnlyBuffer<>), typeof(ReadOnlyBuffer<>))]
[DataRow(typeof(ReadOnlyBuffer<>), typeof(ReadWriteBuffer<>))]
[DataRow(typeof(ReadWriteBuffer<>), typeof(ConstantBuffer<>))]
[DataRow(typeof(ReadWriteBuffer<>), typeof(ReadOnlyBuffer<>))]
[DataRow(typeof(ReadWriteBuffer<>), typeof(ReadWriteBuffer<>))]
public void Allocate_FromBuffer(Type sourceType, Type destinationType)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ConstantBuffer<>))]
[Resource(typeof(ReadOnlyBuffer<>))]
[Resource(typeof(ReadWriteBuffer<>))]
[Data(typeof(ConstantBuffer<>))]
[Data(typeof(ReadOnlyBuffer<>))]
[Data(typeof(ReadWriteBuffer<>))]
public void Allocate_FromBuffer(Device device, Type sourceType, Type destinationType)
{
float[] data = Enumerable.Range(0, 128).Select(static i => (float)i).ToArray();
using Buffer<float> source = Gpu.Default.AllocateBuffer(sourceType, data);
using Buffer<float> destination = Gpu.Default.AllocateBuffer(destinationType, source);
using Buffer<float> source = device.Get().AllocateBuffer(sourceType, data);
using Buffer<float> destination = device.Get().AllocateBuffer(destinationType, source);
Assert.IsNotNull(destination);
Assert.AreEqual(destination.Length, 128);
Assert.AreSame(destination.GraphicsDevice, Gpu.Default);
Assert.AreSame(destination.GraphicsDevice, device.Get());
float[] result = destination.ToArray();
@@ -85,35 +86,34 @@ namespace ComputeSharp.Tests
Assert.IsTrue(data.SequenceEqual(result));
}
[TestMethod]
[DataRow(typeof(ConstantBuffer<>))]
[DataRow(typeof(ReadOnlyBuffer<>))]
[DataRow(typeof(ReadWriteBuffer<>))]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ConstantBuffer<>))]
[Resource(typeof(ReadOnlyBuffer<>))]
[Resource(typeof(ReadWriteBuffer<>))]
[ExpectedException(typeof(ObjectDisposedException))]
public void UsageAfterDispose(Type bufferType)
public void UsageAfterDispose(Device device, Type bufferType)
{
using Buffer<float> buffer = Gpu.Default.AllocateBuffer<float>(bufferType, 128);
using Buffer<float> buffer = device.Get().AllocateBuffer<float>(bufferType, 128);
buffer.Dispose();
_ = buffer.ToArray();
}
[TestMethod]
[DataRow(typeof(ConstantBuffer<>), 0, 4096)]
[DataRow(typeof(ConstantBuffer<>), 128, 512)]
[DataRow(typeof(ConstantBuffer<>), 2048, 2048)]
[DataRow(typeof(ReadOnlyBuffer<>), 0, 4096)]
[DataRow(typeof(ReadOnlyBuffer<>), 128, 512)]
[DataRow(typeof(ReadOnlyBuffer<>), 2048, 2048)]
[DataRow(typeof(ReadWriteBuffer<>), 0, 4096)]
[DataRow(typeof(ReadWriteBuffer<>), 128, 512)]
[DataRow(typeof(ReadWriteBuffer<>), 2048, 2048)]
public void CopyTo_RangeToArray_Ok(Type bufferType, int offset, int count)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ConstantBuffer<>))]
[Resource(typeof(ReadOnlyBuffer<>))]
[Resource(typeof(ReadWriteBuffer<>))]
[Data(0, 4096)]
[Data(128, 512)]
[Data(2048, 2048)]
public void CopyTo_RangeToArray_Ok(Device device, Type bufferType, int offset, int count)
{
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
using Buffer<float> buffer = Gpu.Default.AllocateBuffer(bufferType, array);
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, array);
float[] result = buffer.ToArray(offset, count);
@@ -122,47 +122,39 @@ namespace ComputeSharp.Tests
Assert.IsTrue(array.AsSpan(offset, count).SequenceEqual(result));
}
[TestMethod]
[DataRow(typeof(ConstantBuffer<>), -1, 128)]
[DataRow(typeof(ConstantBuffer<>), 8192, 128)]
[DataRow(typeof(ConstantBuffer<>), 512, 4096)]
[DataRow(typeof(ConstantBuffer<>), 512, -128)]
[DataRow(typeof(ReadOnlyBuffer<>), -1, 128)]
[DataRow(typeof(ReadOnlyBuffer<>), 8192, 128)]
[DataRow(typeof(ReadOnlyBuffer<>), 512, 4096)]
[DataRow(typeof(ReadOnlyBuffer<>), 512, -128)]
[DataRow(typeof(ReadWriteBuffer<>), -1, 128)]
[DataRow(typeof(ReadWriteBuffer<>), 8192, 128)]
[DataRow(typeof(ReadWriteBuffer<>), 512, 4096)]
[DataRow(typeof(ReadWriteBuffer<>), 512, -128)]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ConstantBuffer<>))]
[Resource(typeof(ReadOnlyBuffer<>))]
[Resource(typeof(ReadWriteBuffer<>))]
[Data(-1, 128)]
[Data(8192, 128)]
[Data(512, 4096)]
[Data(512, -128)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void CopyTo_RangeToArray_Fail(Type bufferType, int offset, int count)
public void CopyTo_RangeToArray_Fail(Device device, Type bufferType, int offset, int count)
{
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
using Buffer<float> buffer = Gpu.Default.AllocateBuffer(bufferType, array);
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, array);
_ = buffer.ToArray(offset, count);
}
[TestMethod]
[DataRow(typeof(ConstantBuffer<>), 0, 0, 4096)]
[DataRow(typeof(ConstantBuffer<>), 512, 0, 2048)]
[DataRow(typeof(ConstantBuffer<>), 0, 512, 2048)]
[DataRow(typeof(ConstantBuffer<>), 127, 1024, 587)]
[DataRow(typeof(ReadOnlyBuffer<>), 0, 0, 4096)]
[DataRow(typeof(ReadOnlyBuffer<>), 512, 0, 2048)]
[DataRow(typeof(ReadOnlyBuffer<>), 0, 512, 2048)]
[DataRow(typeof(ReadOnlyBuffer<>), 127, 1024, 587)]
[DataRow(typeof(ReadWriteBuffer<>), 0, 0, 4096)]
[DataRow(typeof(ReadWriteBuffer<>), 512, 0, 2048)]
[DataRow(typeof(ReadWriteBuffer<>), 0, 512, 2048)]
[DataRow(typeof(ReadWriteBuffer<>), 127, 1024, 587)]
public void CopyTo_RangeToVoid_Ok(Type bufferType, int destinationOffset, int bufferOffset, int count)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ConstantBuffer<>))]
[Resource(typeof(ReadOnlyBuffer<>))]
[Resource(typeof(ReadWriteBuffer<>))]
[Data(0, 0, 4096)]
[Data(512, 0, 2048)]
[Data(0, 512, 2048)]
[Data(127, 1024, 587)]
public void CopyTo_RangeToVoid_Ok(Device device, Type bufferType, int destinationOffset, int bufferOffset, int count)
{
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
using Buffer<float> buffer = Gpu.Default.AllocateBuffer(bufferType, array);
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, array);
float[] result = new float[4096];
@@ -171,46 +163,39 @@ namespace ComputeSharp.Tests
Assert.IsTrue(array.AsSpan(bufferOffset, count).SequenceEqual(result.AsSpan(destinationOffset, count)));
}
[TestMethod]
[DataRow(typeof(ConstantBuffer<>), 0, 0, 8196)]
[DataRow(typeof(ConstantBuffer<>), -12, 0, 1024)]
[DataRow(typeof(ConstantBuffer<>), 0, -56, 1024)]
[DataRow(typeof(ConstantBuffer<>), 512, 0, 4096)]
[DataRow(typeof(ConstantBuffer<>), 12, 1024, 3600)]
[DataRow(typeof(ConstantBuffer<>), 12, 1024, -2096)]
[DataRow(typeof(ReadOnlyBuffer<>), 0, 0, 8196)]
[DataRow(typeof(ReadOnlyBuffer<>), -12, 0, 1024)]
[DataRow(typeof(ReadOnlyBuffer<>), 0, -56, 1024)]
[DataRow(typeof(ReadOnlyBuffer<>), 512, 0, 4096)]
[DataRow(typeof(ReadOnlyBuffer<>), 12, 1024, 3600)]
[DataRow(typeof(ReadOnlyBuffer<>), 12, 1024, -2096)]
[DataRow(typeof(ReadWriteBuffer<>), 0, 0, 8196)]
[DataRow(typeof(ReadWriteBuffer<>), -12, 0, 1024)]
[DataRow(typeof(ReadWriteBuffer<>), 0, -56, 1024)]
[DataRow(typeof(ReadWriteBuffer<>), 512, 0, 4096)]
[DataRow(typeof(ReadWriteBuffer<>), 12, 1024, 3600)]
[DataRow(typeof(ReadWriteBuffer<>), 12, 1024, -2096)]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ConstantBuffer<>))]
[Resource(typeof(ReadOnlyBuffer<>))]
[Resource(typeof(ReadWriteBuffer<>))]
[Data(0, 0, 8196)]
[Data(-12, 0, 1024)]
[Data(0, -56, 1024)]
[Data(512, 0, 4096)]
[Data(12, 1024, 3600)]
[Data(12, 1024, -2096)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void CopyTo_RangeToVoid_Fail(Type bufferType, int destinationOffset, int bufferOffset, int count)
public void CopyTo_RangeToVoid_Fail(Device device, Type bufferType, int destinationOffset, int bufferOffset, int count)
{
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
using Buffer<float> buffer = Gpu.Default.AllocateBuffer(bufferType, array);
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, array);
float[] result = new float[4096];
buffer.CopyTo(result, destinationOffset, bufferOffset, count);
}
[TestMethod]
public void Dispatch_ConstantBuffer()
[CombinatorialTestMethod]
[AllDevices]
public void Dispatch_ConstantBuffer(Device device)
{
int[] data = Enumerable.Range(0, 1024).ToArray();
using ConstantBuffer<int> source = Gpu.Default.AllocateConstantBuffer(data);
using ReadWriteBuffer<int> destination = Gpu.Default.AllocateReadWriteBuffer<int>(data.Length);
using ConstantBuffer<int> source = device.Get().AllocateConstantBuffer(data);
using ReadWriteBuffer<int> destination = device.Get().AllocateReadWriteBuffer<int>(data.Length);
Gpu.Default.For(source.Length, new ConstantBufferKernel(source, destination));
device.Get().For(source.Length, new ConstantBufferKernel(source, destination));
int[] result = destination.ToArray();
@@ -229,15 +214,16 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
public void Dispatch_ReadOnlyBuffer()
[CombinatorialTestMethod]
[AllDevices]
public void Dispatch_ReadOnlyBuffer(Device device)
{
int[] data = Enumerable.Range(0, 1024).ToArray();
using ReadOnlyBuffer<int> source = Gpu.Default.AllocateReadOnlyBuffer(data);
using ReadWriteBuffer<int> destination = Gpu.Default.AllocateReadWriteBuffer<int>(data.Length);
using ReadOnlyBuffer<int> source = device.Get().AllocateReadOnlyBuffer(data);
using ReadWriteBuffer<int> destination = device.Get().AllocateReadWriteBuffer<int>(data.Length);
Gpu.Default.For(source.Length, new ReadOnlyBufferKernel(source, destination));
device.Get().For(source.Length, new ReadOnlyBufferKernel(source, destination));
int[] result = destination.ToArray();
@@ -256,15 +242,16 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
public void Dispatch_ReadWriteBuffer()
[CombinatorialTestMethod]
[AllDevices]
public void Dispatch_ReadWriteBuffer(Device device)
{
int[] data = Enumerable.Range(0, 1024).ToArray();
using ReadWriteBuffer<int> source = Gpu.Default.AllocateReadWriteBuffer(data);
using ReadWriteBuffer<int> destination = Gpu.Default.AllocateReadWriteBuffer<int>(data.Length);
using ReadWriteBuffer<int> source = device.Get().AllocateReadWriteBuffer(data);
using ReadWriteBuffer<int> destination = device.Get().AllocateReadWriteBuffer<int>(data.Length);
Gpu.Default.For(source.Length, new ReadWriteBufferKernel(source, destination));
device.Get().For(source.Length, new ReadWriteBufferKernel(source, destination));
int[] result = destination.ToArray();
+14
ファイルの表示
@@ -4,6 +4,7 @@
<TargetFrameworks>net5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
@@ -12,6 +13,7 @@
<PackageReference Include="Microsoft.Toolkit.HighPerformance" Version="7.0.0-preview4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
</ItemGroup>
<ItemGroup>
@@ -22,6 +24,18 @@
PrivateAssets="contentfiles;build"/>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Primitives\Complex64.cs" Link="Imaging\Primitives\Complex64.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Processors\HlslBokehBlurProcessor.cs" Link="Imaging\Processors\HlslBokehBlurProcessor.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Processors\HlslBokehBlurProcessor{TPixel}.cs" Link="Imaging\Processors\HlslBokehBlurProcessor{TPixel}.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Processors\HlslGaussianBlurProcessor.cs" Link="Imaging\Processors\HlslGaussianBlurProcessor.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Processors\HlslGaussianBlurProcessor{TPixel}.cs" Link="Imaging\Processors\HlslGaussianBlurProcessor{TPixel}.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\samples\ComputeSharp.ImageProcessing\city.jpg" Link="Imaging\city.jpg" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<None Update="Texture2DTests.Pixels.tt">
<Generator>TextTemplatingFileGenerator</Generator>
+40 -33
ファイルの表示
@@ -1,4 +1,6 @@
using System;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.Tests
@@ -7,12 +9,13 @@ namespace ComputeSharp.Tests
[TestCategory("Dispatch")]
public partial class DispatchTests
{
[TestMethod]
public void Verify_ThreadIds()
[CombinatorialTestMethod]
[AllDevices]
public void Verify_ThreadIds(Device device)
{
using ReadWriteTexture3D<Int4> buffer = Gpu.Default.AllocateReadWriteTexture3D<Int4>(50, 50, 50);
using ReadWriteTexture3D<Int4> buffer = device.Get().AllocateReadWriteTexture3D<Int4>(50, 50, 50);
Gpu.Default.For(buffer.Width, buffer.Height, buffer.Depth, new ThreadIdsShader(buffer));
device.Get().For(buffer.Width, buffer.Height, buffer.Depth, new ThreadIdsShader(buffer));
Int4[,,] data = buffer.ToArray();
@@ -32,18 +35,19 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
[DataRow(0, 8, 8)]
[DataRow(8, 0, 8)]
[DataRow(8, 8, 0)]
[DataRow(8, -3, 16)]
[DataRow(-1, -1, -1)]
[CombinatorialTestMethod]
[AllDevices]
[Data(0, 8, 8)]
[Data(8, 0, 8)]
[Data(8, 8, 0)]
[Data(8, -3, 16)]
[Data(-1, -1, -1)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Verify_ThreadIds_OutOfRange(int x, int y, int z)
public void Verify_ThreadIds_OutOfRange(Device device, int x, int y, int z)
{
using ReadWriteTexture3D<Int4> buffer = Gpu.Default.AllocateReadWriteTexture3D<Int4>(50, 50, 50);
using ReadWriteTexture3D<Int4> buffer = device.Get().AllocateReadWriteTexture3D<Int4>(50, 50, 50);
Gpu.Default.For(x, y, z, new ThreadIdsShader(buffer));
device.Get().For(x, y, z, new ThreadIdsShader(buffer));
Assert.Fail();
}
@@ -59,12 +63,13 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
public void Verify_GroupIds()
[CombinatorialTestMethod]
[AllDevices]
public void Verify_GroupIds(Device device)
{
using ReadWriteTexture3D<Int4> buffer = Gpu.Default.AllocateReadWriteTexture3D<Int4>(50, 50, 50);
using ReadWriteTexture3D<Int4> buffer = device.Get().AllocateReadWriteTexture3D<Int4>(50, 50, 50);
Gpu.Default.For(buffer.Width, buffer.Height, buffer.Depth, 4, 4, 4, new GroupIdsShader(buffer));
device.Get().For(buffer.Width, buffer.Height, buffer.Depth, 4, 4, 4, new GroupIdsShader(buffer));
Int4[,,] data = buffer.ToArray();
@@ -85,21 +90,22 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
[DataRow(0, 8, 8)]
[DataRow(8, 0, 8)]
[DataRow(8, 8, 0)]
[DataRow(1025, 8, 8)]
[DataRow(8, 2000, 8)]
[DataRow(8, 8, 70)]
[DataRow(8, -1, 8)]
[DataRow(8, 15, 16)]
[CombinatorialTestMethod]
[AllDevices]
[Data(0, 8, 8)]
[Data(8, 0, 8)]
[Data(8, 8, 0)]
[Data(1025, 8, 8)]
[Data(8, 2000, 8)]
[Data(8, 8, 70)]
[Data(8, -1, 8)]
[Data(8, 15, 16)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Verify_GroupIds_OutOfRange(int x, int y, int z)
public void Verify_GroupIds_OutOfRange(Device device, int x, int y, int z)
{
using ReadWriteTexture3D<Int4> buffer = Gpu.Default.AllocateReadWriteTexture3D<Int4>(50, 50, 50);
using ReadWriteTexture3D<Int4> buffer = device.Get().AllocateReadWriteTexture3D<Int4>(50, 50, 50);
Gpu.Default.For(buffer.Width, buffer.Height, buffer.Depth, x, y, z, new GroupIdsShader(buffer));
device.Get().For(buffer.Width, buffer.Height, buffer.Depth, x, y, z, new GroupIdsShader(buffer));
Assert.Fail();
}
@@ -116,12 +122,13 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
public void Verify_GroupSize()
[CombinatorialTestMethod]
[AllDevices]
public void Verify_GroupSize(Device device)
{
using ReadWriteBuffer<int> buffer = Gpu.Default.AllocateReadWriteBuffer<int>(32);
using ReadWriteBuffer<int> buffer = device.Get().AllocateReadWriteBuffer<int>(32);
Gpu.Default.For(1, 1, 1, 4, 15, 7, new GroupSizeShader(buffer));
device.Get().For(1, 1, 1, 4, 15, 7, new GroupSizeShader(buffer));
int[] data = buffer.ToArray();
+80
ファイルの表示
@@ -0,0 +1,80 @@
using System.Linq;
using Microsoft.Toolkit.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.Tests.Extensions
{
/// <summary>
/// A helper class for testing <see cref="Gpu"/> APIs.
/// </summary>
public static class DeviceExtensions
{
/// <summary>
/// The <see cref="GraphicsDevice"/> instance for the default discrete device.
/// </summary>
private static readonly GraphicsDevice? DiscreteDevice;
/// <summary>
/// The <see cref="GraphicsDevice"/> instance for the WARP device.
/// </summary>
private static readonly GraphicsDevice WarpDevice;
/// <summary>
/// Initializes <see cref="DiscreteDevice"/> and <see cref="WarpDevice"/>.
/// </summary>
static DeviceExtensions()
{
GraphicsDevice defaultDevice = Gpu.Default;
if (defaultDevice.IsHardwareAccelerated)
{
DiscreteDevice = defaultDevice;
WarpDevice = Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First();
}
else
{
DiscreteDevice = null;
WarpDevice = defaultDevice;
}
}
/// <summary>
/// Gets a <see cref="GraphicsDevice"/> instance matching a specified type.
/// </summary>
/// <param name="type">The device to retrieve.</param>
/// <returns>The device of the requested type.</returns>
/// <exception cref="AssertInconclusiveException">Thrown when the requested device is not present.</exception>
public static GraphicsDevice Get(this Device type)
{
GraphicsDevice? device = type switch
{
Device.Discrete => DiscreteDevice,
Device.Warp => WarpDevice,
_ => ThrowHelper.ThrowArgumentException<GraphicsDevice>("Invalid device")
};
if (device is null)
{
Assert.Inconclusive();
}
return device!;
}
}
/// <summary>
/// Indicates a specific compute device.
/// </summary>
public enum Device
{
/// <summary>
/// A discrete device.
/// </summary>
Discrete,
/// <summary>
/// A WARP device (software fallback).
/// </summary>
Warp
}
}
-39
ファイルの表示
@@ -1,39 +0,0 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace ComputeSharp.Tests.Extensions
{
/// <summary>
/// An helper <see langword="class"/> with methods to process fixed-size buffers.
/// </summary>
public static class SpanExtensions
{
/// <summary>
/// The maximum threshold to validate two <see langword="float"/> values as being equal.
/// </summary>
private const float FloatThreshold = 0.00001f;
/// <summary>
/// Checks whether or not the two input <see cref="Span{T}"/> instances have the same content.
/// </summary>
/// <param name="a">The first <see cref="Span{T}"/> to check.</param>
/// <param name="b">The second <see cref="Span{T}"/> to check.</param>
[Pure]
public static bool ContentEquals(this Span<float> a, Span<float> b)
{
if (a.Length != b.Length) return false;
if (a.Length == 0) return true;
var l = a.Length;
ref var ra = ref a.GetPinnableReference();
ref var rb = ref b.GetPinnableReference();
for (var i = 0; i < l; i++)
if (Math.Abs(Unsafe.Add(ref ra, i) - Unsafe.Add(ref rb, i)) > FloatThreshold)
return false;
return true;
}
}
}
+182
ファイルの表示
@@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using ComputeSharp.BokehBlur.Processors;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
namespace ComputeSharp.Tests
{
[TestClass]
[TestCategory("Imaging")]
public class ImagingTests
{
[CombinatorialTestMethod]
[AllDevices]
public void BokehBlur(Device device)
{
// Early test to ensure the device is available. This saves time when running the
// unit test if the target device is not available, as we skip the preprocessing.
_ = device.Get();
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
using var original = Image.Load<ImageSharpRgba32>(Path.Combine(path, "city.jpg"));
using var cpu = original.Clone(c => c.BokehBlur(80, 2, 3));
using var gpu = original.Clone(c => c.ApplyProcessor(new HlslBokehBlurProcessor(device.Get(), 80, 2)));
string
expectedPath = Path.Combine(path, "city_bokeh_cpu.jpg"),
actualPath = Path.Combine(path, "city_bokeh_gpu.jpg");
cpu.Save(expectedPath);
gpu.Save(actualPath);
TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.000009f);
}
[CombinatorialTestMethod]
[AllDevices]
public void GaussianBlur(Device device)
{
_ = device.Get();
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
using var original = Image.Load<ImageSharpRgba32>(Path.Combine(path, "city.jpg"));
using var cpu = original.Clone(c => c.GaussianBlur(30f));
using var gpu = original.Clone(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(device.Get(), 90)));
string
expectedPath = Path.Combine(path, "city_gaussian_cpu.jpg"),
actualPath = Path.Combine(path, "city_gaussian_gpu.jpg");
cpu.Save(expectedPath);
gpu.Save(actualPath);
TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.000003f);
}
/// <summary>
/// An tolerant image comparer type, from <see href="https://github.com/SixLabors/ImageSharp">ImageSharp</see>.
/// </summary>
private static class TolerantImageComparer
{
/// <summary>
/// Asserts that two images are equal.
/// </summary>
/// <param name="expectedPath">The path to the reference image.</param>
/// <param name="actualPath">The path to the expected image.</param>
/// <param name="threshold">The allowed difference threshold for the normalized delta.</param>
public static void AssertEqual(string expectedPath, string actualPath, float threshold)
{
using var expected = Image.Load<ImageSharpRgba32>(expectedPath);
using var actual = Image.Load<ImageSharpRgba32>(actualPath);
if (expected.Size() != actual.Size())
{
Assert.Fail($"The input images have different sizes: {expected.Size()} and {actual.Size()}");
}
if (expected.Frames.Count != actual.Frames.Count ||
expected.Frames.Count != 1 ||
actual.Frames.Count != 1)
{
Assert.Fail("The two input images must have 1 frame each");
}
int width = actual.Width;
float totalDifference = 0F;
var differences = new List<PixelDifference>(20);
for (int y = 0; y < actual.Height; y++)
{
Span<ImageSharpRgba32> aSpan = expected.GetPixelRowSpan(y);
Span<ImageSharpRgba32> bSpan = actual.GetPixelRowSpan(y);
for (int x = 0; x < width; x++)
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static int GetManhattanDistanceInRgbaSpace(ref ImageSharpRgba32 a, ref ImageSharpRgba32 b)
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static int Diff(ushort a, ushort b) => Math.Abs(a - b);
return Diff(a.R, b.R) + Diff(a.G, b.G) + Diff(a.B, b.B) + Diff(a.A, b.A);
}
int d = GetManhattanDistanceInRgbaSpace(ref aSpan[x], ref bSpan[x]);
if (d > 0)
{
if (differences.Count < 20)
{
var diff = new PixelDifference(new Point(x, y), aSpan[x], bSpan[x]);
differences.Add(diff);
}
totalDifference += d;
}
}
}
float normalizedDifference = totalDifference / (actual.Width * (float)actual.Height);
normalizedDifference /= 4F * 65535F;
if (normalizedDifference > threshold)
{
StringBuilder builder = new();
builder.AppendLine($"The input images don't match. Normalized delta: {normalizedDifference}%");
builder.AppendLine($"First {differences.Count} pixel deltas:");
foreach (var delta in differences)
{
builder.AppendLine(delta.ToString());
}
Assert.Fail(builder.ToString());
}
}
/// <summary>
/// A simple model repressenting info about a difference between two pixels.
/// </summary>
private readonly struct PixelDifference
{
public PixelDifference(Point position, ImageSharpRgba32 expected, ImageSharpRgba32 actual)
{
this.Position = position;
this.RedDifference = actual.R - expected.R;
this.GreenDifference = actual.G - expected.G;
this.BlueDifference = actual.B - expected.B;
this.AlphaDifference = actual.A - expected.A;
}
public readonly Point Position;
public readonly int RedDifference;
public readonly int GreenDifference;
public readonly int BlueDifference;
public readonly int AlphaDifference;
/// <inheritdoc/>
public override string ToString()
{
return $"[delta({RedDifference},{GreenDifference},{BlueDifference},{AlphaDifference}) @ ({Position.X},{Position.Y})]";
}
}
}
}
}
+14 -9
ファイルの表示
@@ -1,5 +1,7 @@
using System;
using System.Linq;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.Tests
@@ -14,23 +16,26 @@ namespace ComputeSharp.Tests
Assert.IsTrue(Gpu.IsSupported);
}
[TestMethod]
public void DefaultDeviceInfo()
[CombinatorialTestMethod]
[AllDevices]
public void DeviceInfo(Device device)
{
Assert.IsTrue(Gpu.Default.Luid != default);
Assert.IsTrue(Gpu.Default.Name is { Length: > 0 });
GraphicsDevice gpu = device.Get();
if (Gpu.Default.IsHardwareAccelerated)
Assert.IsTrue(gpu.Luid != default);
Assert.IsTrue(gpu.Name is { Length: > 0 });
if (gpu.IsHardwareAccelerated)
{
Assert.IsTrue(Gpu.Default.DedicatedMemorySize != 0);
Assert.IsTrue(gpu.DedicatedMemorySize != 0);
}
else
{
Assert.IsTrue(Gpu.Default.SharedMemorySize != 0);
Assert.IsTrue(gpu.SharedMemorySize != 0);
}
Assert.IsTrue(Gpu.Default.ComputeUnits != 0);
Assert.IsTrue(Gpu.Default.WavefrontSize != 0);
Assert.IsTrue(gpu.ComputeUnits != 0);
Assert.IsTrue(gpu.WavefrontSize != 0);
}
[TestMethod]
+22 -30
ファイルの表示
@@ -3,6 +3,7 @@ using System.Numerics;
using System.Reflection;
using ComputeSharp.__Internals;
using ComputeSharp.Resources;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -12,43 +13,34 @@ namespace ComputeSharp.Tests
{
public partial class Texture2DTests
{
[TestMethod]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Bgra32), typeof(Vector4))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Bgra32), typeof(Float4))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(R16), typeof(float))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(R8), typeof(float))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg16), typeof(Vector2))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg16), typeof(Float2))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg32), typeof(Vector2))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg32), typeof(Float2))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba32), typeof(Vector4))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba32), typeof(Float4))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba64), typeof(Vector4))]
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba64), typeof(Float4))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Bgra32), typeof(Vector4))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Bgra32), typeof(Float4))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(R16), typeof(float))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(R8), typeof(float))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg16), typeof(Vector2))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg16), typeof(Float2))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg32), typeof(Vector2))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg32), typeof(Float2))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba32), typeof(Vector4))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba32), typeof(Float4))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba64), typeof(Vector4))]
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba64), typeof(Float4))]
public void Allocate_Uninitialized_Pixel_Ok(Type textureType, Type t, Type tPixel)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture2D<,>))]
[Resource(typeof(ReadWriteTexture2D<,>))]
[Data(typeof(Bgra32), typeof(Vector4))]
[Data(typeof(Bgra32), typeof(Float4))]
[Data(typeof(R16), typeof(float))]
[Data(typeof(R8), typeof(float))]
[Data(typeof(Rg16), typeof(Vector2))]
[Data(typeof(Rg16), typeof(Float2))]
[Data(typeof(Rg32), typeof(Vector2))]
[Data(typeof(Rg32), typeof(Float2))]
[Data(typeof(Rgba32), typeof(Vector4))]
[Data(typeof(Rgba32), typeof(Float4))]
[Data(typeof(Rgba64), typeof(Vector4))]
[Data(typeof(Rgba64), typeof(Float4))]
public void Allocate_Uninitialized_Pixel_Ok(Device device, Type textureType, Type t, Type tPixel)
{
static void Test<T, TPixel>(Type textureType)
static void Test<T, TPixel>(Device device, Type textureType)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
using Texture2D<T> texture = Gpu.Default.AllocateTexture2D<T, TPixel>(textureType, 128, 128);
using Texture2D<T> texture = device.Get().AllocateTexture2D<T, TPixel>(textureType, 128, 128);
Assert.IsNotNull(texture);
Assert.AreEqual(texture.Width, 128);
Assert.AreEqual(texture.Height, 128);
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
Assert.AreSame(texture.GraphicsDevice, device.Get());
if (textureType == typeof(ReadOnlyTexture2D<,>))
{
@@ -62,7 +54,7 @@ namespace ComputeSharp.Tests
try
{
new Action<Type>(Test<Rgba32, Vector4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new[] { textureType });
new Action<Device, Type>(Test<Rgba32, Vector4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new object[] { device, textureType });
}
catch (TargetInvocationException e) when (e.InnerException is not null)
{
+53 -51
ファイルの表示
@@ -1,109 +1,111 @@
using System;
using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
namespace ComputeSharp.Tests
{
public partial class Texture2DTests
{
[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_NormalizedTexture2D(Type t, Type tPixel)
[CombinatorialTestMethod]
[AllDevices]
[Data(typeof(Bgra32), typeof(Vector4))]
[Data(typeof(Bgra32), typeof(Float4))]
[Data(typeof(R16), typeof(float))]
[Data(typeof(R8), typeof(float))]
[Data(typeof(Rg16), typeof(Vector2))]
[Data(typeof(Rg16), typeof(Float2))]
[Data(typeof(Rg32), typeof(Vector2))]
[Data(typeof(Rg32), typeof(Float2))]
[Data(typeof(Rgba32), typeof(Vector4))]
[Data(typeof(Rgba32), typeof(Float4))]
[Data(typeof(Rgba64), typeof(Vector4))]
[Data(typeof(Rgba64), typeof(Float4))]
public void Dispatch_NormalizedTexture2D(Device device, 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);
using ReadOnlyTexture2D<Bgra32, Vector4> source = device.Get().AllocateReadOnlyTexture2D<Bgra32, Vector4>(128, 128);
using ReadWriteTexture2D<Bgra32, Vector4> destination = device.Get().AllocateReadWriteTexture2D<Bgra32, Vector4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Bgra32_Vector4(source, destination));
device.Get().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);
using ReadOnlyTexture2D<Bgra32, Float4> source = device.Get().AllocateReadOnlyTexture2D<Bgra32, Float4>(128, 128);
using ReadWriteTexture2D<Bgra32, Float4> destination = device.Get().AllocateReadWriteTexture2D<Bgra32, Float4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Bgra32_Float4(source, destination));
device.Get().For(128, 128, new Shader_Unorm_Bgra32_Float4(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);
using ReadOnlyTexture2D<R16, float> source = device.Get().AllocateReadOnlyTexture2D<R16, float>(128, 128);
using ReadWriteTexture2D<R16, float> destination = device.Get().AllocateReadWriteTexture2D<R16, float>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_R16_float(source, destination));
device.Get().For(128, 128, new Shader_Unorm_R16_float(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);
using ReadOnlyTexture2D<R8, float> source = device.Get().AllocateReadOnlyTexture2D<R8, float>(128, 128);
using ReadWriteTexture2D<R8, float> destination = device.Get().AllocateReadWriteTexture2D<R8, float>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_R8_float(source, destination));
device.Get().For(128, 128, new Shader_Unorm_R8_float(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);
using ReadOnlyTexture2D<Rg16, Vector2> source = device.Get().AllocateReadOnlyTexture2D<Rg16, Vector2>(128, 128);
using ReadWriteTexture2D<Rg16, Vector2> destination = device.Get().AllocateReadWriteTexture2D<Rg16, Vector2>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rg16_Vector2(source, destination));
device.Get().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);
using ReadOnlyTexture2D<Rg16, Float2> source = device.Get().AllocateReadOnlyTexture2D<Rg16, Float2>(128, 128);
using ReadWriteTexture2D<Rg16, Float2> destination = device.Get().AllocateReadWriteTexture2D<Rg16, Float2>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rg16_Float2(source, destination));
device.Get().For(128, 128, new Shader_Unorm_Rg16_Float2(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);
using ReadOnlyTexture2D<Rg32, Vector2> source = device.Get().AllocateReadOnlyTexture2D<Rg32, Vector2>(128, 128);
using ReadWriteTexture2D<Rg32, Vector2> destination = device.Get().AllocateReadWriteTexture2D<Rg32, Vector2>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rg32_Vector2(source, destination));
device.Get().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);
using ReadOnlyTexture2D<Rg32, Float2> source = device.Get().AllocateReadOnlyTexture2D<Rg32, Float2>(128, 128);
using ReadWriteTexture2D<Rg32, Float2> destination = device.Get().AllocateReadWriteTexture2D<Rg32, Float2>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rg32_Float2(source, destination));
device.Get().For(128, 128, new Shader_Unorm_Rg32_Float2(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);
using ReadOnlyTexture2D<Rgba32, Vector4> source = device.Get().AllocateReadOnlyTexture2D<Rgba32, Vector4>(128, 128);
using ReadWriteTexture2D<Rgba32, Vector4> destination = device.Get().AllocateReadWriteTexture2D<Rgba32, Vector4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba32_Vector4(source, destination));
device.Get().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);
using ReadOnlyTexture2D<Rgba32, Float4> source = device.Get().AllocateReadOnlyTexture2D<Rgba32, Float4>(128, 128);
using ReadWriteTexture2D<Rgba32, Float4> destination = device.Get().AllocateReadWriteTexture2D<Rgba32, Float4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba32_Float4(source, destination));
device.Get().For(128, 128, new Shader_Unorm_Rgba32_Float4(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);
using ReadOnlyTexture2D<Rgba64, Vector4> source = device.Get().AllocateReadOnlyTexture2D<Rgba64, Vector4>(128, 128);
using ReadWriteTexture2D<Rgba64, Vector4> destination = device.Get().AllocateReadWriteTexture2D<Rgba64, Vector4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba64_Vector4(source, destination));
device.Get().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);
using ReadOnlyTexture2D<Rgba64, Float4> source = device.Get().AllocateReadOnlyTexture2D<Rgba64, Float4>(128, 128);
using ReadWriteTexture2D<Rgba64, Float4> destination = device.Get().AllocateReadWriteTexture2D<Rgba64, Float4>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba64_Float4(source, destination));
device.Get().For(128, 128, new Shader_Unorm_Rgba64_Float4(source, destination));
}
}
+9 -7
ファイルの表示
@@ -25,22 +25,24 @@ IEnumerable<(string T, string TPixel)> EnumerateTypes()
#>
using System;
using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
namespace ComputeSharp.Tests
{
public partial class Texture2DTests
{
[TestMethod]
[CombinatorialTestMethod]
[AllDevices]
<#
foreach (var (t, tPixel) in EnumerateTypes())
{
#>
[DataRow(typeof(<#=t#>), typeof(<#=tPixel#>))]
[Data(typeof(<#=t#>), typeof(<#=tPixel#>))]
<#
}
#>
public void Dispatch_NormalizedTexture2D(Type t, Type tPixel)
public void Dispatch_NormalizedTexture2D(Device device, Type t, Type tPixel)
{
<#
foreach (var (t, tPixel) in EnumerateTypes())
@@ -48,10 +50,10 @@ 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);
using ReadOnlyTexture2D<<#=t#>, <#=tPixel#>> source = device.Get().AllocateReadOnlyTexture2D<<#=t#>, <#=tPixel#>>(128, 128);
using ReadWriteTexture2D<<#=t#>, <#=tPixel#>> destination = device.Get().AllocateReadWriteTexture2D<<#=t#>, <#=tPixel#>>(128, 128);
Gpu.Default.For(128, 128, new Shader_Unorm_<#=t#>_<#=tPixel#>(source, destination));
device.Get().For(128, 128, new Shader_Unorm_<#=t#>_<#=tPixel#>(source, destination));
}
<#
}
+72 -78
ファイルの表示
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using ComputeSharp.Resources;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.Toolkit.HighPerformance.Memory;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -11,47 +12,48 @@ namespace ComputeSharp.Tests
[TestCategory("Texture2D")]
public partial class Texture2DTests
{
[TestMethod]
[DataRow(typeof(ReadOnlyTexture2D<>))]
[DataRow(typeof(ReadWriteTexture2D<>))]
public void Allocate_Uninitialized_Ok(Type textureType)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture2D<>))]
[Resource(typeof(ReadWriteTexture2D<>))]
public void Allocate_Uninitialized_Ok(Device device, Type textureType)
{
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D<float>(textureType, 128, 128);
using Texture2D<float> texture = device.Get().AllocateTexture2D<float>(textureType, 128, 128);
Assert.IsNotNull(texture);
Assert.AreEqual(texture.Width, 128);
Assert.AreEqual(texture.Height, 128);
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
Assert.AreSame(texture.GraphicsDevice, device.Get());
}
[TestMethod]
[DataRow(typeof(ReadOnlyTexture2D<>), 128, -14253)]
[DataRow(typeof(ReadOnlyTexture2D<>), 128, -1)]
[DataRow(typeof(ReadOnlyTexture2D<>), 0, -4314)]
[DataRow(typeof(ReadOnlyTexture2D<>), -14, -53)]
[DataRow(typeof(ReadWriteTexture2D<>), 128, -14253)]
[DataRow(typeof(ReadWriteTexture2D<>), 128, -1)]
[DataRow(typeof(ReadWriteTexture2D<>), 0, -4314)]
[DataRow(typeof(ReadWriteTexture2D<>), -14, -53)]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture2D<>))]
[Resource(typeof(ReadWriteTexture2D<>))]
[Data(128, -14253)]
[Data(128, -1)]
[Data(0, -4314)]
[Data(-14, -53)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Allocate_Uninitialized_Fail(Type textureType, int width, int height)
public void Allocate_Uninitialized_Fail(Device device, Type textureType, int width, int height)
{
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D<float>(textureType, width, height);
using Texture2D<float> texture = device.Get().AllocateTexture2D<float>(textureType, width, height);
}
[TestMethod]
[DataRow(typeof(ReadOnlyTexture2D<>))]
[DataRow(typeof(ReadWriteTexture2D<>))]
public void Allocate_FromArray(Type textureType)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture2D<>))]
[Resource(typeof(ReadWriteTexture2D<>))]
public void Allocate_FromArray(Device device, Type textureType)
{
float[] data = Enumerable.Range(0, 128 * 128).Select(static i => (float)i).ToArray();
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D(textureType, data, 128, 128);
using Texture2D<float> texture = device.Get().AllocateTexture2D(textureType, data, 128, 128);
Assert.IsNotNull(texture);
Assert.AreEqual(texture.Width, 128);
Assert.AreEqual(texture.Height, 128);
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
Assert.AreSame(texture.GraphicsDevice, device.Get());
float[,] result = texture.ToArray();
@@ -60,43 +62,38 @@ namespace ComputeSharp.Tests
Assert.IsTrue(data.SequenceEqual(result.Cast<float>()));
}
[TestMethod]
[DataRow(typeof(ReadOnlyTexture2D<>))]
[DataRow(typeof(ReadWriteTexture2D<>))]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture2D<>))]
[Resource(typeof(ReadWriteTexture2D<>))]
[ExpectedException(typeof(ObjectDisposedException))]
public void UsageAfterDispose(Type textureType)
public void UsageAfterDispose(Device device, Type textureType)
{
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D<float>(textureType, 10, 10);
using Texture2D<float> texture = device.Get().AllocateTexture2D<float>(textureType, 10, 10);
texture.Dispose();
_ = texture.ToArray();
}
[TestMethod]
[DataRow(typeof(ReadOnlyTexture2D<>), 0, 0, 64, 64)]
[DataRow(typeof(ReadOnlyTexture2D<>), 0, 14, 64, 50)]
[DataRow(typeof(ReadOnlyTexture2D<>), 14, 0, 50, 64)]
[DataRow(typeof(ReadOnlyTexture2D<>), 10, 10, 54, 54)]
[DataRow(typeof(ReadOnlyTexture2D<>), 20, 20, 32, 27)]
[DataRow(typeof(ReadOnlyTexture2D<>), 60, 0, 4, 64)]
[DataRow(typeof(ReadOnlyTexture2D<>), 0, 60, 64, 4)]
[DataRow(typeof(ReadOnlyTexture2D<>), 63, 2, 1, 60)]
[DataRow(typeof(ReadOnlyTexture2D<>), 2, 63, 60, 1)]
[DataRow(typeof(ReadWriteTexture2D<>), 0, 0, 64, 64)]
[DataRow(typeof(ReadWriteTexture2D<>), 0, 14, 64, 50)]
[DataRow(typeof(ReadWriteTexture2D<>), 14, 0, 50, 64)]
[DataRow(typeof(ReadWriteTexture2D<>), 10, 10, 54, 54)]
[DataRow(typeof(ReadWriteTexture2D<>), 20, 20, 32, 27)]
[DataRow(typeof(ReadWriteTexture2D<>), 60, 0, 4, 64)]
[DataRow(typeof(ReadWriteTexture2D<>), 0, 60, 64, 4)]
[DataRow(typeof(ReadWriteTexture2D<>), 63, 2, 1, 60)]
[DataRow(typeof(ReadWriteTexture2D<>), 2, 63, 60, 1)]
public void GetData_RangeToVoid_Ok(Type textureType, int x, int y, int width, int height)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture2D<>))]
[Resource(typeof(ReadWriteTexture2D<>))]
[Data(0, 0, 64, 64)]
[Data(0, 14, 64, 50)]
[Data(14, 0, 50, 64)]
[Data(10, 10, 54, 54)]
[Data(20, 20, 32, 27)]
[Data(60, 0, 4, 64)]
[Data(0, 60, 64, 4)]
[Data(63, 2, 1, 60)]
[Data(2, 63, 60, 1)]
public void GetData_RangeToVoid_Ok(Device device, Type textureType, int x, int y, int width, int height)
{
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D(textureType, array, 64, 64);
using Texture2D<float> texture = device.Get().AllocateTexture2D(textureType, array, 64, 64);
float[] result = new float[width * height];
@@ -109,44 +106,40 @@ namespace ComputeSharp.Tests
CollectionAssert.AreEqual(expected.ToArray(), data.ToArray());
}
[TestMethod]
[DataRow(typeof(ReadOnlyTexture2D<>), 0, -1, 50, 50)]
[DataRow(typeof(ReadOnlyTexture2D<>), -1, 0, 50, 50)]
[DataRow(typeof(ReadOnlyTexture2D<>), 12, 0, -1, 50)]
[DataRow(typeof(ReadOnlyTexture2D<>), 12, 0, 20, -1)]
[DataRow(typeof(ReadOnlyTexture2D<>), 12, 20, 20, 50)]
[DataRow(typeof(ReadOnlyTexture2D<>), 12, 20, 60, 20)]
[DataRow(typeof(ReadOnlyTexture2D<>), 80, 20, 40, 20)]
[DataRow(typeof(ReadOnlyTexture2D<>), 0, 80, 40, 20)]
[DataRow(typeof(ReadWriteTexture2D<>), 0, -1, 50, 50)]
[DataRow(typeof(ReadWriteTexture2D<>), -1, 0, 50, 50)]
[DataRow(typeof(ReadWriteTexture2D<>), 12, 0, -1, 50)]
[DataRow(typeof(ReadWriteTexture2D<>), 12, 0, 20, -1)]
[DataRow(typeof(ReadWriteTexture2D<>), 12, 20, 20, 50)]
[DataRow(typeof(ReadWriteTexture2D<>), 12, 20, 60, 20)]
[DataRow(typeof(ReadWriteTexture2D<>), 80, 20, 40, 20)]
[DataRow(typeof(ReadWriteTexture2D<>), 0, 80, 40, 20)]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture2D<>))]
[Resource(typeof(ReadWriteTexture2D<>))]
[Data(0, -1, 50, 50)]
[Data(-1, 0, 50, 50)]
[Data(12, 0, -1, 50)]
[Data(12, 0, 20, -1)]
[Data(12, 20, 20, 50)]
[Data(12, 20, 60, 20)]
[Data(80, 20, 40, 20)]
[Data(0, 80, 40, 20)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void GetData_RangeToVoid_Fail(Type textureType, int x, int y, int width, int height)
public void GetData_RangeToVoid_Fail(Device device, Type textureType, int x, int y, int width, int height)
{
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D(textureType, array, 64, 64);
using Texture2D<float> texture = device.Get().AllocateTexture2D(textureType, array, 64, 64);
float[] result = new float[4096];
texture.CopyTo(result, x, y, width, height);
}
[TestMethod]
public void Dispatch_ReadOnlyTexture2D()
[CombinatorialTestMethod]
[AllDevices]
public void Dispatch_ReadOnlyTexture2D(Device device)
{
int[] data = Enumerable.Range(0, 32 * 32).ToArray();
using ReadOnlyTexture2D<int> source = Gpu.Default.AllocateReadOnlyTexture2D(data, 32, 32);
using ReadWriteBuffer<int> destination = Gpu.Default.AllocateReadWriteBuffer<int>(data.Length);
using ReadOnlyTexture2D<int> source = device.Get().AllocateReadOnlyTexture2D(data, 32, 32);
using ReadWriteBuffer<int> destination = device.Get().AllocateReadWriteBuffer<int>(data.Length);
Gpu.Default.For(source.Width, source.Height, new ReadOnlyTexture2DKernel(source, destination));
device.Get().For(source.Width, source.Height, new ReadOnlyTexture2DKernel(source, destination));
int[] result = destination.ToArray();
@@ -165,15 +158,16 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
public void Dispatch_ReadWriteTexture2D()
[CombinatorialTestMethod]
[AllDevices]
public void Dispatch_ReadWriteTexture2D(Device device)
{
int[] data = Enumerable.Range(0, 32 * 32).ToArray();
using ReadWriteTexture2D<int> source = Gpu.Default.AllocateReadWriteTexture2D(data, 32, 32);
using ReadWriteTexture2D<int> destination = Gpu.Default.AllocateReadWriteTexture2D<int>(32, 32);
using ReadWriteTexture2D<int> source = device.Get().AllocateReadWriteTexture2D(data, 32, 32);
using ReadWriteTexture2D<int> destination = device.Get().AllocateReadWriteTexture2D<int>(32, 32);
Gpu.Default.For(source.Width, source.Height, new ReadWriteTexture2DKernel(source, destination));
device.Get().For(source.Width, source.Height, new ReadWriteTexture2DKernel(source, destination));
int[] result = new int[data.Length];
+22 -30
ファイルの表示
@@ -3,6 +3,7 @@ using System.Numerics;
using System.Reflection;
using ComputeSharp.__Internals;
using ComputeSharp.Resources;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -12,44 +13,35 @@ namespace ComputeSharp.Tests
{
public partial class Texture3DTests
{
[TestMethod]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Bgra32), typeof(Vector4))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Bgra32), typeof(Float4))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(R16), typeof(float))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(R8), typeof(float))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg16), typeof(Vector2))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg16), typeof(Float2))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg32), typeof(Vector2))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg32), typeof(Float2))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba32), typeof(Vector4))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba32), typeof(Float4))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba64), typeof(Vector4))]
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba64), typeof(Float4))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Bgra32), typeof(Vector4))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Bgra32), typeof(Float4))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(R16), typeof(float))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(R8), typeof(float))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg16), typeof(Vector2))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg16), typeof(Float2))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg32), typeof(Vector2))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg32), typeof(Float2))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba32), typeof(Vector4))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba32), typeof(Float4))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba64), typeof(Vector4))]
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba64), typeof(Float4))]
public void Allocate_Uninitialized_Pixel_Ok(Type textureType, Type t, Type tPixel)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture3D<,>))]
[Resource(typeof(ReadWriteTexture3D<,>))]
[Data(typeof(Bgra32), typeof(Vector4))]
[Data(typeof(Bgra32), typeof(Float4))]
[Data(typeof(R16), typeof(float))]
[Data(typeof(R8), typeof(float))]
[Data(typeof(Rg16), typeof(Vector2))]
[Data(typeof(Rg16), typeof(Float2))]
[Data(typeof(Rg32), typeof(Vector2))]
[Data(typeof(Rg32), typeof(Float2))]
[Data(typeof(Rgba32), typeof(Vector4))]
[Data(typeof(Rgba32), typeof(Float4))]
[Data(typeof(Rgba64), typeof(Vector4))]
[Data(typeof(Rgba64), typeof(Float4))]
public void Allocate_Uninitialized_Pixel_Ok(Device device, Type textureType, Type t, Type tPixel)
{
static void Test<T, TPixel>(Type textureType)
static void Test<T, TPixel>(Device device, Type textureType)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
using Texture3D<T> texture = Gpu.Default.AllocateTexture3D<T, TPixel>(textureType, 128, 128, 2);
using Texture3D<T> texture = device.Get().AllocateTexture3D<T, TPixel>(textureType, 128, 128, 2);
Assert.IsNotNull(texture);
Assert.AreEqual(texture.Width, 128);
Assert.AreEqual(texture.Height, 128);
Assert.AreEqual(texture.Depth, 2);
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
Assert.AreSame(texture.GraphicsDevice, device.Get());
if (textureType == typeof(ReadOnlyTexture3D<,>))
{
@@ -63,7 +55,7 @@ namespace ComputeSharp.Tests
try
{
new Action<Type>(Test<Rgba32, Vector4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new[] { textureType });
new Action<Device, Type>(Test<Rgba32, Vector4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new object[] { device, textureType });
}
catch (TargetInvocationException e) when (e.InnerException is not null)
{
+53 -51
ファイルの表示
@@ -1,109 +1,111 @@
using System;
using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
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)
[CombinatorialTestMethod]
[AllDevices]
[Data(typeof(Bgra32), typeof(Vector4))]
[Data(typeof(Bgra32), typeof(Float4))]
[Data(typeof(R16), typeof(float))]
[Data(typeof(R8), typeof(float))]
[Data(typeof(Rg16), typeof(Vector2))]
[Data(typeof(Rg16), typeof(Float2))]
[Data(typeof(Rg32), typeof(Vector2))]
[Data(typeof(Rg32), typeof(Float2))]
[Data(typeof(Rgba32), typeof(Vector4))]
[Data(typeof(Rgba32), typeof(Float4))]
[Data(typeof(Rgba64), typeof(Vector4))]
[Data(typeof(Rgba64), typeof(Float4))]
public void Dispatch_NormalizedTexture3D(Device device, Type t, Type tPixel)
{
if (t == typeof(Bgra32) && tPixel == typeof(Vector4))
{
using ReadOnlyTexture3D<Bgra32, Vector4> source = Gpu.Default.AllocateReadOnlyTexture3D<Bgra32, Vector4>(128, 128, 2);
using ReadWriteTexture3D<Bgra32, Vector4> destination = Gpu.Default.AllocateReadWriteTexture3D<Bgra32, Vector4>(128, 128, 2);
using ReadOnlyTexture3D<Bgra32, Vector4> source = device.Get().AllocateReadOnlyTexture3D<Bgra32, Vector4>(128, 128, 2);
using ReadWriteTexture3D<Bgra32, Vector4> destination = device.Get().AllocateReadWriteTexture3D<Bgra32, Vector4>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Bgra32_Vector4(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_Bgra32_Vector4(source, destination));
}
if (t == typeof(Bgra32) && tPixel == typeof(Float4))
{
using ReadOnlyTexture3D<Bgra32, Float4> source = Gpu.Default.AllocateReadOnlyTexture3D<Bgra32, Float4>(128, 128, 2);
using ReadWriteTexture3D<Bgra32, Float4> destination = Gpu.Default.AllocateReadWriteTexture3D<Bgra32, Float4>(128, 128, 2);
using ReadOnlyTexture3D<Bgra32, Float4> source = device.Get().AllocateReadOnlyTexture3D<Bgra32, Float4>(128, 128, 2);
using ReadWriteTexture3D<Bgra32, Float4> destination = device.Get().AllocateReadWriteTexture3D<Bgra32, Float4>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Bgra32_Float4(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_Bgra32_Float4(source, destination));
}
if (t == typeof(R16) && tPixel == typeof(float))
{
using ReadOnlyTexture3D<R16, float> source = Gpu.Default.AllocateReadOnlyTexture3D<R16, float>(128, 128, 2);
using ReadWriteTexture3D<R16, float> destination = Gpu.Default.AllocateReadWriteTexture3D<R16, float>(128, 128, 2);
using ReadOnlyTexture3D<R16, float> source = device.Get().AllocateReadOnlyTexture3D<R16, float>(128, 128, 2);
using ReadWriteTexture3D<R16, float> destination = device.Get().AllocateReadWriteTexture3D<R16, float>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_R16_float(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_R16_float(source, destination));
}
if (t == typeof(R8) && tPixel == typeof(float))
{
using ReadOnlyTexture3D<R8, float> source = Gpu.Default.AllocateReadOnlyTexture3D<R8, float>(128, 128, 2);
using ReadWriteTexture3D<R8, float> destination = Gpu.Default.AllocateReadWriteTexture3D<R8, float>(128, 128, 2);
using ReadOnlyTexture3D<R8, float> source = device.Get().AllocateReadOnlyTexture3D<R8, float>(128, 128, 2);
using ReadWriteTexture3D<R8, float> destination = device.Get().AllocateReadWriteTexture3D<R8, float>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_R8_float(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_R8_float(source, destination));
}
if (t == typeof(Rg16) && tPixel == typeof(Vector2))
{
using ReadOnlyTexture3D<Rg16, Vector2> source = Gpu.Default.AllocateReadOnlyTexture3D<Rg16, Vector2>(128, 128, 2);
using ReadWriteTexture3D<Rg16, Vector2> destination = Gpu.Default.AllocateReadWriteTexture3D<Rg16, Vector2>(128, 128, 2);
using ReadOnlyTexture3D<Rg16, Vector2> source = device.Get().AllocateReadOnlyTexture3D<Rg16, Vector2>(128, 128, 2);
using ReadWriteTexture3D<Rg16, Vector2> destination = device.Get().AllocateReadWriteTexture3D<Rg16, Vector2>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg16_Vector2(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_Rg16_Vector2(source, destination));
}
if (t == typeof(Rg16) && tPixel == typeof(Float2))
{
using ReadOnlyTexture3D<Rg16, Float2> source = Gpu.Default.AllocateReadOnlyTexture3D<Rg16, Float2>(128, 128, 2);
using ReadWriteTexture3D<Rg16, Float2> destination = Gpu.Default.AllocateReadWriteTexture3D<Rg16, Float2>(128, 128, 2);
using ReadOnlyTexture3D<Rg16, Float2> source = device.Get().AllocateReadOnlyTexture3D<Rg16, Float2>(128, 128, 2);
using ReadWriteTexture3D<Rg16, Float2> destination = device.Get().AllocateReadWriteTexture3D<Rg16, Float2>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg16_Float2(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_Rg16_Float2(source, destination));
}
if (t == typeof(Rg32) && tPixel == typeof(Vector2))
{
using ReadOnlyTexture3D<Rg32, Vector2> source = Gpu.Default.AllocateReadOnlyTexture3D<Rg32, Vector2>(128, 128, 2);
using ReadWriteTexture3D<Rg32, Vector2> destination = Gpu.Default.AllocateReadWriteTexture3D<Rg32, Vector2>(128, 128, 2);
using ReadOnlyTexture3D<Rg32, Vector2> source = device.Get().AllocateReadOnlyTexture3D<Rg32, Vector2>(128, 128, 2);
using ReadWriteTexture3D<Rg32, Vector2> destination = device.Get().AllocateReadWriteTexture3D<Rg32, Vector2>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg32_Vector2(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_Rg32_Vector2(source, destination));
}
if (t == typeof(Rg32) && tPixel == typeof(Float2))
{
using ReadOnlyTexture3D<Rg32, Float2> source = Gpu.Default.AllocateReadOnlyTexture3D<Rg32, Float2>(128, 128, 2);
using ReadWriteTexture3D<Rg32, Float2> destination = Gpu.Default.AllocateReadWriteTexture3D<Rg32, Float2>(128, 128, 2);
using ReadOnlyTexture3D<Rg32, Float2> source = device.Get().AllocateReadOnlyTexture3D<Rg32, Float2>(128, 128, 2);
using ReadWriteTexture3D<Rg32, Float2> destination = device.Get().AllocateReadWriteTexture3D<Rg32, Float2>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg32_Float2(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_Rg32_Float2(source, destination));
}
if (t == typeof(Rgba32) && tPixel == typeof(Vector4))
{
using ReadOnlyTexture3D<Rgba32, Vector4> source = Gpu.Default.AllocateReadOnlyTexture3D<Rgba32, Vector4>(128, 128, 2);
using ReadWriteTexture3D<Rgba32, Vector4> destination = Gpu.Default.AllocateReadWriteTexture3D<Rgba32, Vector4>(128, 128, 2);
using ReadOnlyTexture3D<Rgba32, Vector4> source = device.Get().AllocateReadOnlyTexture3D<Rgba32, Vector4>(128, 128, 2);
using ReadWriteTexture3D<Rgba32, Vector4> destination = device.Get().AllocateReadWriteTexture3D<Rgba32, Vector4>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba32_Vector4(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_Rgba32_Vector4(source, destination));
}
if (t == typeof(Rgba32) && tPixel == typeof(Float4))
{
using ReadOnlyTexture3D<Rgba32, Float4> source = Gpu.Default.AllocateReadOnlyTexture3D<Rgba32, Float4>(128, 128, 2);
using ReadWriteTexture3D<Rgba32, Float4> destination = Gpu.Default.AllocateReadWriteTexture3D<Rgba32, Float4>(128, 128, 2);
using ReadOnlyTexture3D<Rgba32, Float4> source = device.Get().AllocateReadOnlyTexture3D<Rgba32, Float4>(128, 128, 2);
using ReadWriteTexture3D<Rgba32, Float4> destination = device.Get().AllocateReadWriteTexture3D<Rgba32, Float4>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba32_Float4(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_Rgba32_Float4(source, destination));
}
if (t == typeof(Rgba64) && tPixel == typeof(Vector4))
{
using ReadOnlyTexture3D<Rgba64, Vector4> source = Gpu.Default.AllocateReadOnlyTexture3D<Rgba64, Vector4>(128, 128, 2);
using ReadWriteTexture3D<Rgba64, Vector4> destination = Gpu.Default.AllocateReadWriteTexture3D<Rgba64, Vector4>(128, 128, 2);
using ReadOnlyTexture3D<Rgba64, Vector4> source = device.Get().AllocateReadOnlyTexture3D<Rgba64, Vector4>(128, 128, 2);
using ReadWriteTexture3D<Rgba64, Vector4> destination = device.Get().AllocateReadWriteTexture3D<Rgba64, Vector4>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba64_Vector4(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_Rgba64_Vector4(source, destination));
}
if (t == typeof(Rgba64) && tPixel == typeof(Float4))
{
using ReadOnlyTexture3D<Rgba64, Float4> source = Gpu.Default.AllocateReadOnlyTexture3D<Rgba64, Float4>(128, 128, 2);
using ReadWriteTexture3D<Rgba64, Float4> destination = Gpu.Default.AllocateReadWriteTexture3D<Rgba64, Float4>(128, 128, 2);
using ReadOnlyTexture3D<Rgba64, Float4> source = device.Get().AllocateReadOnlyTexture3D<Rgba64, Float4>(128, 128, 2);
using ReadWriteTexture3D<Rgba64, Float4> destination = device.Get().AllocateReadWriteTexture3D<Rgba64, Float4>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba64_Float4(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_Rgba64_Float4(source, destination));
}
}
+9 -7
ファイルの表示
@@ -25,22 +25,24 @@ IEnumerable<(string T, string TPixel)> EnumerateTypes()
#>
using System;
using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
namespace ComputeSharp.Tests
{
public partial class Texture3DTests
{
[TestMethod]
[CombinatorialTestMethod]
[AllDevices]
<#
foreach (var (t, tPixel) in EnumerateTypes())
{
#>
[DataRow(typeof(<#=t#>), typeof(<#=tPixel#>))]
[Data(typeof(<#=t#>), typeof(<#=tPixel#>))]
<#
}
#>
public void Dispatch_NormalizedTexture3D(Type t, Type tPixel)
public void Dispatch_NormalizedTexture3D(Device device, Type t, Type tPixel)
{
<#
foreach (var (t, tPixel) in EnumerateTypes())
@@ -48,10 +50,10 @@ 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);
using ReadOnlyTexture3D<<#=t#>, <#=tPixel#>> source = device.Get().AllocateReadOnlyTexture3D<<#=t#>, <#=tPixel#>>(128, 128, 2);
using ReadWriteTexture3D<<#=t#>, <#=tPixel#>> destination = device.Get().AllocateReadWriteTexture3D<<#=t#>, <#=tPixel#>>(128, 128, 2);
Gpu.Default.For(128, 128, 2, new Shader_Unorm_<#=t#>_<#=tPixel#>(source, destination));
device.Get().For(128, 128, 2, new Shader_Unorm_<#=t#>_<#=tPixel#>(source, destination));
}
<#
}
+80 -92
ファイルの表示
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using ComputeSharp.Resources;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.Toolkit.HighPerformance.Extensions;
using Microsoft.Toolkit.HighPerformance.Memory;
@@ -12,59 +13,56 @@ namespace ComputeSharp.Tests
[TestCategory("Texture3D")]
public partial class Texture3DTests
{
[TestMethod]
[DataRow(typeof(ReadOnlyTexture3D<>))]
[DataRow(typeof(ReadWriteTexture3D<>))]
public void Allocate_Uninitialized_Ok(Type textureType)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture3D<>))]
[Resource(typeof(ReadWriteTexture3D<>))]
public void Allocate_Uninitialized_Ok(Device device, Type textureType)
{
using Texture3D<float> texture = Gpu.Default.AllocateTexture3D<float>(textureType, 64, 64, 12);
using Texture3D<float> texture = device.Get().AllocateTexture3D<float>(textureType, 64, 64, 12);
Assert.IsNotNull(texture);
Assert.AreEqual(texture.Width, 64);
Assert.AreEqual(texture.Height, 64);
Assert.AreEqual(texture.Depth, 12);
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
Assert.AreSame(texture.GraphicsDevice, device.Get());
}
[TestMethod]
[DataRow(typeof(ReadOnlyTexture3D<>), 128, -14253, 4)]
[DataRow(typeof(ReadOnlyTexture3D<>), 128, -1, 4)]
[DataRow(typeof(ReadOnlyTexture3D<>), 0, -4314, 4)]
[DataRow(typeof(ReadOnlyTexture3D<>), -14, -53, 4)]
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 12, -1)]
[DataRow(typeof(ReadOnlyTexture3D<>), 2, 4, ushort.MaxValue + 1)]
[DataRow(typeof(ReadWriteTexture3D<>), 128, -14253, 4)]
[DataRow(typeof(ReadWriteTexture3D<>), 128, -1, 4)]
[DataRow(typeof(ReadWriteTexture3D<>), 0, -4314, 4)]
[DataRow(typeof(ReadWriteTexture3D<>), -14, -53, 4)]
[DataRow(typeof(ReadWriteTexture3D<>), 12, 12, -1)]
[DataRow(typeof(ReadWriteTexture3D<>), 2, 4, ushort.MaxValue + 1)]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture3D<>))]
[Resource(typeof(ReadWriteTexture3D<>))]
[Data(128, -14253, 4)]
[Data(128, -1, 4)]
[Data(0, -4314, 4)]
[Data(-14, -53, 4)]
[Data(12, 12, -1)]
[Data(2, 4, ushort.MaxValue + 1)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Allocate_Uninitialized_Fail(Type textureType, int width, int height, int depth)
public void Allocate_Uninitialized_Fail(Device device, Type textureType, int width, int height, int depth)
{
using Texture3D<float> texture = Gpu.Default.AllocateTexture3D<float>(textureType, width, height, depth);
using Texture3D<float> texture = device.Get().AllocateTexture3D<float>(textureType, width, height, depth);
}
[TestMethod]
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 12, 4)]
[DataRow(typeof(ReadOnlyTexture3D<>), 2, 12, 4)]
[DataRow(typeof(ReadOnlyTexture3D<>), 64, 64, 1)]
[DataRow(typeof(ReadOnlyTexture3D<>), 64, 27, 3)]
[DataRow(typeof(ReadWriteTexture3D<>), 12, 12, 4)]
[DataRow(typeof(ReadWriteTexture3D<>), 2, 12, 4)]
[DataRow(typeof(ReadWriteTexture3D<>), 64, 64, 1)]
[DataRow(typeof(ReadWriteTexture3D<>), 64, 27, 3)]
public void Allocate_FromArray(Type textureType, int width, int height, int depth)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture3D<>))]
[Resource(typeof(ReadWriteTexture3D<>))]
[Data(12, 12, 4)]
[Data(2, 12, 4)]
[Data(64, 64, 1)]
[Data(64, 27, 3)]
public void Allocate_FromArray(Device device, Type textureType, int width, int height, int depth)
{
float[] data = Enumerable.Range(0, width * height * depth).Select(static i => (float)i).ToArray();
using Texture3D<float> texture = Gpu.Default.AllocateTexture3D(textureType, data, width, height, depth);
using Texture3D<float> texture = device.Get().AllocateTexture3D(textureType, data, width, height, depth);
Assert.IsNotNull(texture);
Assert.AreEqual(texture.Width, width);
Assert.AreEqual(texture.Height, height);
Assert.AreEqual(texture.Depth, depth);
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
Assert.AreSame(texture.GraphicsDevice, device.Get());
float[,,] result = texture.ToArray();
@@ -84,48 +82,42 @@ namespace ComputeSharp.Tests
CollectionAssert.AreEqual(flat, data);
}
[TestMethod]
[DataRow(typeof(ReadOnlyTexture3D<>))]
[DataRow(typeof(ReadWriteTexture3D<>))]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture3D<>))]
[Resource(typeof(ReadWriteTexture3D<>))]
[ExpectedException(typeof(ObjectDisposedException))]
public void UsageAfterDispose(Type textureType)
public void UsageAfterDispose(Device device, Type textureType)
{
using Texture3D<float> texture = Gpu.Default.AllocateTexture3D<float>(textureType, 10, 10, 4);
using Texture3D<float> texture = device.Get().AllocateTexture3D<float>(textureType, 10, 10, 4);
texture.Dispose();
_ = texture.ToArray();
}
[TestMethod]
[DataRow(typeof(ReadOnlyTexture3D<>), 0, 0, 0, 64, 64, 3)]
[DataRow(typeof(ReadOnlyTexture3D<>), 0, 14, 0, 64, 50, 3)]
[DataRow(typeof(ReadOnlyTexture3D<>), 0, 14, 1, 64, 50, 2)]
[DataRow(typeof(ReadOnlyTexture3D<>), 14, 0, 1, 50, 64, 2)]
[DataRow(typeof(ReadOnlyTexture3D<>), 10, 10, 2, 54, 54, 1)]
[DataRow(typeof(ReadOnlyTexture3D<>), 20, 20, 0, 32, 27, 3)]
[DataRow(typeof(ReadOnlyTexture3D<>), 60, 0, 0, 4, 64, 3)]
[DataRow(typeof(ReadOnlyTexture3D<>), 0, 60, 2, 64, 4, 1)]
[DataRow(typeof(ReadOnlyTexture3D<>), 63, 2, 0, 1, 60, 2)]
[DataRow(typeof(ReadOnlyTexture3D<>), 2, 63, 1, 60, 1, 2)]
[DataRow(typeof(ReadWriteTexture3D<>), 0, 0, 0, 64, 64, 3)]
[DataRow(typeof(ReadWriteTexture3D<>), 0, 14, 0, 64, 50, 3)]
[DataRow(typeof(ReadWriteTexture3D<>), 0, 14, 1, 64, 50, 2)]
[DataRow(typeof(ReadWriteTexture3D<>), 14, 0, 1, 50, 64, 2)]
[DataRow(typeof(ReadWriteTexture3D<>), 10, 10, 2, 54, 54, 1)]
[DataRow(typeof(ReadWriteTexture3D<>), 20, 20, 0, 32, 27, 3)]
[DataRow(typeof(ReadWriteTexture3D<>), 60, 0, 0, 4, 64, 3)]
[DataRow(typeof(ReadWriteTexture3D<>), 0, 60, 2, 64, 4, 1)]
[DataRow(typeof(ReadWriteTexture3D<>), 63, 2, 0, 1, 60, 2)]
[DataRow(typeof(ReadWriteTexture3D<>), 2, 63, 1, 60, 1, 2)]
public void GetData_RangeToVoid_Ok(Type textureType, int x, int y, int z, int width, int height, int depth)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture3D<>))]
[Resource(typeof(ReadWriteTexture3D<>))]
[Data(0, 0, 0, 64, 64, 3)]
[Data(0, 14, 0, 64, 50, 3)]
[Data(0, 14, 1, 64, 50, 2)]
[Data(14, 0, 1, 50, 64, 2)]
[Data(10, 10, 2, 54, 54, 1)]
[Data(20, 20, 0, 32, 27, 3)]
[Data(60, 0, 0, 4, 64, 3)]
[Data(0, 60, 2, 64, 4, 1)]
[Data(63, 2, 0, 1, 60, 2)]
[Data(2, 63, 1, 60, 1, 2)]
public void GetData_RangeToVoid_Ok(Device device, Type textureType, int x, int y, int z, int width, int height, int depth)
{
int[,,] array = new int[3, 64, 64];
foreach (var item in array.AsSpan().Enumerate())
item.Value = item.Index;
using Texture3D<int> texture = Gpu.Default.AllocateTexture3D(textureType, array);
using Texture3D<int> texture = device.Get().AllocateTexture3D(textureType, array);
int[,,] result = new int[depth, height, width];
@@ -141,46 +133,41 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
[DataRow(typeof(ReadOnlyTexture3D<>), 0, -1, 0, 50, 50, 2)]
[DataRow(typeof(ReadOnlyTexture3D<>), -1, 0, 0, 50, 50, 3)]
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 0, 0, -1, 50, 1)]
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 0, 0, 20, 50, 0)]
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 0, 1, 20, -1, 2)]
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 20, 2, 20, 50, 1)]
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 20, 0, 60, 20, 3)]
[DataRow(typeof(ReadOnlyTexture3D<>), 80, 20, 2, 40, 20, 1)]
[DataRow(typeof(ReadOnlyTexture3D<>), 0, 80, 2, 40, 20, 1)]
[DataRow(typeof(ReadWriteTexture3D<>), 0, -1, 0, 50, 50, 2)]
[DataRow(typeof(ReadWriteTexture3D<>), -1, 0, 0, 50, 50, 3)]
[DataRow(typeof(ReadWriteTexture3D<>), 12, 0, 0, -1, 50, 1)]
[DataRow(typeof(ReadWriteTexture3D<>), 12, 0, 0, 20, 50, 0)]
[DataRow(typeof(ReadWriteTexture3D<>), 12, 0, 1, 20, -1, 2)]
[DataRow(typeof(ReadWriteTexture3D<>), 12, 20, 2, 20, 50, 1)]
[DataRow(typeof(ReadWriteTexture3D<>), 12, 20, 0, 60, 20, 3)]
[DataRow(typeof(ReadWriteTexture3D<>), 80, 20, 2, 40, 20, 1)]
[DataRow(typeof(ReadWriteTexture3D<>), 0, 80, 2, 40, 20, 1)]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(ReadOnlyTexture3D<>))]
[Resource(typeof(ReadWriteTexture3D<>))]
[Data(0, -1, 0, 50, 50, 2)]
[Data(-1, 0, 0, 50, 50, 3)]
[Data(12, 0, 0, -1, 50, 1)]
[Data(12, 0, 0, 20, 50, 0)]
[Data(12, 0, 1, 20, -1, 2)]
[Data(12, 20, 2, 20, 50, 1)]
[Data(12, 20, 0, 60, 20, 3)]
[Data(80, 20, 2, 40, 20, 1)]
[Data(0, 80, 2, 40, 20, 1)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void GetData_RangeToVoid_Fail(Type textureType, int x, int y, int z, int width, int height, int depth)
public void GetData_RangeToVoid_Fail(Device device, Type textureType, int x, int y, int z, int width, int height, int depth)
{
float[] array = Enumerable.Range(0, 64 * 64 * 3).Select(static i => (float)i).ToArray();
using Texture3D<float> texture = Gpu.Default.AllocateTexture3D(textureType, array, 64, 64, 3);
using Texture3D<float> texture = device.Get().AllocateTexture3D(textureType, array, 64, 64, 3);
float[] result = new float[array.Length];
texture.CopyTo(result, x, y, z, width, height, depth);
}
[TestMethod]
public void Dispatch_ReadOnlyTexture3D()
[CombinatorialTestMethod]
[AllDevices]
public void Dispatch_ReadOnlyTexture3D(Device device)
{
int[] data = Enumerable.Range(0, 32 * 32 * 3).ToArray();
using ReadOnlyTexture3D<int> source = Gpu.Default.AllocateReadOnlyTexture3D(data, 32, 32, 3);
using ReadWriteBuffer<int> destination = Gpu.Default.AllocateReadWriteBuffer<int>(data.Length);
using ReadOnlyTexture3D<int> source = device.Get().AllocateReadOnlyTexture3D(data, 32, 32, 3);
using ReadWriteBuffer<int> destination = device.Get().AllocateReadWriteBuffer<int>(data.Length);
Gpu.Default.For(source.Width, source.Height, source.Depth, new ReadOnlyTexture3DKernel(source, destination));
device.Get().For(source.Width, source.Height, source.Depth, new ReadOnlyTexture3DKernel(source, destination));
int[] result = destination.ToArray();
@@ -199,15 +186,16 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
public void Dispatch_ReadWriteTexture2D()
[CombinatorialTestMethod]
[AllDevices]
public void Dispatch_ReadWriteTexture2D(Device device)
{
int[] data = Enumerable.Range(0, 32 * 32 * 3).ToArray();
using ReadWriteTexture3D<int> source = Gpu.Default.AllocateReadWriteTexture3D(data, 32, 32, 3);
using ReadWriteTexture3D<int> destination = Gpu.Default.AllocateReadWriteTexture3D<int>(32, 32, 3);
using ReadWriteTexture3D<int> source = device.Get().AllocateReadWriteTexture3D(data, 32, 32, 3);
using ReadWriteTexture3D<int> destination = device.Get().AllocateReadWriteTexture3D<int>(32, 32, 3);
Gpu.Default.For(source.Width, source.Height, source.Depth, new ReadWriteTexture3DKernel(source, destination));
device.Get().For(source.Width, source.Height, source.Depth, new ReadWriteTexture3DKernel(source, destination));
int[] result = new int[data.Length];
+50 -42
ファイルの表示
@@ -2,6 +2,7 @@
using System.Linq;
using System.Runtime.CompilerServices;
using ComputeSharp.Resources;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.Toolkit.HighPerformance.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -12,12 +13,13 @@ namespace ComputeSharp.Tests
[TestCategory("TransferBuffer")]
public partial class TransferBufferTests
{
[TestMethod]
[DataRow(typeof(UploadBuffer<>))]
[DataRow(typeof(ReadBackBuffer<>))]
public unsafe void Allocate_Uninitialized_Ok(Type bufferType)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(UploadBuffer<>))]
[Resource(typeof(ReadBackBuffer<>))]
public unsafe void Allocate_Uninitialized_Ok(Device device, Type bufferType)
{
using TransferBuffer<float> buffer = Gpu.Default.AllocateTransferBuffer<float>(bufferType, 128);
using TransferBuffer<float> buffer = device.Get().AllocateTransferBuffer<float>(bufferType, 128);
Assert.IsNotNull(buffer);
Assert.AreEqual(buffer.Length, 128);
@@ -25,41 +27,44 @@ namespace ComputeSharp.Tests
Assert.AreEqual(buffer.Span.Length, 128);
Assert.IsTrue(Unsafe.AreSame(ref buffer.Memory.Span[0], ref buffer.Span[0]));
Assert.IsTrue(Unsafe.AreSame(ref *(float*)buffer.Memory.Pin().Pointer, ref buffer.Span[0]));
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
Assert.AreSame(buffer.GraphicsDevice, device.Get());
}
[TestMethod]
[DataRow(typeof(UploadBuffer<>), -247824)]
[DataRow(typeof(UploadBuffer<>), -1)]
[DataRow(typeof(ReadBackBuffer<>), -247824)]
[DataRow(typeof(ReadBackBuffer<>), -1)]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(UploadBuffer<>))]
[Resource(typeof(ReadBackBuffer<>))]
[Data(-247824)]
[Data(-1)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Allocate_Uninitialized_Fail(Type bufferType, int length)
public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int length)
{
using TransferBuffer<float> buffer = Gpu.Default.AllocateTransferBuffer<float>(bufferType, length);
using TransferBuffer<float> buffer = device.Get().AllocateTransferBuffer<float>(bufferType, length);
}
[TestMethod]
[DataRow(typeof(UploadBuffer<>))]
[DataRow(typeof(ReadBackBuffer<>))]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(UploadBuffer<>))]
[Resource(typeof(ReadBackBuffer<>))]
[ExpectedException(typeof(ObjectDisposedException))]
public void UsageAfterDispose(Type bufferType)
public void UsageAfterDispose(Device device, Type bufferType)
{
using TransferBuffer<float> buffer = Gpu.Default.AllocateTransferBuffer<float>(bufferType, 128);
using TransferBuffer<float> buffer = device.Get().AllocateTransferBuffer<float>(bufferType, 128);
buffer.Dispose();
_ = buffer.Span;
}
[TestMethod]
public void Allocate_UploadBuffer_Copy_Full()
[CombinatorialTestMethod]
[AllDevices]
public void Allocate_UploadBuffer_Copy_Full(Device device)
{
using UploadBuffer<int> uploadBuffer = Gpu.Default.AllocateUploadBuffer<int>(4096);
using UploadBuffer<int> uploadBuffer = device.Get().AllocateUploadBuffer<int>(4096);
new Random(42).NextBytes(uploadBuffer.Span.AsBytes());
using ReadOnlyBuffer<int> readOnlyBuffer = Gpu.Default.AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
uploadBuffer.CopyTo(readOnlyBuffer);
@@ -69,18 +74,19 @@ namespace ComputeSharp.Tests
Assert.IsTrue(uploadBuffer.Span.SequenceEqual(result));
}
[TestMethod]
[DataRow(0, 0, 4096)]
[DataRow(128, 0, 2048)]
[DataRow(0, 128, 2048)]
[DataRow(97, 33, 512)]
public void Allocate_UploadBuffer_Copy_Range(int destinationOffset, int bufferOffset, int count)
[CombinatorialTestMethod]
[AllDevices]
[Data(0, 0, 4096)]
[Data(128, 0, 2048)]
[Data(0, 128, 2048)]
[Data(97, 33, 512)]
public void Allocate_UploadBuffer_Copy_Range(Device device, int destinationOffset, int bufferOffset, int count)
{
using UploadBuffer<int> uploadBuffer = Gpu.Default.AllocateUploadBuffer<int>(4096);
using UploadBuffer<int> uploadBuffer = device.Get().AllocateUploadBuffer<int>(4096);
new Random(42).NextBytes(uploadBuffer.Span.AsBytes());
using ReadOnlyBuffer<int> readOnlyBuffer = Gpu.Default.AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
uploadBuffer.CopyTo(readOnlyBuffer, destinationOffset, bufferOffset, count);
@@ -90,15 +96,16 @@ namespace ComputeSharp.Tests
Assert.IsTrue(uploadBuffer.Span.Slice(bufferOffset, count).SequenceEqual(result));
}
[TestMethod]
public void Allocate_ReadBackBuffer_Copy_Full()
[CombinatorialTestMethod]
[AllDevices]
public void Allocate_ReadBackBuffer_Copy_Full(Device device)
{
int[] source = new int[4096];
new Random(42).NextBytes(source.AsSpan().AsBytes());
using ReadOnlyBuffer<int> readOnlyBuffer = Gpu.Default.AllocateReadOnlyBuffer(source);
using ReadBackBuffer<int> readBackBuffer = Gpu.Default.AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer(source);
using ReadBackBuffer<int> readBackBuffer = device.Get().AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
readOnlyBuffer.CopyTo(readBackBuffer);
@@ -106,19 +113,20 @@ namespace ComputeSharp.Tests
Assert.IsTrue(source.AsSpan().SequenceEqual(readBackBuffer.Span));
}
[TestMethod]
[DataRow(0, 0, 4096)]
[DataRow(128, 0, 2048)]
[DataRow(0, 128, 2048)]
[DataRow(97, 33, 512)]
public void Allocate_ReadBackBuffer_Copy_Range(int destinationOffset, int bufferOffset, int count)
[CombinatorialTestMethod]
[AllDevices]
[Data(0, 0, 4096)]
[Data(128, 0, 2048)]
[Data(0, 128, 2048)]
[Data(97, 33, 512)]
public void Allocate_ReadBackBuffer_Copy_Range(Device device, int destinationOffset, int bufferOffset, int count)
{
int[] source = new int[4096];
new Random(42).NextBytes(source.AsSpan().AsBytes());
using ReadOnlyBuffer<int> readOnlyBuffer = Gpu.Default.AllocateReadOnlyBuffer(source);
using ReadBackBuffer<int> readBackBuffer = Gpu.Default.AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer(source);
using ReadBackBuffer<int> readBackBuffer = device.Get().AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
readOnlyBuffer.CopyTo(readBackBuffer, destinationOffset, bufferOffset, count);
+52 -46
ファイルの表示
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using ComputeSharp.Resources;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.Toolkit.HighPerformance.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -11,60 +12,62 @@ namespace ComputeSharp.Tests
[TestCategory("TransferTexture2D")]
public partial class TransferTexture2DTests
{
[TestMethod]
[DataRow(typeof(UploadTexture2D<>))]
[DataRow(typeof(ReadBackTexture2D<>))]
public unsafe void Allocate_Uninitialized_Ok(Type bufferType)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(UploadTexture2D<>))]
[Resource(typeof(ReadBackTexture2D<>))]
public unsafe void Allocate_Uninitialized_Ok(Device device, Type bufferType)
{
using TransferTexture2D<float> buffer = Gpu.Default.AllocateTransferTexture2D<float>(bufferType, 128, 256);
using TransferTexture2D<float> buffer = device.Get().AllocateTransferTexture2D<float>(bufferType, 128, 256);
Assert.IsNotNull(buffer);
Assert.AreEqual(buffer.Width, 128);
Assert.AreEqual(buffer.Height, 256);
Assert.AreEqual(buffer.View.Width, 128);
Assert.AreEqual(buffer.View.Height, 256);
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
Assert.AreSame(buffer.GraphicsDevice, device.Get());
}
[TestMethod]
[DataRow(typeof(UploadTexture2D<>), 128, -14253)]
[DataRow(typeof(UploadTexture2D<>), 128, -1)]
[DataRow(typeof(UploadTexture2D<>), 0, -4314)]
[DataRow(typeof(UploadTexture2D<>), -14, -53)]
[DataRow(typeof(ReadBackTexture2D<>), 128, -14253)]
[DataRow(typeof(ReadBackTexture2D<>), 128, -1)]
[DataRow(typeof(ReadBackTexture2D<>), 0, -4314)]
[DataRow(typeof(ReadBackTexture2D<>), -14, -53)]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(UploadTexture2D<>))]
[Resource(typeof(ReadBackTexture2D<>))]
[Data(128, -14253)]
[Data(128, -1)]
[Data(0, -4314)]
[Data(-14, -53)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Allocate_Uninitialized_Fail(Type bufferType, int width, int height)
public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int width, int height)
{
using TransferTexture2D<float> buffer = Gpu.Default.AllocateTransferTexture2D<float>(bufferType, width, height);
using TransferTexture2D<float> buffer = device.Get().AllocateTransferTexture2D<float>(bufferType, width, height);
}
[TestMethod]
[DataRow(typeof(UploadTexture2D<>))]
[DataRow(typeof(ReadBackTexture2D<>))]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(UploadTexture2D<>))]
[Resource(typeof(ReadBackTexture2D<>))]
[ExpectedException(typeof(ObjectDisposedException))]
public void UsageAfterDispose(Type bufferType)
public void UsageAfterDispose(Device device, Type bufferType)
{
using TransferTexture2D<float> buffer = Gpu.Default.AllocateTransferTexture2D<float>(bufferType, 32, 32);
using TransferTexture2D<float> buffer = device.Get().AllocateTransferTexture2D<float>(bufferType, 32, 32);
buffer.Dispose();
_ = buffer.View;
}
[TestMethod]
public void Allocate_UploadTexture2D_Copy_Full()
[CombinatorialTestMethod]
[AllDevices]
public void Allocate_UploadTexture2D_Copy_Full(Device device)
{
using UploadTexture2D<int> uploadTexture2D = Gpu.Default.AllocateUploadTexture2D<int>(256, 256);
using UploadTexture2D<int> uploadTexture2D = device.Get().AllocateUploadTexture2D<int>(256, 256);
for (int i = 0; i < uploadTexture2D.Height; i++)
{
new Random(i).NextBytes(uploadTexture2D.View.GetRowSpan(i).AsBytes());
}
using ReadOnlyTexture2D<int> readOnlyTexture2D = Gpu.Default.AllocateReadOnlyTexture2D<int>(uploadTexture2D.Width, uploadTexture2D.Height);
using ReadOnlyTexture2D<int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D<int>(uploadTexture2D.Width, uploadTexture2D.Height);
uploadTexture2D.CopyTo(readOnlyTexture2D);
@@ -79,21 +82,22 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
[DataRow(0, 0, 2048, 2048)]
[DataRow(128, 0, 1813, 2048)]
[DataRow(0, 128, 2000, 944)]
[DataRow(97, 33, 512, 794)]
public void Allocate_UploadTexture2D_Copy_Range(int x, int y, int width, int height)
[CombinatorialTestMethod]
[AllDevices]
[Data(0, 0, 2048, 2048)]
[Data(128, 0, 1813, 2048)]
[Data(0, 128, 2000, 944)]
[Data(97, 33, 512, 794)]
public void Allocate_UploadTexture2D_Copy_Range(Device device, int x, int y, int width, int height)
{
using UploadTexture2D<int> uploadTexture2D = Gpu.Default.AllocateUploadTexture2D<int>(2048, 2048);
using UploadTexture2D<int> uploadTexture2D = device.Get().AllocateUploadTexture2D<int>(2048, 2048);
for (int i = 0; i < uploadTexture2D.Height; i++)
{
new Random(i).NextBytes(uploadTexture2D.View.GetRowSpan(i).AsBytes());
}
using ReadOnlyTexture2D<int> readOnlyTexture2D = Gpu.Default.AllocateReadOnlyTexture2D<int>(uploadTexture2D.Width, uploadTexture2D.Height);
using ReadOnlyTexture2D<int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D<int>(uploadTexture2D.Width, uploadTexture2D.Height);
uploadTexture2D.CopyTo(readOnlyTexture2D, x, y, width, height);
@@ -108,8 +112,9 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
public void Allocate_ReadBackTexture2D_Copy_Full()
[CombinatorialTestMethod]
[AllDevices]
public void Allocate_ReadBackTexture2D_Copy_Full(Device device)
{
int[,] source = new int[256, 256];
@@ -118,8 +123,8 @@ namespace ComputeSharp.Tests
new Random(42).NextBytes(source.GetRowSpan(i).AsBytes());
}
using ReadOnlyTexture2D<int> readOnlyTexture2D = Gpu.Default.AllocateReadOnlyTexture2D(source);
using ReadBackTexture2D<int> readBackTexture2D = Gpu.Default.AllocateReadBackTexture2D<int>(256, 256);
using ReadOnlyTexture2D<int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D(source);
using ReadBackTexture2D<int> readBackTexture2D = device.Get().AllocateReadBackTexture2D<int>(256, 256);
readOnlyTexture2D.CopyTo(readBackTexture2D);
@@ -132,12 +137,13 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
[DataRow(0, 0, 2048, 2048)]
[DataRow(128, 0, 1813, 2048)]
[DataRow(0, 128, 2000, 944)]
[DataRow(97, 33, 512, 794)]
public void Allocate_ReadBackTexture2D_Copy_Range(int x, int y, int width, int height)
[CombinatorialTestMethod]
[AllDevices]
[Data(0, 0, 2048, 2048)]
[Data(128, 0, 1813, 2048)]
[Data(0, 128, 2000, 944)]
[Data(97, 33, 512, 794)]
public void Allocate_ReadBackTexture2D_Copy_Range(Device device, int x, int y, int width, int height)
{
int[,] source = new int[2048, 2048];
@@ -146,8 +152,8 @@ namespace ComputeSharp.Tests
new Random(42).NextBytes(source.GetRowSpan(i).AsBytes());
}
using ReadOnlyTexture2D<int> readOnlyTexture2D = Gpu.Default.AllocateReadOnlyTexture2D(source);
using ReadBackTexture2D<int> readBackTexture2D = Gpu.Default.AllocateReadBackTexture2D<int>(2048, 2048);
using ReadOnlyTexture2D<int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D(source);
using ReadBackTexture2D<int> readBackTexture2D = device.Get().AllocateReadBackTexture2D<int>(2048, 2048);
readOnlyTexture2D.CopyTo(readBackTexture2D, x, y, width, height);
+56 -52
ファイルの表示
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using ComputeSharp.Resources;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.Toolkit.HighPerformance.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -11,12 +12,13 @@ namespace ComputeSharp.Tests
[TestCategory("TransferTexture3D")]
public partial class TransferTexture3DTests
{
[TestMethod]
[DataRow(typeof(UploadTexture3D<>))]
[DataRow(typeof(ReadBackTexture3D<>))]
public unsafe void Allocate_Uninitialized_Ok(Type bufferType)
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(UploadTexture3D<>))]
[Resource(typeof(ReadBackTexture3D<>))]
public unsafe void Allocate_Uninitialized_Ok(Device device, Type bufferType)
{
using TransferTexture3D<float> buffer = Gpu.Default.AllocateTransferTexture3D<float>(bufferType, 128, 256, 32);
using TransferTexture3D<float> buffer = device.Get().AllocateTransferTexture3D<float>(bufferType, 128, 256, 32);
Assert.IsNotNull(buffer);
Assert.AreEqual(buffer.Width, 128);
@@ -25,45 +27,44 @@ namespace ComputeSharp.Tests
Assert.AreEqual(buffer.View.Width, 128);
Assert.AreEqual(buffer.View.Height, 256);
Assert.AreEqual(buffer.View.Depth, 32);
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
Assert.AreSame(buffer.GraphicsDevice, device.Get());
}
[TestMethod]
[DataRow(typeof(UploadTexture3D<>), 128, -14253, 4)]
[DataRow(typeof(UploadTexture3D<>), 128, -1, 4)]
[DataRow(typeof(UploadTexture3D<>), 0, -4314, 4)]
[DataRow(typeof(UploadTexture3D<>), -14, -53, 4)]
[DataRow(typeof(UploadTexture3D<>), 12, 12, -1)]
[DataRow(typeof(UploadTexture3D<>), 2, 4, ushort.MaxValue + 1)]
[DataRow(typeof(ReadBackTexture3D<>), 128, -14253, 4)]
[DataRow(typeof(ReadBackTexture3D<>), 128, -1, 4)]
[DataRow(typeof(ReadBackTexture3D<>), 0, -4314, 4)]
[DataRow(typeof(ReadBackTexture3D<>), -14, -53, 4)]
[DataRow(typeof(ReadBackTexture3D<>), 12, 12, -1)]
[DataRow(typeof(ReadBackTexture3D<>), 2, 4, ushort.MaxValue + 1)]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(UploadTexture3D<>))]
[Resource(typeof(ReadBackTexture3D<>))]
[Data(128, -14253, 4)]
[Data(128, -1, 4)]
[Data(0, -4314, 4)]
[Data(-14, -53, 4)]
[Data(12, 12, -1)]
[Data(2, 4, ushort.MaxValue + 1)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Allocate_Uninitialized_Fail(Type bufferType, int width, int height, int depth)
public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int width, int height, int depth)
{
using TransferTexture3D<float> buffer = Gpu.Default.AllocateTransferTexture3D<float>(bufferType, width, height, depth);
using TransferTexture3D<float> buffer = device.Get().AllocateTransferTexture3D<float>(bufferType, width, height, depth);
}
[TestMethod]
[DataRow(typeof(UploadTexture3D<>))]
[DataRow(typeof(ReadBackTexture3D<>))]
[CombinatorialTestMethod]
[AllDevices]
[Resource(typeof(UploadTexture3D<>))]
[Resource(typeof(ReadBackTexture3D<>))]
[ExpectedException(typeof(ObjectDisposedException))]
public void UsageAfterDispose(Type bufferType)
public void UsageAfterDispose(Device device, Type bufferType)
{
using TransferTexture3D<float> buffer = Gpu.Default.AllocateTransferTexture3D<float>(bufferType, 32, 32, 16);
using TransferTexture3D<float> buffer = device.Get().AllocateTransferTexture3D<float>(bufferType, 32, 32, 16);
buffer.Dispose();
_ = buffer.View;
}
[TestMethod]
public void Allocate_UploadTexture3D_Copy_Full()
[CombinatorialTestMethod]
[AllDevices]
public void Allocate_UploadTexture3D_Copy_Full(Device device)
{
using UploadTexture3D<int> uploadTexture3D = Gpu.Default.AllocateUploadTexture3D<int>(256, 256, 16);
using UploadTexture3D<int> uploadTexture3D = device.Get().AllocateUploadTexture3D<int>(256, 256, 16);
for (int i = 0; i < uploadTexture3D.Depth; i++)
{
@@ -73,7 +74,7 @@ namespace ComputeSharp.Tests
}
}
using ReadOnlyTexture3D<int> readOnlyTexture3D = Gpu.Default.AllocateReadOnlyTexture3D<int>(uploadTexture3D.Width, uploadTexture3D.Height, uploadTexture3D.Depth);
using ReadOnlyTexture3D<int> readOnlyTexture3D = device.Get().AllocateReadOnlyTexture3D<int>(uploadTexture3D.Width, uploadTexture3D.Height, uploadTexture3D.Depth);
uploadTexture3D.CopyTo(readOnlyTexture3D);
@@ -95,15 +96,16 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
[DataRow(0, 0, 0, 256, 256, 16)]
[DataRow(128, 0, 0, 72, 256, 16)]
[DataRow(0, 128, 0, 189, 67, 8)]
[DataRow(0, 0, 15, 32, 64, 1)]
[DataRow(97, 33, 4, 128, 99, 7)]
public void Allocate_UploadTexture3D_Copy_Range(int x, int y, int z, int width, int height, int depth)
[CombinatorialTestMethod]
[AllDevices]
[Data(0, 0, 0, 256, 256, 16)]
[Data(128, 0, 0, 72, 256, 16)]
[Data(0, 128, 0, 189, 67, 8)]
[Data(0, 0, 15, 32, 64, 1)]
[Data(97, 33, 4, 128, 99, 7)]
public void Allocate_UploadTexture3D_Copy_Range(Device device, int x, int y, int z, int width, int height, int depth)
{
using UploadTexture3D<int> uploadTexture3D = Gpu.Default.AllocateUploadTexture3D<int>(256, 256, 16);
using UploadTexture3D<int> uploadTexture3D = device.Get().AllocateUploadTexture3D<int>(256, 256, 16);
for (int i = 0; i < uploadTexture3D.Depth; i++)
{
@@ -113,7 +115,7 @@ namespace ComputeSharp.Tests
}
}
using ReadOnlyTexture3D<int> readOnlyTexture3D = Gpu.Default.AllocateReadOnlyTexture3D<int>(uploadTexture3D.Width, uploadTexture3D.Height, uploadTexture3D.Depth);
using ReadOnlyTexture3D<int> readOnlyTexture3D = device.Get().AllocateReadOnlyTexture3D<int>(uploadTexture3D.Width, uploadTexture3D.Height, uploadTexture3D.Depth);
uploadTexture3D.CopyTo(readOnlyTexture3D, x, y, z, width, height, depth);
@@ -131,8 +133,9 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
public void Allocate_ReadBackTexture3D_Copy_Full()
[CombinatorialTestMethod]
[AllDevices]
public void Allocate_ReadBackTexture3D_Copy_Full(Device device)
{
int[,,] source = new int[16, 256, 256];
@@ -144,8 +147,8 @@ namespace ComputeSharp.Tests
}
}
using ReadOnlyTexture3D<int> readOnlyTexture3D = Gpu.Default.AllocateReadOnlyTexture3D(source);
using ReadBackTexture3D<int> readBackTexture3D = Gpu.Default.AllocateReadBackTexture3D<int>(256, 256, 16);
using ReadOnlyTexture3D<int> readOnlyTexture3D = device.Get().AllocateReadOnlyTexture3D(source);
using ReadBackTexture3D<int> readBackTexture3D = device.Get().AllocateReadBackTexture3D<int>(256, 256, 16);
readOnlyTexture3D.CopyTo(readBackTexture3D);
@@ -165,13 +168,14 @@ namespace ComputeSharp.Tests
}
}
[TestMethod]
[DataRow(0, 0, 0, 256, 256, 16)]
[DataRow(128, 0, 0, 72, 256, 16)]
[DataRow(0, 128, 0, 189, 67, 8)]
[DataRow(0, 0, 15, 32, 64, 1)]
[DataRow(97, 33, 4, 128, 99, 7)]
public void Allocate_ReadBackTexture3D_Copy_Range(int x, int y, int z, int width, int height, int depth)
[CombinatorialTestMethod]
[AllDevices]
[Data(0, 0, 0, 256, 256, 16)]
[Data(128, 0, 0, 72, 256, 16)]
[Data(0, 128, 0, 189, 67, 8)]
[Data(0, 0, 15, 32, 64, 1)]
[Data(97, 33, 4, 128, 99, 7)]
public void Allocate_ReadBackTexture3D_Copy_Range(Device device, int x, int y, int z, int width, int height, int depth)
{
int[,,] source = new int[16, 256, 256];
@@ -183,8 +187,8 @@ namespace ComputeSharp.Tests
}
}
using ReadOnlyTexture3D<int> readOnlyTexture3D = Gpu.Default.AllocateReadOnlyTexture3D(source);
using ReadBackTexture3D<int> readBackTexture3D = Gpu.Default.AllocateReadBackTexture3D<int>(256, 256, 16);
using ReadOnlyTexture3D<int> readOnlyTexture3D = device.Get().AllocateReadOnlyTexture3D(source);
using ReadBackTexture3D<int> readBackTexture3D = device.Get().AllocateReadBackTexture3D<int>(256, 256, 16);
readOnlyTexture3D.CopyTo(readBackTexture3D, x, y, z, width, height, depth);