diff --git a/src/ComputeSharp.Graphics/Extensions/ID3D12ResourceExtensions.cs b/src/ComputeSharp.Graphics/Extensions/ID3D12ResourceExtensions.cs
index c6afd4bd..3995f71e 100644
--- a/src/ComputeSharp.Graphics/Extensions/ID3D12ResourceExtensions.cs
+++ b/src/ComputeSharp.Graphics/Extensions/ID3D12ResourceExtensions.cs
@@ -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);
}
+
+ ///
+ /// Assigns a name to a given .
+ ///
+ /// The target to map.
+ /// The wrapper object to get the name from.
+ /// Thrown when the mapping operation fails.
+ [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();
+ }
+ }
}
}
diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs
index 46fbdc5a..fbb8ba9b 100644
--- a/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs
+++ b/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs
@@ -80,6 +80,8 @@ namespace ComputeSharp.Resources
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, D3D12CpuDescriptorHandle);
break;
}
+
+ this.d3D12Resource.Get()->SetName(this);
}
///
diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs
index bed6e970..9510905c 100644
--- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs
+++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs
@@ -111,6 +111,8 @@ namespace ComputeSharp.Resources
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType(), D3D12_UAV_DIMENSION_TEXTURE2D, D3D12CpuDescriptorHandle);
break;
}
+
+ this.d3D12Resource.Get()->SetName(this);
}
///
diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs
index 9e4e6d54..3b1c9253 100644
--- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs
+++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs
@@ -115,6 +115,8 @@ namespace ComputeSharp.Resources
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType(), D3D12_UAV_DIMENSION_TEXTURE3D, D3D12CpuDescriptorHandle);
break;
}
+
+ this.d3D12Resource.Get()->SetName(this);
}
///
diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/TransferBuffer{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/TransferBuffer{T}.cs
index 431c5806..d2a3a2fc 100644
--- a/src/ComputeSharp.Graphics/Resources/Abstract/TransferBuffer{T}.cs
+++ b/src/ComputeSharp.Graphics/Resources/Abstract/TransferBuffer{T}.cs
@@ -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);
}
///
diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture2D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture2D{T}.cs
index 57390ada..003a04c2 100644
--- a/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture2D{T}.cs
+++ b/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture2D{T}.cs
@@ -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);
}
///
diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture3D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture3D{T}.cs
index 16acda8a..3e92d0e5 100644
--- a/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture3D{T}.cs
+++ b/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture3D{T}.cs
@@ -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);
}
///
diff --git a/tests/ComputeSharp.Tests/Extensions/SpanExtensions.cs b/tests/ComputeSharp.Tests/Extensions/SpanExtensions.cs
deleted file mode 100644
index 59c2e235..00000000
--- a/tests/ComputeSharp.Tests/Extensions/SpanExtensions.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System;
-using System.Diagnostics.Contracts;
-using System.Runtime.CompilerServices;
-
-namespace ComputeSharp.Tests.Extensions
-{
- ///
- /// An helper with methods to process fixed-size buffers.
- ///
- public static class SpanExtensions
- {
- ///
- /// The maximum threshold to validate two values as being equal.
- ///
- private const float FloatThreshold = 0.00001f;
-
- ///
- /// Checks whether or not the two input instances have the same content.
- ///
- /// The first to check.
- /// The second to check.
- [Pure]
- public static bool ContentEquals(this Span a, Span 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;
- }
- }
-}
diff --git a/tests/ComputeSharp.Tests/ImagingTests.cs b/tests/ComputeSharp.Tests/ImagingTests.cs
index 887c7cbe..c51cb09a 100644
--- a/tests/ComputeSharp.Tests/ImagingTests.cs
+++ b/tests/ComputeSharp.Tests/ImagingTests.cs
@@ -22,6 +22,10 @@ namespace ComputeSharp.Tests
[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(Path.Combine(path, "city.jpg"));
@@ -42,6 +46,8 @@ namespace ComputeSharp.Tests
[AllDevices]
public void GaussianBlur(Device device)
{
+ _ = device.Get();
+
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
using var original = Image.Load(Path.Combine(path, "city.jpg"));