Updated sample and tests to use new texture loading APIs
このコミットが含まれているのは:
1 親
41d4ae683f
コミット
d1a2c667dd
6ファイル変更
+7
-40
検索条件に一致するファイルはありません
@@ -5,10 +5,6 @@
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj"
|
||||
|
||||
@@ -3,11 +3,8 @@ using System.Diagnostics.Contracts;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.SwapChain.Backend;
|
||||
using ComputeSharp.SwapChain.Shaders;
|
||||
using SixLabors.ImageSharp;
|
||||
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
|
||||
|
||||
namespace ComputeSharp.SwapChain
|
||||
{
|
||||
@@ -71,15 +68,7 @@ namespace ComputeSharp.SwapChain
|
||||
{
|
||||
string filename = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Textures", $"{name}.png");
|
||||
|
||||
using Image<ImageSharpRgba32> image = Image.Load<ImageSharpRgba32>(filename);
|
||||
|
||||
ReadOnlyTexture2D<Rgba32, Float4> texture = Gpu.Default.AllocateReadOnlyTexture2D<Rgba32, Float4>(image.Width, image.Height);
|
||||
|
||||
image.TryGetSinglePixelSpan(out Span<ImageSharpRgba32> span);
|
||||
|
||||
texture.CopyFrom(MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(span));
|
||||
|
||||
return texture;
|
||||
return Gpu.Default.AllocateReadOnlyTexture2D<Rgba32, Float4>(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NuGetizer" Version="0.6.2" PrivateAssets="all" />
|
||||
<PackageReference Include="NuGetizer" Version="0.7.0" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Directory.Build.props" />
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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]
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする