From 9f68fc31da7b55f1052e3ed41b65999a633a6529 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 1 Aug 2022 23:48:38 +0200 Subject: [PATCH] Fix NAOT trimming annotations for ComputeSharp --- .../GraphicsDeviceMismatchException.cs | 3 +- .../Graphics/Extensions/BufferExtensions.cs | 29 ++++++++++--------- .../GraphicsDeviceExtensions.Resources.cs | 25 ++++++++-------- .../Extensions/ReadBackBufferExtensions.cs | 7 +++-- .../Extensions/StructuredBufferExtensions.cs | 11 +++---- .../Extensions/UploadBufferExtensions.cs | 7 +++-- .../Graphics/Helpers/TypeInfo{T}.cs | 2 ++ .../__Internals/GraphicsResourceHelper.cs | 3 +- .../Graphics/Interop/InteropServices.cs | 5 ++-- .../Graphics/Resources/Abstract/Buffer{T}.cs | 6 ++-- .../Resources/Abstract/StructuredBuffer{T}.cs | 5 ++-- .../Graphics/Resources/ConstantBuffer{T}.cs | 3 +- .../Resources/Debug/BufferDebugView{T}.cs | 3 +- .../Graphics/Resources/ReadOnlyBuffer{T}.cs | 3 +- .../Graphics/Resources/ReadWriteBuffer{T}.cs | 3 +- .../Extensions/ComputeContextExtensions.cs | 7 +++-- 16 files changed, 69 insertions(+), 53 deletions(-) diff --git a/src/ComputeSharp/Graphics/Exceptions/GraphicsDeviceMismatchException.cs b/src/ComputeSharp/Graphics/Exceptions/GraphicsDeviceMismatchException.cs index 6283a35b..36ede967 100644 --- a/src/ComputeSharp/Graphics/Exceptions/GraphicsDeviceMismatchException.cs +++ b/src/ComputeSharp/Graphics/Exceptions/GraphicsDeviceMismatchException.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Text; using ComputeSharp.Interop; using ComputeSharp.Resources; @@ -49,7 +50,7 @@ public sealed class GraphicsDeviceMismatchException : InvalidOperationException /// The type of values in the input buffer. /// The input that was used. /// The target instance that was used. - internal static void Throw(Buffer buffer, GraphicsDevice device) + internal static void Throw<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(Buffer buffer, GraphicsDevice device) where T : unmanaged { throw Create(buffer, buffer.GraphicsDevice, device); diff --git a/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs b/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs index 6045ba1e..35a0b9cb 100644 --- a/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using CommunityToolkit.Diagnostics; using ComputeSharp.Resources; @@ -19,7 +20,7 @@ public static class BufferExtensions /// The type of items stored on the buffer. /// The input instance to read data from. /// A array with the contents of the input buffer. - public static T[] ToArray(this Buffer source) + public static T[] ToArray<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer source) where T : unmanaged { Guard.IsNotNull(source); @@ -35,7 +36,7 @@ public static class BufferExtensions /// The offset to start reading data from. /// The number of items to read. /// A array with the contents of the specified range from the current buffer. - public static T[] ToArray(this Buffer source, int offset, int count) + public static T[] ToArray<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer source, int offset, int count) where T : unmanaged { Guard.IsNotNull(source); @@ -54,7 +55,7 @@ public static class BufferExtensions /// The type of items stored on the buffer. /// The input instance to read data from. /// The input array to write data to. - public static void CopyTo(this Buffer source, T[] destination) + public static void CopyTo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer source, T[] destination) where T : unmanaged { Guard.IsNotNull(source); @@ -72,7 +73,7 @@ public static class BufferExtensions /// The offset to start reading data from. /// The starting offset within to write data to. /// The number of items to read. - public static void CopyTo(this Buffer source, T[] destination, int sourceOffset, int destinationOffset, int count) + public static void CopyTo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer source, T[] destination, int sourceOffset, int destinationOffset, int count) where T : unmanaged { Guard.IsNotNull(source); @@ -89,7 +90,7 @@ public static class BufferExtensions /// The type of items stored on the buffer. /// The input instance to read data from. /// The input to write data to. - public static void CopyTo(this Buffer source, Span destination) + public static void CopyTo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer source, Span destination) where T : unmanaged { Guard.IsNotNull(source); @@ -104,7 +105,7 @@ public static class BufferExtensions /// The input instance to read data from. /// The input to write data to. /// The offset to start reading data from. - public static void CopyTo(this Buffer source, Span destination, int sourceOffset) + public static void CopyTo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer source, Span destination, int sourceOffset) where T : unmanaged { Guard.IsNotNull(source); @@ -118,7 +119,7 @@ public static class BufferExtensions /// The type of items stored on the buffers. /// The input instance to read data from. /// The target instance to write data to. - public static void CopyTo(this Buffer source, Buffer destination) + public static void CopyTo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer source, Buffer destination) where T : unmanaged { Guard.IsNotNull(source); @@ -136,7 +137,7 @@ public static class BufferExtensions /// The offset to start reading data from. /// The starting offset within to write data to. /// The number of items to read. - public static void CopyTo(this Buffer source, Buffer destination, int sourceOffset, int destinationOffset, int count) + public static void CopyTo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer source, Buffer destination, int sourceOffset, int destinationOffset, int count) where T : unmanaged { Guard.IsNotNull(source); @@ -151,7 +152,7 @@ public static class BufferExtensions /// The type of items stored on the buffer. /// The target instance to write data to. /// The input array to read data from. - public static void CopyFrom(this Buffer destination, T[] source) + public static void CopyFrom<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer destination, T[] source) where T : unmanaged { Guard.IsNotNull(destination); @@ -169,7 +170,7 @@ public static class BufferExtensions /// The starting offset within to read data from. /// The offset to start writing data to. /// The number of items to write. - public static void CopyFrom(this Buffer destination, T[] source, int sourceOffset, int destinationOffset, int count) + public static void CopyFrom<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer destination, T[] source, int sourceOffset, int destinationOffset, int count) where T : unmanaged { Guard.IsNotNull(destination); @@ -186,7 +187,7 @@ public static class BufferExtensions /// The type of items stored on the buffer. /// The target instance to write data to. /// The input to read data from. - public static void CopyFrom(this Buffer destination, ReadOnlySpan source) + public static void CopyFrom<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer destination, ReadOnlySpan source) where T : unmanaged { Guard.IsNotNull(destination); @@ -201,7 +202,7 @@ public static class BufferExtensions /// The target instance to write data to. /// The input to read data from. /// The offset to start writing data to. - public static void CopyFrom(this Buffer destination, ReadOnlySpan source, int destinationOffset) + public static void CopyFrom<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer destination, ReadOnlySpan source, int destinationOffset) where T : unmanaged { Guard.IsNotNull(destination); @@ -215,7 +216,7 @@ public static class BufferExtensions /// The type of items stored on the buffers. /// The input instance to write data data to. /// The source instance to read data from. - public static void CopyFrom(this Buffer destination, Buffer source) + public static void CopyFrom<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer destination, Buffer source) where T : unmanaged { Guard.IsNotNull(destination); @@ -233,7 +234,7 @@ public static class BufferExtensions /// The offset to start reading data from. /// The starting offset within to write data to. /// The number of items to read. - public static void CopyFrom(this Buffer destination, Buffer source, int sourceOffset, int destinationOffset, int count) + public static void CopyFrom<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this Buffer destination, Buffer source, int sourceOffset, int destinationOffset, int count) where T : unmanaged { Guard.IsNotNull(destination); diff --git a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs index a434df13..e545adbf 100644 --- a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs +++ b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.IO; using CommunityToolkit.Diagnostics; using ComputeSharp.Graphics.Helpers; @@ -17,7 +18,7 @@ partial class GraphicsDeviceExtensions /// The length of the buffer to allocate. /// The allocation mode to use for the new resource. /// A zeroed instance of size . - public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default) + public static ConstantBuffer AllocateConstantBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default) where T : unmanaged { Guard.IsNotNull(device); @@ -32,7 +33,7 @@ partial class GraphicsDeviceExtensions /// The instance to use to allocate the buffer. /// The input array with the data to copy on the allocated buffer. /// A constant instance with the contents of the input array. - public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, T[] source) + public static ConstantBuffer AllocateConstantBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, T[] source) where T : unmanaged { Guard.IsNotNull(device); @@ -48,7 +49,7 @@ partial class GraphicsDeviceExtensions /// The instance to use to allocate the buffer. /// The input with the data to copy on the allocated buffer. /// A constant instance with the contents of the input . - public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, ReadOnlySpan source) + public static ConstantBuffer AllocateConstantBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, ReadOnlySpan source) where T : unmanaged { Guard.IsNotNull(device); @@ -67,7 +68,7 @@ partial class GraphicsDeviceExtensions /// The instance to use to allocate the buffer. /// The input with the data to copy on the allocated buffer. /// A constant instance with the contents of the input . - public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, Buffer source) + public static ConstantBuffer AllocateConstantBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, Buffer source) where T : unmanaged { Guard.IsNotNull(device); @@ -88,7 +89,7 @@ partial class GraphicsDeviceExtensions /// The length of the buffer to allocate. /// The allocation mode to use for the new resource. /// A zeroed instance of size . - public static ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default) + public static ReadOnlyBuffer AllocateReadOnlyBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default) where T : unmanaged { Guard.IsNotNull(device); @@ -103,7 +104,7 @@ partial class GraphicsDeviceExtensions /// The instance to use to allocate the buffer. /// The input array with the data to copy on the allocated buffer. /// A read write instance with the contents of the input array. - public static ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, T[] source) + public static ReadOnlyBuffer AllocateReadOnlyBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, T[] source) where T : unmanaged { Guard.IsNotNull(device); @@ -119,7 +120,7 @@ partial class GraphicsDeviceExtensions /// The instance to use to allocate the buffer. /// The input with the data to copy on the allocated buffer. /// A read write instance with the contents of the input . - public static ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, ReadOnlySpan source) + public static ReadOnlyBuffer AllocateReadOnlyBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, ReadOnlySpan source) where T : unmanaged { Guard.IsNotNull(device); @@ -138,7 +139,7 @@ partial class GraphicsDeviceExtensions /// The instance to use to allocate the buffer. /// The input with the data to copy on the allocated buffer. /// A read write instance with the contents of the input . - public static ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, Buffer source) + public static ReadOnlyBuffer AllocateReadOnlyBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, Buffer source) where T : unmanaged { Guard.IsNotNull(device); @@ -575,7 +576,7 @@ partial class GraphicsDeviceExtensions /// The length of the buffer to allocate. /// The allocation mode to use for the new resource. /// A zeroed instance of size . - public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default) + public static ReadWriteBuffer AllocateReadWriteBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default) where T : unmanaged { Guard.IsNotNull(device); @@ -590,7 +591,7 @@ partial class GraphicsDeviceExtensions /// The instance to use to allocate the buffer. /// The input array with the data to copy on the allocated buffer. /// A read write instance with the contents of the input array. - public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, T[] source) + public static ReadWriteBuffer AllocateReadWriteBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, T[] source) where T : unmanaged { Guard.IsNotNull(device); @@ -606,7 +607,7 @@ partial class GraphicsDeviceExtensions /// The instance to use to allocate the buffer. /// The input with the data to copy on the allocated buffer. /// A read write instance with the contents of the input . - public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, ReadOnlySpan source) + public static ReadWriteBuffer AllocateReadWriteBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, ReadOnlySpan source) where T : unmanaged { Guard.IsNotNull(device); @@ -625,7 +626,7 @@ partial class GraphicsDeviceExtensions /// The instance to use to allocate the buffer. /// The input with the data to copy on the allocated buffer. /// A read write instance with the contents of the input . - public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, Buffer source) + public static ReadWriteBuffer AllocateReadWriteBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this GraphicsDevice device, Buffer source) where T : unmanaged { Guard.IsNotNull(device); diff --git a/src/ComputeSharp/Graphics/Extensions/ReadBackBufferExtensions.cs b/src/ComputeSharp/Graphics/Extensions/ReadBackBufferExtensions.cs index 0940cf5d..ce322cbf 100644 --- a/src/ComputeSharp/Graphics/Extensions/ReadBackBufferExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/ReadBackBufferExtensions.cs @@ -1,4 +1,5 @@ -using CommunityToolkit.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using CommunityToolkit.Diagnostics; using ComputeSharp.Resources; namespace ComputeSharp; @@ -14,7 +15,7 @@ public static class ReadBackBufferExtensions /// The type of items stored on the buffer. /// The target instance to write data to. /// The input instance to read data from. - public static void CopyFrom(this ReadBackBuffer destination, StructuredBuffer source) + public static void CopyFrom<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this ReadBackBuffer destination, StructuredBuffer source) where T : unmanaged { Guard.IsNotNull(destination); @@ -32,7 +33,7 @@ public static class ReadBackBufferExtensions /// The offset to start reading data from. /// The starting offset within to write data to. /// The number of items to read. - public static void CopyFrom(this ReadBackBuffer destination, StructuredBuffer source, int sourceOffset, int destinationOffset, int count) + public static void CopyFrom<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this ReadBackBuffer destination, StructuredBuffer source, int sourceOffset, int destinationOffset, int count) where T : unmanaged { Guard.IsNotNull(destination); diff --git a/src/ComputeSharp/Graphics/Extensions/StructuredBufferExtensions.cs b/src/ComputeSharp/Graphics/Extensions/StructuredBufferExtensions.cs index 1166042e..6f86a471 100644 --- a/src/ComputeSharp/Graphics/Extensions/StructuredBufferExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/StructuredBufferExtensions.cs @@ -1,4 +1,5 @@ -using CommunityToolkit.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using CommunityToolkit.Diagnostics; using ComputeSharp.Resources; namespace ComputeSharp; @@ -14,7 +15,7 @@ public static class StructuredBufferExtensions /// The type of items stored on the buffer. /// The input instance to read data from. /// The target instance to write data to. - public static void CopyTo(this StructuredBuffer source, ReadBackBuffer destination) + public static void CopyTo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this StructuredBuffer source, ReadBackBuffer destination) where T : unmanaged { Guard.IsNotNull(source); @@ -32,7 +33,7 @@ public static class StructuredBufferExtensions /// The offset to start reading data from. /// The starting offset within to write data to. /// The number of items to read. - public static void CopyTo(this StructuredBuffer source, ReadBackBuffer destination, int sourceOffset, int destinationOffset, int count) + public static void CopyTo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this StructuredBuffer source, ReadBackBuffer destination, int sourceOffset, int destinationOffset, int count) where T : unmanaged { Guard.IsNotNull(source); @@ -47,7 +48,7 @@ public static class StructuredBufferExtensions /// The type of items stored on the buffer. /// The target instance to write data to. /// The input instance to read data from. - public static void CopyFrom(this StructuredBuffer destination, UploadBuffer source) + public static void CopyFrom<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this StructuredBuffer destination, UploadBuffer source) where T : unmanaged { Guard.IsNotNull(destination); @@ -65,7 +66,7 @@ public static class StructuredBufferExtensions /// The offset to start reading data from. /// The starting offset within to write data to. /// The number of items to read. - public static void CopyFrom(this StructuredBuffer destination, UploadBuffer source, int sourceOffset, int destinationOffset, int count) + public static void CopyFrom<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this StructuredBuffer destination, UploadBuffer source, int sourceOffset, int destinationOffset, int count) where T : unmanaged { Guard.IsNotNull(destination); diff --git a/src/ComputeSharp/Graphics/Extensions/UploadBufferExtensions.cs b/src/ComputeSharp/Graphics/Extensions/UploadBufferExtensions.cs index 118eeb9e..4a3aa8d4 100644 --- a/src/ComputeSharp/Graphics/Extensions/UploadBufferExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/UploadBufferExtensions.cs @@ -1,4 +1,5 @@ -using CommunityToolkit.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using CommunityToolkit.Diagnostics; using ComputeSharp.Resources; namespace ComputeSharp; @@ -14,7 +15,7 @@ public static class UploadBufferExtensions /// The type of items stored on the buffer. /// The input instance to read data from. /// The target instance to write data to. - public static void CopyTo(this UploadBuffer source, StructuredBuffer destination) + public static void CopyTo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this UploadBuffer source, StructuredBuffer destination) where T : unmanaged { Guard.IsNotNull(source); @@ -32,7 +33,7 @@ public static class UploadBufferExtensions /// The offset to start reading data from. /// The starting offset within to write data to. /// The number of items to read. - public static void CopyTo(this UploadBuffer source, StructuredBuffer destination, int sourceOffset, int destinationOffset, int count) + public static void CopyTo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this UploadBuffer source, StructuredBuffer destination, int sourceOffset, int destinationOffset, int count) where T : unmanaged { Guard.IsNotNull(source); diff --git a/src/ComputeSharp/Graphics/Helpers/TypeInfo{T}.cs b/src/ComputeSharp/Graphics/Helpers/TypeInfo{T}.cs index 2b4948f6..cc860a7e 100644 --- a/src/ComputeSharp/Graphics/Helpers/TypeInfo{T}.cs +++ b/src/ComputeSharp/Graphics/Helpers/TypeInfo{T}.cs @@ -29,7 +29,9 @@ internal static class TypeInfo<[DynamicallyAccessedMembers(DynamicallyAccessedMe foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { +#pragma warning disable IL2072 // 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' if (ChecksIsDoubleOrContainsDoubles(fieldInfo.FieldType)) +#pragma warning restore IL2072 { return true; } diff --git a/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs b/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs index fd4dea7c..23997e72 100644 --- a/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using CommunityToolkit.Diagnostics; using ComputeSharp.Interop; @@ -62,7 +63,7 @@ public static class GraphicsResourceHelper /// The target instance in use. /// The GPU descriptor handle for the buffer. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe ulong ValidateAndGetGpuDescriptorHandle(Buffer buffer, GraphicsDevice device) + public static unsafe ulong ValidateAndGetGpuDescriptorHandle<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(Buffer buffer, GraphicsDevice device) where T : unmanaged { Guard.IsNotNull(buffer); diff --git a/src/ComputeSharp/Graphics/Interop/InteropServices.cs b/src/ComputeSharp/Graphics/Interop/InteropServices.cs index 5427cb64..f6e06929 100644 --- a/src/ComputeSharp/Graphics/Interop/InteropServices.cs +++ b/src/ComputeSharp/Graphics/Interop/InteropServices.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using ComputeSharp.Core.Extensions; using ComputeSharp.Resources; @@ -49,7 +50,7 @@ public static unsafe class InteropServices /// The address of a pointer to an interface with the IID specified in . /// The instance has been disposed. /// Thrown if the IUnknown::QueryInterface call doesn't return S_OK. - public static void GetID3D12Resource(Buffer buffer, Guid* riid, void** ppvObject) + public static void GetID3D12Resource<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(Buffer buffer, Guid* riid, void** ppvObject) where T : unmanaged { using var _0 = buffer.GetReferenceTrackingLease(); @@ -179,7 +180,7 @@ public static unsafe class InteropServices /// If ppvObject (the address) is nullptr, then this method returns E_POINTER. /// /// The instance has been disposed. - public static int TryGetID3D12Resource(Buffer buffer, Guid* riid, void** ppvObject) + public static int TryGetID3D12Resource<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(Buffer buffer, Guid* riid, void** ppvObject) where T : unmanaged { using var _0 = buffer.GetReferenceTrackingLease(); diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs index 2d97587d..1fb3a508 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs @@ -1,5 +1,5 @@ -using System; -using System.Buffers; +using System.Buffers; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using CommunityToolkit.Diagnostics; using ComputeSharp.Core.Helpers; @@ -25,7 +25,7 @@ namespace ComputeSharp.Resources; /// A representing a typed buffer stored on GPU memory. /// /// The type of items stored on the buffer. -public unsafe abstract class Buffer : NativeObject, IGraphicsResource +public unsafe abstract class Buffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T> : NativeObject, IGraphicsResource where T : unmanaged { #if NET6_0_OR_GREATER diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs index 81a977de..88f47a2e 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs @@ -1,4 +1,5 @@ -using CommunityToolkit.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using CommunityToolkit.Diagnostics; using ComputeSharp.Graphics.Commands; using ComputeSharp.Graphics.Extensions; using ComputeSharp.Graphics.Helpers; @@ -14,7 +15,7 @@ namespace ComputeSharp.Resources; /// A representing a typed structured buffer stored on GPU memory. /// /// The type of items stored on the buffer. -public abstract class StructuredBuffer : Buffer +public abstract class StructuredBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T> : Buffer where T : unmanaged { /// diff --git a/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs index f7002cdc..e131d2a9 100644 --- a/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using CommunityToolkit.Diagnostics; using ComputeSharp.Core.Helpers; @@ -19,7 +20,7 @@ namespace ComputeSharp; /// The type of items stored on the buffer. [DebuggerTypeProxy(typeof(BufferDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] -public sealed class ConstantBuffer : Buffer +public sealed class ConstantBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T> : Buffer where T : unmanaged { /// diff --git a/src/ComputeSharp/Graphics/Resources/Debug/BufferDebugView{T}.cs b/src/ComputeSharp/Graphics/Resources/Debug/BufferDebugView{T}.cs index 6ee0d853..a290ea03 100644 --- a/src/ComputeSharp/Graphics/Resources/Debug/BufferDebugView{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Debug/BufferDebugView{T}.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; #if NET6_0_OR_GREATER using GC = System.GC; #else @@ -11,7 +12,7 @@ namespace ComputeSharp.Resources.Debug; /// A debug proxy used to display items in a instance. /// /// The type of items to display. -internal sealed class BufferDebugView +internal sealed class BufferDebugView<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T> where T : unmanaged { /// diff --git a/src/ComputeSharp/Graphics/Resources/ReadOnlyBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/ReadOnlyBuffer{T}.cs index 46613dae..98d7108e 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadOnlyBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadOnlyBuffer{T}.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Resources.Enums; using ComputeSharp.Resources; @@ -12,7 +13,7 @@ namespace ComputeSharp; /// The type of items stored on the buffer. [DebuggerTypeProxy(typeof(BufferDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] -public sealed class ReadOnlyBuffer : StructuredBuffer +public sealed class ReadOnlyBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T> : StructuredBuffer where T : unmanaged { /// diff --git a/src/ComputeSharp/Graphics/Resources/ReadWriteBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/ReadWriteBuffer{T}.cs index 469669ff..315eae39 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadWriteBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadWriteBuffer{T}.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Resources.Enums; using ComputeSharp.Resources; @@ -12,7 +13,7 @@ namespace ComputeSharp; /// The type of items stored on the buffer. [DebuggerTypeProxy(typeof(BufferDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] -public sealed class ReadWriteBuffer : StructuredBuffer +public sealed class ReadWriteBuffer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T> : StructuredBuffer where T : unmanaged { /// diff --git a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs index 6b6bc55f..f150cd76 100644 --- a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs +++ b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs @@ -1,4 +1,5 @@ -using System.Runtime.CompilerServices; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using CommunityToolkit.Diagnostics; using ComputeSharp.__Internals; using ComputeSharp.Graphics.Helpers; @@ -20,7 +21,7 @@ public static class ComputeContextExtensions /// The type of items stored on the buffer. /// The to use to insert the resource barrier. /// The input instance to insert the barrier for. - public static unsafe void Barrier(this in ComputeContext context, ReadWriteBuffer buffer) + public static unsafe void Barrier<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this in ComputeContext context, ReadWriteBuffer buffer) where T : unmanaged { Guard.IsNotNull(buffer); @@ -136,7 +137,7 @@ public static class ComputeContextExtensions /// The type of items stored on the buffer. /// The to use to clear the resource. /// The input instance to clear. - public static unsafe void Clear(this in ComputeContext context, ReadWriteBuffer buffer) + public static unsafe void Clear<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this in ComputeContext context, ReadWriteBuffer buffer) where T : unmanaged { Guard.IsNotNull(buffer);