Use explicit types everywhere
このコミットが含まれているのは:
1 親
27c629f3b4
コミット
16c0fc9aab
74ファイル変更
+455
-446
検索条件に一致するファイルはありません
@@ -78,9 +78,9 @@ public sealed partial class BokehBlurEffect
|
||||
this.componentsCount = componentsCount;
|
||||
|
||||
// Reuse the initialized values from the cache, if possible
|
||||
var parameters = (this.radius, this.componentsCount);
|
||||
(int radius, int componentsCount) parameters = (this.radius, this.componentsCount);
|
||||
|
||||
if (Cache.TryGetValue(parameters, out var info))
|
||||
if (Cache.TryGetValue(parameters, out (Vector4[] Parameters, float Scale, (float[] Real, float[] Imaginary)[] Kernels) info))
|
||||
{
|
||||
this.kernelParameters = info.Parameters;
|
||||
this.kernelsScale = info.Scale;
|
||||
@@ -91,7 +91,7 @@ public sealed partial class BokehBlurEffect
|
||||
// Initialize the complex kernels and parameters with the current arguments
|
||||
(this.kernelParameters, this.kernelsScale) = GetParameters();
|
||||
|
||||
var kernels = CreateComplexKernels();
|
||||
Complex64[][] kernels = CreateComplexKernels();
|
||||
|
||||
NormalizeKernels(kernels, this.kernelParameters);
|
||||
|
||||
@@ -177,7 +177,7 @@ public sealed partial class BokehBlurEffect
|
||||
/// </summary>
|
||||
private Complex64[][] CreateComplexKernels()
|
||||
{
|
||||
var kernels = new Complex64[kernelParameters.Length][];
|
||||
Complex64[][] kernels = new Complex64[kernelParameters.Length][];
|
||||
ref Vector4 baseRef = ref MemoryMarshal.GetReference(kernelParameters.AsSpan());
|
||||
|
||||
for (int i = 0; i < kernelParameters.Length; i++)
|
||||
@@ -197,7 +197,7 @@ public sealed partial class BokehBlurEffect
|
||||
/// <param name="b">The angle component for each complex component.</param>
|
||||
private Complex64[] CreateComplex1DKernel(float a, float b)
|
||||
{
|
||||
var kernel = new Complex64[kernelSize];
|
||||
Complex64[] kernel = new Complex64[kernelSize];
|
||||
ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel.AsSpan());
|
||||
int r = radius;
|
||||
int n = -r;
|
||||
@@ -274,13 +274,13 @@ public sealed partial class BokehBlurEffect
|
||||
/// <param name="kernels">The input kernels to convert.</param>
|
||||
private static (float[] Real, float[] Imaginary)[] ConvertKernelsToStructureOfArrays(Complex64[][] kernels)
|
||||
{
|
||||
var structureOfArrayKernels = new (float[] Real, float[] Imaginary)[kernels.Length];
|
||||
(float[] Real, float[] Imaginary)[] structureOfArrayKernels = new (float[] Real, float[] Imaginary)[kernels.Length];
|
||||
|
||||
for (int i = 0; i < kernels.Length; i++)
|
||||
{
|
||||
Complex64[] kernel = kernels[i];
|
||||
var real = new float[kernel.Length];
|
||||
var imaginary = new float[kernel.Length];
|
||||
float[] real = new float[kernel.Length];
|
||||
float[] imaginary = new float[kernel.Length];
|
||||
|
||||
for (int j = 0; j < kernel.Length; j++)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ float[] array = Enumerable.Range(1, 100).Select(static i => (float)i).ToArray();
|
||||
using ReadWriteBuffer<float> gpuBuffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer(array);
|
||||
|
||||
// Run the shader
|
||||
using (var context = GraphicsDevice.GetDefault().CreateComputeContext())
|
||||
using (ComputeContext context = GraphicsDevice.GetDefault().CreateComputeContext())
|
||||
{
|
||||
context.Log("Dispatching shader");
|
||||
context.BeginEvent("Dispatching event");
|
||||
|
||||
@@ -62,15 +62,15 @@ public partial class DeviceDisposalTests
|
||||
|
||||
using (GraphicsDevice graphicsDevice = device.Get())
|
||||
{
|
||||
using var r1 = graphicsDevice.AllocateConstantBuffer<float>(128);
|
||||
using var r2 = graphicsDevice.AllocateReadOnlyBuffer<float>(128);
|
||||
using var r3 = graphicsDevice.AllocateReadWriteBuffer<float>(128);
|
||||
using var r4 = graphicsDevice.AllocateReadOnlyTexture2D<float>(128, 128);
|
||||
using var r5 = graphicsDevice.AllocateReadWriteTexture2D<float>(128, 128);
|
||||
using var r6 = graphicsDevice.AllocateUploadBuffer<float>(128);
|
||||
using var r7 = graphicsDevice.AllocateReadBackBuffer<float>(128);
|
||||
using var r8 = graphicsDevice.AllocateUploadTexture2D<float>(128, 128);
|
||||
using var r9 = graphicsDevice.AllocateReadBackTexture2D<float>(128, 128);
|
||||
using ConstantBuffer<float> r1 = graphicsDevice.AllocateConstantBuffer<float>(128);
|
||||
using ReadOnlyBuffer<float> r2 = graphicsDevice.AllocateReadOnlyBuffer<float>(128);
|
||||
using ReadWriteBuffer<float> r3 = graphicsDevice.AllocateReadWriteBuffer<float>(128);
|
||||
using ReadOnlyTexture2D<float> r4 = graphicsDevice.AllocateReadOnlyTexture2D<float>(128, 128);
|
||||
using ReadWriteTexture2D<float> r5 = graphicsDevice.AllocateReadWriteTexture2D<float>(128, 128);
|
||||
using UploadBuffer<float> r6 = graphicsDevice.AllocateUploadBuffer<float>(128);
|
||||
using ReadBackBuffer<float> r7 = graphicsDevice.AllocateReadBackBuffer<float>(128);
|
||||
using UploadTexture2D<float> r8 = graphicsDevice.AllocateUploadTexture2D<float>(128, 128);
|
||||
using ReadBackTexture2D<float> r9 = graphicsDevice.AllocateReadBackTexture2D<float>(128, 128);
|
||||
|
||||
GraphicsDeviceHelper.GetD3D12Device(graphicsDevice, in d3D12Device);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public partial class DeviceDisposalTests
|
||||
|
||||
using (GraphicsDevice graphicsDevice = device.Get())
|
||||
{
|
||||
using var buffer = graphicsDevice.AllocateReadWriteBuffer<float>(128);
|
||||
using ReadWriteBuffer<float> buffer = graphicsDevice.AllocateReadWriteBuffer<float>(128);
|
||||
|
||||
using (ComputeContext context = graphicsDevice.CreateComputeContext())
|
||||
{
|
||||
@@ -151,7 +151,7 @@ public partial class DeviceDisposalTests
|
||||
|
||||
using (GraphicsDevice graphicsDevice = device.Get())
|
||||
{
|
||||
using var texture = graphicsDevice.AllocateReadWriteTexture2D<Rgba32, float4>(128, 128);
|
||||
using ReadWriteTexture2D<Rgba32, float4> texture = graphicsDevice.AllocateReadWriteTexture2D<Rgba32, float4>(128, 128);
|
||||
|
||||
using (ComputeContext context = graphicsDevice.CreateComputeContext())
|
||||
{
|
||||
|
||||
@@ -53,7 +53,7 @@ public class DeviceLostTests
|
||||
|
||||
await GraphicsDeviceHelper.RemoveDeviceAsync(graphicsDevice);
|
||||
|
||||
using var _ = graphicsDevice.AllocateBuffer<float>(bufferType, 128);
|
||||
using Resources.Buffer<float> _ = graphicsDevice.AllocateBuffer<float>(bufferType, 128);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
@@ -67,7 +67,7 @@ public class DeviceLostTests
|
||||
|
||||
await GraphicsDeviceHelper.RemoveDeviceAsync(graphicsDevice);
|
||||
|
||||
using var _ = graphicsDevice.AllocateTexture2D<float>(textureType, 128, 128);
|
||||
using Resources.Texture2D<float> _ = graphicsDevice.AllocateTexture2D<float>(textureType, 128, 128);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
@@ -81,7 +81,7 @@ public class DeviceLostTests
|
||||
|
||||
await GraphicsDeviceHelper.RemoveDeviceAsync(graphicsDevice);
|
||||
|
||||
using var _ = graphicsDevice.AllocateTexture3D<float>(textureType, 128, 128, 3);
|
||||
using Resources.Texture3D<float> _ = graphicsDevice.AllocateTexture3D<float>(textureType, 128, 128, 3);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
@@ -153,6 +153,6 @@ public class DeviceLostTests
|
||||
|
||||
await GraphicsDeviceHelper.RemoveDeviceAsync(graphicsDevice);
|
||||
|
||||
using var _ = graphicsDevice.CreateComputeContext();
|
||||
using ComputeContext _ = graphicsDevice.CreateComputeContext();
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class NativeObjectTests
|
||||
|
||||
Assert.IsTrue(obj.IsDisposed);
|
||||
|
||||
using var lease0 = obj.TryGetReferenceTrackingLease(out bool leaseTaken);
|
||||
using NativeObject.Lease lease0 = obj.TryGetReferenceTrackingLease(out bool leaseTaken);
|
||||
|
||||
Assert.IsFalse(leaseTaken);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class NativeObjectTests
|
||||
{
|
||||
DisposableObject obj = new();
|
||||
|
||||
var lease0 = obj.GetReferenceTrackingLease();
|
||||
NativeObject.Lease lease0 = obj.GetReferenceTrackingLease();
|
||||
|
||||
obj.Dispose();
|
||||
|
||||
@@ -49,7 +49,7 @@ public class NativeObjectTests
|
||||
{
|
||||
DisposableObject obj = new();
|
||||
|
||||
var lease0 = obj.TryGetReferenceTrackingLease(out bool leaseTaken);
|
||||
NativeObject.Lease lease0 = obj.TryGetReferenceTrackingLease(out bool leaseTaken);
|
||||
|
||||
Assert.IsTrue(leaseTaken);
|
||||
|
||||
@@ -89,7 +89,7 @@ public class NativeObjectTests
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
using var lease = obj.GetReferenceTrackingLease();
|
||||
using NativeObject.Lease lease = obj.GetReferenceTrackingLease();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -118,7 +118,7 @@ public class NativeObjectTests
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
using var lease = obj.TryGetReferenceTrackingLease(out bool leaseTaken);
|
||||
using NativeObject.Lease lease = obj.TryGetReferenceTrackingLease(out bool leaseTaken);
|
||||
|
||||
if (isDisposed)
|
||||
{
|
||||
@@ -135,7 +135,7 @@ public class NativeObjectTests
|
||||
{
|
||||
DisposableObject obj = new();
|
||||
|
||||
var outstandingLease = obj.GetReferenceTrackingLease();
|
||||
NativeObject.Lease outstandingLease = obj.GetReferenceTrackingLease();
|
||||
|
||||
_ = Parallel.For(0, 2048, i =>
|
||||
{
|
||||
@@ -150,7 +150,7 @@ public class NativeObjectTests
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
using var lease = obj.TryGetReferenceTrackingLease(out bool leaseTaken);
|
||||
using NativeObject.Lease lease = obj.TryGetReferenceTrackingLease(out bool leaseTaken);
|
||||
|
||||
if (isDisposed)
|
||||
{
|
||||
|
||||
@@ -896,13 +896,13 @@ public partial class ComputeContextTests
|
||||
string imagingPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
|
||||
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
using Image<ImageSharpRgba32> sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
|
||||
using ReadOnlyTexture2D<Rgba32, float4> source = device.Get().LoadReadOnlyTexture2D<Rgba32, float4>(Path.Combine(imagingPath, "city.jpg"));
|
||||
using ReadWriteTexture2D<float4> sourceAsFloat4 = device.Get().AllocateReadWriteTexture2D<float4>(source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Rgba32, float4> destination = device.Get().AllocateReadWriteTexture2D<Rgba32, float4>(sampled.Width, sampled.Height);
|
||||
|
||||
using (var context = device.Get().CreateComputeContext())
|
||||
using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
context.For(source.Width, source.Height, new ConvertToNonNormalized2DShader(source, sourceAsFloat4));
|
||||
context.Transition(sourceAsFloat4, ResourceState.ReadOnly);
|
||||
@@ -910,7 +910,7 @@ public partial class ComputeContextTests
|
||||
context.Transition(sourceAsFloat4, ResourceState.ReadWrite);
|
||||
}
|
||||
|
||||
using var processed = destination.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
using Image<ImageSharpRgba32> processed = destination.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
|
||||
TolerantImageComparer.AssertEqual(sampled, processed, 0.00000174f);
|
||||
}
|
||||
@@ -924,19 +924,19 @@ public partial class ComputeContextTests
|
||||
string imagingPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
|
||||
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
using Image<ImageSharpRgba32> sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, float4> source = device.Get().LoadReadWriteTexture2D<Rgba32, float4>(Path.Combine(imagingPath, "city.jpg"));
|
||||
using ReadWriteTexture2D<Rgba32, float4> destination = device.Get().AllocateReadWriteTexture2D<Rgba32, float4>(sampled.Width, sampled.Height);
|
||||
|
||||
using (var context = device.Get().CreateComputeContext())
|
||||
using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
context.Transition(source, ResourceState.ReadOnly);
|
||||
context.ForEach(destination, new LinearSamplingFromNormalized2DPixelShader(source.AsReadOnly()));
|
||||
context.Transition(source, ResourceState.ReadWrite);
|
||||
}
|
||||
|
||||
using var processed = destination.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
using Image<ImageSharpRgba32> processed = destination.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
|
||||
TolerantImageComparer.AssertEqual(sampled, processed, 0.0000017f);
|
||||
}
|
||||
@@ -950,15 +950,15 @@ public partial class ComputeContextTests
|
||||
string imagingPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
|
||||
using var sampled1 = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
using var sampled2 = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024SamplingInverted.png"));
|
||||
using Image<ImageSharpRgba32> sampled1 = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
using Image<ImageSharpRgba32> sampled2 = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024SamplingInverted.png"));
|
||||
|
||||
using ReadOnlyTexture2D<Rgba32, float4> image = device.Get().LoadReadOnlyTexture2D<Rgba32, float4>(Path.Combine(imagingPath, "city.jpg"));
|
||||
using ReadWriteTexture2D<Rgba32, float4> source = device.Get().AllocateReadWriteTexture2D<Rgba32, float4>(image.Width, image.Height);
|
||||
using ReadWriteTexture2D<Rgba32, float4> destination1 = device.Get().AllocateReadWriteTexture2D<Rgba32, float4>(sampled1.Width, sampled1.Height);
|
||||
using ReadWriteTexture2D<Rgba32, float4> destination2 = device.Get().AllocateReadWriteTexture2D<Rgba32, float4>(sampled1.Width, sampled1.Height);
|
||||
|
||||
using (var context = device.Get().CreateComputeContext())
|
||||
using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
// Dispatch before any transitions, and UAV barrier test
|
||||
context.ForEach<ClearPixelShader, float4>(source);
|
||||
@@ -980,8 +980,8 @@ public partial class ComputeContextTests
|
||||
context.ForEach(destination2, new LinearSamplingFromNormalized2DPixelShader(source.AsReadOnly()));
|
||||
}
|
||||
|
||||
using var processed1 = destination1.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
using var processed2 = destination2.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
using Image<ImageSharpRgba32> processed1 = destination1.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
using Image<ImageSharpRgba32> processed2 = destination2.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
|
||||
TolerantImageComparer.AssertEqual(sampled1, processed1, 0.0000017f);
|
||||
TolerantImageComparer.AssertEqual(sampled2, processed2, 0.0000028f);
|
||||
@@ -997,9 +997,9 @@ public partial class ComputeContextTests
|
||||
string originalPath = Path.Combine(assetsPath, "CityWith1920x1280Resizing.png");
|
||||
string sampledPath = Path.Combine(assetsPath, "CityAfter1024x1024SamplingFrom1920x1080.png");
|
||||
|
||||
var imageInfo = Image.Identify(originalPath);
|
||||
IImageInfo imageInfo = Image.Identify(originalPath);
|
||||
|
||||
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, sampledPath));
|
||||
using Image<ImageSharpRgba32> sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, sampledPath));
|
||||
|
||||
using ReadWriteTexture3D<float4> sourceAsFloat4 = device.Get().AllocateReadWriteTexture3D<float4>(imageInfo.Width, imageInfo.Height, 3);
|
||||
|
||||
@@ -1024,7 +1024,7 @@ public partial class ComputeContextTests
|
||||
|
||||
using ReadWriteTexture3D<Rgba32, float4> destination = device.Get().AllocateReadWriteTexture3D<Rgba32, float4>(sampled.Width, sampled.Height, 2);
|
||||
|
||||
using (var context = device.Get().CreateComputeContext())
|
||||
using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
context.Transition(sourceAsFloat4, ResourceState.ReadOnly);
|
||||
context.For(destination.Width, destination.Height, destination.Depth, new LinearSampling3DComputeShader(sourceAsFloat4.AsReadOnly(), destination));
|
||||
@@ -1033,7 +1033,7 @@ public partial class ComputeContextTests
|
||||
|
||||
for (int z = 0; z < destination.Depth; z++)
|
||||
{
|
||||
using var processed = destination.ToImage<Rgba32, ImageSharpRgba32>(depth: z);
|
||||
using Image<ImageSharpRgba32> processed = destination.ToImage<Rgba32, ImageSharpRgba32>(depth: z);
|
||||
|
||||
TolerantImageComparer.AssertEqual(sampled, processed, 0.000012f);
|
||||
}
|
||||
@@ -1049,9 +1049,9 @@ public partial class ComputeContextTests
|
||||
string originalPath = Path.Combine(assetsPath, "CityWith1920x1280Resizing.png");
|
||||
string sampledPath = Path.Combine(assetsPath, "CityAfter1024x1024SamplingFrom1920x1080.png");
|
||||
|
||||
var imageInfo = Image.Identify(originalPath);
|
||||
IImageInfo imageInfo = Image.Identify(originalPath);
|
||||
|
||||
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, sampledPath));
|
||||
using Image<ImageSharpRgba32> sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, sampledPath));
|
||||
|
||||
using ReadWriteTexture3D<Rgba32, float4> source = device.Get().AllocateReadWriteTexture3D<Rgba32, float4>(imageInfo.Width, imageInfo.Height, 3);
|
||||
|
||||
@@ -1068,7 +1068,7 @@ public partial class ComputeContextTests
|
||||
|
||||
using ReadWriteTexture3D<Rgba32, float4> destination = device.Get().AllocateReadWriteTexture3D<Rgba32, float4>(sampled.Width, sampled.Height, 2);
|
||||
|
||||
using (var context = device.Get().CreateComputeContext())
|
||||
using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
context.Transition(source, ResourceState.ReadOnly);
|
||||
context.For(destination.Width, destination.Height, destination.Depth, new LinearSamplingFromNormalized3DComputeShader(source.AsReadOnly(), destination));
|
||||
@@ -1077,7 +1077,7 @@ public partial class ComputeContextTests
|
||||
|
||||
for (int z = 0; z < destination.Depth; z++)
|
||||
{
|
||||
using var processed = destination.ToImage<Rgba32, ImageSharpRgba32>(depth: z);
|
||||
using Image<ImageSharpRgba32> processed = destination.ToImage<Rgba32, ImageSharpRgba32>(depth: z);
|
||||
|
||||
TolerantImageComparer.AssertEqual(sampled, processed, 0.000012f);
|
||||
}
|
||||
@@ -1092,12 +1092,12 @@ public partial class ComputeContextTests
|
||||
string imagingPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
|
||||
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024SamplingAndDashing.png"));
|
||||
using Image<ImageSharpRgba32> sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024SamplingAndDashing.png"));
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, float4> source = device.Get().LoadReadWriteTexture2D<Rgba32, float4>(Path.Combine(imagingPath, "city.jpg"));
|
||||
using ReadWriteTexture2D<Rgba32, float4> destination = device.Get().AllocateReadWriteTexture2D<Rgba32, float4>(sampled.Width, sampled.Height);
|
||||
|
||||
using (var context = device.Get().CreateComputeContext())
|
||||
using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
context.For(source.Width, source.Height, new Dotted2DPixelShader(source));
|
||||
context.Transition(source, ResourceState.ReadOnly);
|
||||
@@ -1106,7 +1106,7 @@ public partial class ComputeContextTests
|
||||
context.Fill(source, new Rgba32(0xFF, 0x6A, 0x00, 0x00));
|
||||
}
|
||||
|
||||
using var processed = destination.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
using Image<ImageSharpRgba32> processed = destination.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
|
||||
TolerantImageComparer.AssertEqual(sampled, processed, 0.0000017f);
|
||||
|
||||
@@ -1128,9 +1128,9 @@ public partial class ComputeContextTests
|
||||
string originalPath = Path.Combine(assetsPath, "CityWith1920x1280Resizing.png");
|
||||
string sampledPath = Path.Combine(assetsPath, "CityAfter1024x1024SamplingFrom1920x1080AndDashing.png");
|
||||
|
||||
var imageInfo = Image.Identify(originalPath);
|
||||
IImageInfo imageInfo = Image.Identify(originalPath);
|
||||
|
||||
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, sampledPath));
|
||||
using Image<ImageSharpRgba32> sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, sampledPath));
|
||||
|
||||
using ReadWriteTexture3D<Rgba32, float4> source = device.Get().AllocateReadWriteTexture3D<Rgba32, float4>(imageInfo.Width, imageInfo.Height, 3);
|
||||
|
||||
@@ -1147,7 +1147,7 @@ public partial class ComputeContextTests
|
||||
|
||||
using ReadWriteTexture3D<Rgba32, float4> destination = device.Get().AllocateReadWriteTexture3D<Rgba32, float4>(sampled.Width, sampled.Height, 2);
|
||||
|
||||
using (var context = device.Get().CreateComputeContext())
|
||||
using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
context.For(source.Width, source.Height, source.Depth, new Dotted3DPixelShader(source));
|
||||
context.Transition(source, ResourceState.ReadOnly);
|
||||
@@ -1158,7 +1158,7 @@ public partial class ComputeContextTests
|
||||
|
||||
for (int z = 0; z < destination.Depth; z++)
|
||||
{
|
||||
using var processed = destination.ToImage<Rgba32, ImageSharpRgba32>(depth: z);
|
||||
using Image<ImageSharpRgba32> processed = destination.ToImage<Rgba32, ImageSharpRgba32>(depth: z);
|
||||
|
||||
TolerantImageComparer.AssertEqual(sampled, processed, 0.000012f);
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ internal static class TolerantImageComparer
|
||||
/// <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);
|
||||
using Image<ImageSharpRgba32> expected = Image.Load<ImageSharpRgba32>(expectedPath);
|
||||
using Image<ImageSharpRgba32> actual = Image.Load<ImageSharpRgba32>(actualPath);
|
||||
|
||||
AssertEqual(expected, actual, threshold);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ internal static class TolerantImageComparer
|
||||
|
||||
float totalDifference = 0F;
|
||||
|
||||
var differences = new List<PixelDifference>(20);
|
||||
List<PixelDifference> differences = new List<PixelDifference>(20);
|
||||
Span<ImageSharpRgba32> aBuffer = new ImageSharpRgba32[actual.Width];
|
||||
Span<ImageSharpRgba32> bBuffer = new ImageSharpRgba32[actual.Width];
|
||||
|
||||
@@ -84,7 +84,7 @@ internal static class TolerantImageComparer
|
||||
{
|
||||
if (differences.Count < 20)
|
||||
{
|
||||
var diff = new PixelDifference(new Point(x, y), aBuffer[x], bBuffer[x]);
|
||||
PixelDifference diff = new PixelDifference(new Point(x, y), aBuffer[x], bBuffer[x]);
|
||||
differences.Add(diff);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ internal static class TolerantImageComparer
|
||||
_ = builder.AppendLine($"The input images don't match. Normalized delta: {normalizedDifference}%");
|
||||
_ = builder.AppendLine($"First {differences.Count} pixel deltas:");
|
||||
|
||||
foreach (var delta in differences)
|
||||
foreach (PixelDifference delta in differences)
|
||||
{
|
||||
_ = builder.AppendLine(delta.ToString());
|
||||
}
|
||||
|
||||
@@ -25,12 +25,12 @@ public class ImageProcessingTests
|
||||
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
|
||||
using var original = Image.Load<ImageSharpRgba32>(Path.Combine(path, "city.jpg"));
|
||||
using Image<ImageSharpRgba32> original = Image.Load<ImageSharpRgba32>(Path.Combine(path, "city.jpg"));
|
||||
|
||||
original.Mutate(c => c.Resize(1920, 1080));
|
||||
|
||||
using var cpu = original.Clone(c => c.BokehBlur(40, 2, 3));
|
||||
using var gpu = original.Clone(c => c.ApplyProcessor(new HlslBokehBlurProcessor(device.Get(), 40, 2)));
|
||||
using Image<ImageSharpRgba32> cpu = original.Clone(c => c.BokehBlur(40, 2, 3));
|
||||
using Image<ImageSharpRgba32> gpu = original.Clone(c => c.ApplyProcessor(new HlslBokehBlurProcessor(device.Get(), 40, 2)));
|
||||
|
||||
string expectedPath = Path.Combine(path, "city_bokeh_cpu.jpg");
|
||||
string actualPath = Path.Combine(path, "city_bokeh_gpu.jpg");
|
||||
@@ -49,12 +49,12 @@ public class ImageProcessingTests
|
||||
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
|
||||
using var original = Image.Load<ImageSharpRgba32>(Path.Combine(path, "city.jpg"));
|
||||
using Image<ImageSharpRgba32> original = Image.Load<ImageSharpRgba32>(Path.Combine(path, "city.jpg"));
|
||||
|
||||
original.Mutate(c => c.Resize(1920, 1080));
|
||||
|
||||
using var cpu = original.Clone(c => c.GaussianBlur(30f));
|
||||
using var gpu = original.Clone(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(device.Get(), 90)));
|
||||
using Image<ImageSharpRgba32> cpu = original.Clone(c => c.GaussianBlur(30f));
|
||||
using Image<ImageSharpRgba32> gpu = original.Clone(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(device.Get(), 90)));
|
||||
|
||||
string expectedPath = Path.Combine(path, "city_gaussian_cpu.jpg");
|
||||
string actualPath = Path.Combine(path, "city_gaussian_gpu.jpg");
|
||||
|
||||
@@ -3,6 +3,8 @@ using ComputeSharp.Interop;
|
||||
using ComputeSharp.Tests.Misc;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
#pragma warning disable IDE0008
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
{
|
||||
[TestClass]
|
||||
|
||||
@@ -4,6 +4,8 @@ using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
#pragma warning disable IDE0008
|
||||
|
||||
namespace ComputeSharp.Tests;
|
||||
|
||||
[TestClass]
|
||||
|
||||
@@ -169,7 +169,7 @@ public class ShadersTests
|
||||
texture.GraphicsDevice.For(texture.Width, texture.Height, (T)Activator.CreateInstance(typeof(T), texture, 0f)!);
|
||||
}
|
||||
|
||||
var action = new Action<ReadWriteTexture2D<Rgba32, float4>>(RunComputeShader<SwapChain.Shaders.Compute.ColorfulInfinity>);
|
||||
Action<ReadWriteTexture2D<Rgba32, float4>> action = new Action<ReadWriteTexture2D<Rgba32, float4>>(RunComputeShader<SwapChain.Shaders.Compute.ColorfulInfinity>);
|
||||
|
||||
_ = action.Method.GetGenericMethodDefinition().MakeGenericMethod(shaderType).Invoke(null, new[] { texture });
|
||||
}
|
||||
@@ -181,7 +181,7 @@ public class ShadersTests
|
||||
texture.GraphicsDevice.ForEach(texture, (T)Activator.CreateInstance(typeof(T), 0f)!);
|
||||
}
|
||||
|
||||
var action = new Action<ReadWriteTexture2D<Rgba32, float4>>(RunPixelShader<ColorfulInfinity>);
|
||||
Action<ReadWriteTexture2D<Rgba32, float4>> action = new Action<ReadWriteTexture2D<Rgba32, float4>>(RunPixelShader<ColorfulInfinity>);
|
||||
|
||||
_ = action.Method.GetGenericMethodDefinition().MakeGenericMethod(shaderType).Invoke(null, new[] { texture });
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ partial class Texture1DTests
|
||||
string imagingPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
|
||||
using var original = Image.Load<ImageSharpRgba32>(Path.Combine(imagingPath, "city.jpg"));
|
||||
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
using Image<ImageSharpRgba32> original = Image.Load<ImageSharpRgba32>(Path.Combine(imagingPath, "city.jpg"));
|
||||
using Image<ImageSharpRgba32> sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
|
||||
if (!original.DangerousTryGetSinglePixelMemory(out Memory<ImageSharpRgba32> originalMemory))
|
||||
{
|
||||
@@ -82,8 +82,8 @@ partial class Texture1DTests
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
using var sampledRow = Image.WrapMemory(sampledMemory.Slice(0, sampled.Width), sampled.Width, 1);
|
||||
using var processedRow = Image.WrapMemory(processed.AsMemory().Cast<Rgba32, ImageSharpRgba32>(), sampled.Width, 1);
|
||||
using Image<ImageSharpRgba32> sampledRow = Image.WrapMemory(sampledMemory.Slice(0, sampled.Width), sampled.Width, 1);
|
||||
using Image<ImageSharpRgba32> processedRow = Image.WrapMemory(processed.AsMemory().Cast<Rgba32, ImageSharpRgba32>(), sampled.Width, 1);
|
||||
|
||||
TolerantImageComparer.AssertEqual(sampledRow, processedRow, 0.0000017f);
|
||||
}
|
||||
@@ -117,7 +117,7 @@ partial class Texture1DTests
|
||||
{
|
||||
using ReadWriteTexture1D<T, TPixel> texture = device.Get().AllocateReadWriteTexture1D<T, TPixel>(64);
|
||||
|
||||
using (var context = device.Get().CreateComputeContext())
|
||||
using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
context.Transition(texture, ResourceState.ReadOnly);
|
||||
|
||||
|
||||
@@ -59,14 +59,14 @@ partial class Texture2DTests
|
||||
string imagingPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
|
||||
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
using Image<ImageSharpRgba32> sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
|
||||
using ReadOnlyTexture2D<Rgba32, float4> source = device.Get().LoadReadOnlyTexture2D<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<Rgba32, ImageSharpRgba32>();
|
||||
using Image<ImageSharpRgba32> processed = destination.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
|
||||
TolerantImageComparer.AssertEqual(sampled, processed, 0.0000017f);
|
||||
}
|
||||
@@ -92,14 +92,14 @@ partial class Texture2DTests
|
||||
string imagingPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
|
||||
using var sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
using Image<ImageSharpRgba32> sampled = Image.Load<ImageSharpRgba32>(Path.Combine(assetsPath, "CityAfter1024x1024Sampling.png"));
|
||||
|
||||
using ReadOnlyTexture2D<Rgba32, float4> source = device.Get().LoadReadOnlyTexture2D<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<Rgba32, ImageSharpRgba32>();
|
||||
using Image<ImageSharpRgba32> processed = destination.ToImage<Rgba32, ImageSharpRgba32>();
|
||||
|
||||
TolerantImageComparer.AssertEqual(sampled, processed, 0.0000017f);
|
||||
}
|
||||
@@ -132,7 +132,7 @@ partial class Texture2DTests
|
||||
{
|
||||
using ReadWriteTexture2D<T, TPixel> texture = device.Get().AllocateReadWriteTexture2D<T, TPixel>(64, 64);
|
||||
|
||||
using (var context = device.Get().CreateComputeContext())
|
||||
using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
context.Transition(texture, ResourceState.ReadOnly);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ partial class Texture3DTests
|
||||
{
|
||||
using ReadWriteTexture3D<T, TPixel> texture = device.Get().AllocateReadWriteTexture3D<T, TPixel>(32, 32, 2);
|
||||
|
||||
using (var context = device.Get().CreateComputeContext())
|
||||
using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
context.Transition(texture, ResourceState.ReadOnly);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.HighPerformance;
|
||||
using CommunityToolkit.HighPerformance.Enumerables;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
@@ -183,7 +184,7 @@ public partial class Texture3DTests
|
||||
|
||||
fixed (int* p = array)
|
||||
{
|
||||
foreach (var item in new Span<int>(p, array.Length).Enumerate())
|
||||
foreach (SpanEnumerable<int>.Item item in new Span<int>(p, array.Length).Enumerate())
|
||||
{
|
||||
item.Value = item.Index;
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする