diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs index 5331e22d..437d26c5 100644 --- a/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs @@ -79,22 +79,13 @@ namespace ComputeSharp.Graphics.Buffers.Abstract /// public int Length { get; } - /// - /// Gets the size in bytes of each value contained in the buffer. - /// - protected int ElementSizeInBytes - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => Unsafe.SizeOf(); - } - /// /// Gets whether or not there is some padding between elements in the current buffer. /// internal bool IsPaddingPresent { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => SizeInBytes > Length * Unsafe.SizeOf(); + get => SizeInBytes > (nint)Length * sizeof(T); } /// diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/StructuredBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/StructuredBuffer{T}.cs index 78fad45f..ee91333e 100644 --- a/src/ComputeSharp.Graphics/Buffers/Abstract/StructuredBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/Abstract/StructuredBuffer{T}.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.CompilerServices; using ComputeSharp.Graphics.Buffers.Enums; using ComputeSharp.Graphics.Buffers.Interop; using ComputeSharp.Graphics.Commands; @@ -24,8 +23,8 @@ namespace ComputeSharp.Graphics.Buffers.Abstract /// The associated with the current instance. /// The number of items to store in the current buffer. /// The buffer type for the current buffer. - private protected StructuredBuffer(GraphicsDevice device, int length, ResourceType resourceType) - : base(device, length, (uint)Unsafe.SizeOf(), resourceType) + private protected unsafe StructuredBuffer(GraphicsDevice device, int length, ResourceType resourceType) + : base(device, length, (uint)sizeof(T), resourceType) { } @@ -40,8 +39,8 @@ namespace ComputeSharp.Graphics.Buffers.Abstract Guard.IsLessThanOrEqualTo((uint)offset + destination.Length, (uint)Length, nameof(destination)); nint - byteOffset = (nint)offset * ElementSizeInBytes, - byteSize = (nint)destination.Length * ElementSizeInBytes; + byteOffset = (nint)offset * sizeof(T), + byteSize = (nint)destination.Length * sizeof(T); using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, (ulong)byteSize); @@ -74,8 +73,8 @@ namespace ComputeSharp.Graphics.Buffers.Abstract Guard.IsLessThanOrEqualTo((uint)offset + source.Length, (uint)Length, nameof(source)); nint - byteOffset = (nint)offset * ElementSizeInBytes, - byteSize = (nint)source.Length * ElementSizeInBytes; + byteOffset = (nint)offset * sizeof(T), + byteSize = (nint)source.Length * sizeof(T); using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, (ulong)byteSize); diff --git a/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs index 16c005bb..9fc1bc86 100644 --- a/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs @@ -47,9 +47,9 @@ namespace ComputeSharp /// [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static int GetPaddedSize() + private static unsafe int GetPaddedSize() { - return (Unsafe.SizeOf() + 15) & ~15; + return (sizeof(T) + 15) & ~15; } ///