diff --git a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs
index 5d3f3172..b8e91f45 100644
--- a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs
+++ b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs
@@ -1075,6 +1075,7 @@ partial class GraphicsDeviceExtensions
/// The length of the buffer to allocate.
/// The allocation mode to use for the new resource.
/// A instance of size .
+ [RequiresUnreferencedCode("This method reads type info of all fields of the resource element type (recursively).")]
public static UploadBuffer AllocateUploadBuffer(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
@@ -1126,6 +1127,7 @@ partial class GraphicsDeviceExtensions
/// The length of the buffer to allocate.
/// The allocation mode to use for the new resource.
/// A instance of size .
+ [RequiresUnreferencedCode("This method reads type info of all fields of the resource element type (recursively).")]
public static ReadBackBuffer AllocateReadBackBuffer(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs
index b227b2f8..33f3efcf 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs
@@ -1,12 +1,15 @@
using System;
using System.Buffers;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using CommunityToolkit.Diagnostics;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Extensions;
+using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Interop;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
+using static TerraFX.Interop.DirectX.D3D12_FEATURE;
using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType;
namespace ComputeSharp.Resources;
@@ -42,6 +45,7 @@ public abstract unsafe class TransferBuffer : NativeObject, IGraphicsResource
/// The number of items to store in the current buffer.
/// The resource type for the current buffer.
/// The allocation mode to use for the new resource.
+ [RequiresUnreferencedCode("This method reads type info of all fields of the resource element type (recursively).")]
private protected TransferBuffer(GraphicsDevice device, int length, ResourceType resourceType, AllocationMode allocationMode)
{
// The maximum length is set such that the aligned buffer size can't exceed uint.MaxValue
@@ -51,6 +55,12 @@ public abstract unsafe class TransferBuffer : NativeObject, IGraphicsResource
device.ThrowIfDeviceLost();
+ if (TypeInfo.IsDoubleOrContainsDoubles &&
+ device.D3D12Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS).DoublePrecisionFloatShaderOps == 0)
+ {
+ UnsupportedDoubleOperationException.Throw();
+ }
+
GraphicsDevice = device;
Length = length;
diff --git a/src/ComputeSharp/Graphics/Resources/ReadBackBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/ReadBackBuffer{T}.cs
index 9ae4cae3..78b8ec2d 100644
--- a/src/ComputeSharp/Graphics/Resources/ReadBackBuffer{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/ReadBackBuffer{T}.cs
@@ -1,4 +1,5 @@
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using ComputeSharp.Graphics.Resources.Enums;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Debug;
@@ -20,6 +21,7 @@ public sealed class ReadBackBuffer : TransferBuffer
/// The associated with the current instance.
/// The number of items to store in the current buffer.
/// The allocation mode to use for the new resource.
+ [RequiresUnreferencedCode("This method reads type info of all fields of the resource element type (recursively).")]
internal ReadBackBuffer(GraphicsDevice device, int length, AllocationMode allocationMode)
: base(device, length, ResourceType.ReadBack, allocationMode)
{
diff --git a/src/ComputeSharp/Graphics/Resources/UploadBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/UploadBuffer{T}.cs
index 61265ee1..1400f410 100644
--- a/src/ComputeSharp/Graphics/Resources/UploadBuffer{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/UploadBuffer{T}.cs
@@ -1,4 +1,5 @@
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using ComputeSharp.Graphics.Resources.Enums;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Debug;
@@ -20,6 +21,7 @@ public sealed class UploadBuffer : TransferBuffer
/// The associated with the current instance.
/// The number of items to store in the current buffer.
/// The allocation mode to use for the new resource.
+ [RequiresUnreferencedCode("This method reads type info of all fields of the resource element type (recursively).")]
internal UploadBuffer(GraphicsDevice device, int length, AllocationMode allocationMode)
: base(device, length, ResourceType.Upload, allocationMode)
{
diff --git a/tests/ComputeSharp.Tests/BufferTests.cs b/tests/ComputeSharp.Tests/BufferTests.cs
index 4e468e16..5d84cf8e 100644
--- a/tests/ComputeSharp.Tests/BufferTests.cs
+++ b/tests/ComputeSharp.Tests/BufferTests.cs
@@ -388,7 +388,7 @@ public partial class BufferTests
[Resource(typeof(ReadOnlyBuffer<>))]
[Resource(typeof(ReadWriteBuffer<>))]
[ExpectedException(typeof(UnsupportedDoubleOperationException))]
- public void Dispatch_ReadWriteBuffer_DoublePrecision_ThrowsExceptionIfUnsupported(Device device, Type resourceType)
+ public void Dispatch_Buffer_DoublePrecision_ThrowsExceptionIfUnsupported(Device device, Type resourceType)
{
if (device.Get().IsDoublePrecisionSupportAvailable())
{
@@ -399,4 +399,21 @@ public partial class BufferTests
Assert.Fail();
}
+
+ [CombinatorialTestMethod]
+ [AllDevices]
+ [Resource(typeof(UploadBuffer<>))]
+ [Resource(typeof(ReadBackBuffer<>))]
+ [ExpectedException(typeof(UnsupportedDoubleOperationException))]
+ public void Dispatch_TransferBuffer_DoublePrecision_ThrowsExceptionIfUnsupported(Device device, Type resourceType)
+ {
+ if (device.Get().IsDoublePrecisionSupportAvailable())
+ {
+ Assert.Inconclusive();
+ }
+
+ using TransferBuffer buffer = device.Get().AllocateTransferBuffer(resourceType, 32);
+
+ Assert.Fail();
+ }
}