From 7f8c2053301330b059787f502c54cd5ade52d325 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 15 Aug 2019 16:04:15 +0200 Subject: [PATCH] Code refactoring, removed cross dependencies in some buffer classes --- ...turedBuffer.cs => HlslStructuredBuffer{T}.cs} | 2 +- .../Buffers/{Buffer.cs => Buffer{T}.cs} | 11 +++++++++++ .../Buffers/ConstantBuffer{T}.cs | 16 +--------------- 3 files changed, 13 insertions(+), 16 deletions(-) rename src/ComputeSharp.Graphics/Buffers/Abstract/{HlslStructuredBuffer.cs => HlslStructuredBuffer{T}.cs} (96%) rename src/ComputeSharp.Graphics/Buffers/{Buffer.cs => Buffer{T}.cs} (93%) diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs similarity index 96% rename from src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer.cs rename to src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs index 2a7e2d5b..944adb56 100644 --- a/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer.cs +++ b/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs @@ -53,7 +53,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract /// public override void SetData(HlslBuffer buffer) { - if (buffer is ConstantBuffer readOnlyBuffer && !readOnlyBuffer.IsPaddingPresent) + if (!buffer.IsPaddingPresent) { // Directly copy the input buffer using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy); diff --git a/src/ComputeSharp.Graphics/Buffers/Buffer.cs b/src/ComputeSharp.Graphics/Buffers/Buffer{T}.cs similarity index 93% rename from src/ComputeSharp.Graphics/Buffers/Buffer.cs rename to src/ComputeSharp.Graphics/Buffers/Buffer{T}.cs index 2be4b4b0..c08a8304 100644 --- a/src/ComputeSharp.Graphics/Buffers/Buffer.cs +++ b/src/ComputeSharp.Graphics/Buffers/Buffer{T}.cs @@ -26,6 +26,7 @@ namespace ComputeSharp.Graphics.Buffers SizeInBytes = sizeInBytes; // Not necessarily a multiple of the element size, as there could be padding ElementSizeInBytes = Unsafe.SizeOf(); BufferType = bufferType; + PaddedElementSizeInBytes = sizeInBytes / size; // Determine the right heap type and flags (HeapType heapType, ResourceFlags flags, ResourceStates states) = bufferType switch @@ -67,6 +68,16 @@ namespace ComputeSharp.Graphics.Buffers /// protected int ElementSizeInBytes { get; } + /// + /// Gets the size in bytes of the current buffer + /// + internal int PaddedElementSizeInBytes { get; } + + /// + /// Gets whether or not there is some padding between elements in the current buffer + /// + internal bool IsPaddingPresent => PaddedElementSizeInBytes > ElementSizeInBytes; + /// /// Gets the buffer type for the current instance /// diff --git a/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs index 96b09c2a..4ee092c8 100644 --- a/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs @@ -20,21 +20,7 @@ namespace ComputeSharp.Graphics.Buffers /// /// The associated with the current instance /// The number of items to store in the current buffer - internal ConstantBuffer(GraphicsDevice device, int size) : base(device, size, size * (Unsafe.SizeOf() / 16 + 1) * 16, BufferType.Constant) - { - PaddedElementSizeInBytes = SizeInBytes / Size; - IsPaddingPresent = PaddedElementSizeInBytes > ElementSizeInBytes; - } - - /// - /// Gets the size in bytes of the current buffer - /// - internal int PaddedElementSizeInBytes { get; } - - /// - /// Gets whether or not there is some padding between elements in the current buffer - /// - internal bool IsPaddingPresent { get; } + internal ConstantBuffer(GraphicsDevice device, int size) : base(device, size, size * (Unsafe.SizeOf() / 16 + 1) * 16, BufferType.Constant) { } /// /// Gets a single value from the current constant buffer