Updated sample and tests to use new texture loading APIs

このコミットが含まれているのは:
Sergio Pedri committed 2021-05-12 11:33:05 +02:00
1 親 41d4ae683f
コミット d1a2c667dd
6ファイル変更
+7 -40

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

-18
ファイルの表示
@@ -12,24 +12,6 @@ namespace ComputeSharp.Tests.Extensions
/// </summary>
public static class ImagingExtensions
{
/// <summary>
/// Allocates a new <see cref="ReadOnlyTexture2D{T, TPixel}"/> instance with the specified texture data.
/// </summary>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance to allocate the texture for.</param>
/// <param name="path">The path of the texture to load.</param>
/// <returns>A texture with the data from the image at the specified path.</returns>
[Pure]
public static ReadOnlyTexture2D<Rgba32, Float4> LoadTexture(this GraphicsDevice device, string path)
{
using Image<ImageSharpRgba32> image = Image.Load<ImageSharpRgba32>(path);
Assert.IsTrue(image.TryGetSinglePixelSpan(out Span<ImageSharpRgba32> span));
Span<Rgba32> pixels = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(span);
return device.AllocateReadOnlyTexture2D<Rgba32, Float4>(pixels, image.Width, image.Height);
}
/// <summary>
/// Creates a new <see cref="Image{TPixel}"/> instance with the specified texture data.
/// </summary>
+1 -1
ファイルの表示
@@ -105,7 +105,7 @@ namespace ComputeSharp.Tests
{
string filename = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Shaders", "Textures", "RustyMetal.png");
using ReadOnlyTexture2D<Rgba32, Float4> background = device.Get().LoadTexture(filename);
using ReadOnlyTexture2D<Rgba32, Float4> background = device.Get().AllocateReadOnlyTexture2D<Rgba32, Float4>(filename);
RunAndCompareShader(
device,
+4 -4
ファイルの表示
@@ -76,14 +76,14 @@ namespace ComputeSharp.Tests
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
using ReadOnlyTexture2D<Rgba32, Float4> source = device.Get().LoadTexture(Path.Combine(imagingPath, "city.jpg"));
using ReadOnlyTexture2D<Rgba32, Float4> source = device.Get().AllocateReadOnlyTexture2D<Rgba32, Float4>(Path.Combine(imagingPath, "city.jpg"));
using ReadWriteTexture2D<Rgba32, Float4> destination = device.Get().AllocateReadWriteTexture2D<Rgba32, Float4>(sampled.Width, sampled.Height);
device.Get().For(sampled.Width, sampled.Height, new SamplingComputeShader(source, destination));
using var processed = destination.ToImage();
ImagingTests.TolerantImageComparer.AssertEqual(sampled, processed, 0.00000086f);
ImagingTests.TolerantImageComparer.AssertEqual(sampled, processed, 0.0000017f);
}
[AutoConstructor]
@@ -109,14 +109,14 @@ namespace ComputeSharp.Tests
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
using ReadOnlyTexture2D<Rgba32, Float4> source = device.Get().LoadTexture(Path.Combine(imagingPath, "city.jpg"));
using ReadOnlyTexture2D<Rgba32, Float4> source = device.Get().AllocateReadOnlyTexture2D<Rgba32, Float4>(Path.Combine(imagingPath, "city.jpg"));
using ReadWriteTexture2D<Rgba32, Float4> destination = device.Get().AllocateReadWriteTexture2D<Rgba32, Float4>(sampled.Width, sampled.Height);
device.Get().ForEach(destination, new SamplingPixelShader(source));
using var processed = destination.ToImage();
ImagingTests.TolerantImageComparer.AssertEqual(sampled, processed, 0.00000086f);
ImagingTests.TolerantImageComparer.AssertEqual(sampled, processed, 0.0000017f);
}
[AutoConstructor]