Added custom exception when using buffers from other devices

このコミットが含まれているのは:
Sergio Pedri committed 2019-09-06 21:43:04 +02:00
1 親 d17e81cdda
コミット fc9c61ca6a
2ファイル変更
+36

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

+3
ファイルの表示
@@ -1,4 +1,5 @@
using System;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Commands.Abstract;
using Vortice.Direct3D12;
@@ -61,6 +62,8 @@ namespace ComputeSharp.Graphics.Commands
public void SetComputeRootDescriptorTable(int rootParameterIndex, GraphicsResource resource)
{
if (resource.NativeGpuDescriptorHandle == null) throw new InvalidOperationException("Invalid graphics resource GPU descriptor");
if (resource.GraphicsDevice != GraphicsDevice) throw new GraphicsDeviceMismatchException(GraphicsDevice, resource);
NativeCommandList.SetComputeRootDescriptorTable(rootParameterIndex, resource.NativeGpuDescriptorHandle.Value);
}
+33
ファイルの表示
@@ -0,0 +1,33 @@
using System;
using System.Diagnostics.Contracts;
using System.Text;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Extensions;
namespace ComputeSharp.Exceptions
{
/// <summary>
/// A custom <see cref="GraphicsDeviceMismatchException"/> that indicates when mismatched devices are being used
/// </summary>
public sealed class GraphicsDeviceMismatchException : InvalidOperationException
{
/// <summary>
/// Creates a new <see cref="GraphicsDeviceMismatchException"/> instance
/// </summary>
internal GraphicsDeviceMismatchException(GraphicsDevice device, GraphicsResource resource) : base(GetExceptionMessage(device, resource)) { }
// Gets a proper exception message for a pair of device and resource
[Pure]
private static string GetExceptionMessage(GraphicsDevice device, GraphicsResource resource)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("Invalid pairing of graphics devices used to run a compute shader and allocate memory buffers.");
builder.AppendLine($"The target device to run the compute shader is \"{device.Name}\" (id: {device.NativeDevice.AdapterLuid}).");
builder.AppendLine($"The buffer of type {resource.GetType().ToFriendlyString()} was allocated on device \"{resource.GraphicsDevice.Name}\" (id: {resource.GraphicsDevice.NativeDevice.AdapterLuid}).");
builder.AppendLine("Make sure to always allocate buffers on the same device used to actually run the code that accesses them.");
return builder.ToString();
}
}
}