From a5c8ebfc3ae97dcae3ccbdbe3a5bc920b7dca0a6 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 13 Jan 2022 14:29:08 -0800 Subject: [PATCH] update buffer upload ABI --- lib/RefreshCS | 2 +- src/Graphics/CommandBuffer.cs | 86 +++++++++++++++++++++++++++++++ src/Graphics/Resources/Buffer.cs | 88 -------------------------------- 3 files changed, 87 insertions(+), 89 deletions(-) diff --git a/lib/RefreshCS b/lib/RefreshCS index 34bf0b69..07449cfe 160000 --- a/lib/RefreshCS +++ b/lib/RefreshCS @@ -1 +1 @@ -Subproject commit 34bf0b69aedfdb50ce4d161173a955998746dad8 +Subproject commit 07449cfef8aac872e6e89d085e4732e23314e4ab diff --git a/src/Graphics/CommandBuffer.cs b/src/Graphics/CommandBuffer.cs index 309918fc..034515b1 100644 --- a/src/Graphics/CommandBuffer.cs +++ b/src/Graphics/CommandBuffer.cs @@ -668,6 +668,92 @@ namespace MoonWorks.Graphics ); } + /// + /// Copies arbitrary data into a buffer. + /// + /// The buffer to copy into. + /// Pointer to the data to copy into the buffer. + /// Specifies where in the buffer to copy data. + /// The length of data that should be copied. + /// Specifies whether the buffer should be copied in immediate or deferred mode. When in doubt, use deferred. + public void SetBufferData( + Buffer buffer, + IntPtr dataPtr, + uint bufferOffsetInBytes, + uint dataLengthInBytes, + Refresh.SetDataOptions setDataOption = Refresh.SetDataOptions.Deferred + ) { + Refresh.Refresh_SetBufferData( + Device.Handle, + Handle, + buffer.Handle, + bufferOffsetInBytes, + dataPtr, + dataLengthInBytes, + setDataOption + ); + } + + /// + /// Copies array data into a buffer. + /// + /// The buffer to copy to. + /// The array to copy from. + /// Specifies where in the buffer to start copying. + /// The index of the first element to copy from the array. + /// How many elements to copy. + /// Specifies whether the buffer should be copied in immediate or deferred mode. When in doubt, use deferred. + public unsafe void SetBufferData( + Buffer buffer, + T[] data, + uint bufferOffsetInBytes, + uint startElement, + uint numElements, + Refresh.SetDataOptions setDataOption = Refresh.SetDataOptions.Deferred + ) where T : unmanaged + { + var elementSize = Marshal.SizeOf(); + + fixed (T* ptr = &data[0]) + { + var dataPtr = ptr + (startElement * elementSize); + + Refresh.Refresh_SetBufferData( + Device.Handle, + Handle, + buffer.Handle, + bufferOffsetInBytes, + (IntPtr) dataPtr, + (uint) (numElements * elementSize), + setDataOption + ); + } + } + + /// + /// Copies array data into a buffer. + /// + /// The buffer to copy to. + /// The array to copy from. + /// Specifies where in the buffer to start copying. + /// Specifies whether the buffer should be copied in immediate or deferred mode. When in doubt, use deferred. + public unsafe void SetBufferData( + Buffer buffer, + T[] data, + uint bufferOffsetInBytes = 0, + Refresh.SetDataOptions setDataOption = Refresh.SetDataOptions.Deferred + ) where T : unmanaged + { + SetBufferData( + buffer, + data, + bufferOffsetInBytes, + 0, + (uint) data.Length, + setDataOption + ); + } + /// /// Asynchronously copies data into a texture. /// diff --git a/src/Graphics/Resources/Buffer.cs b/src/Graphics/Resources/Buffer.cs index 8004064c..4b638ff2 100644 --- a/src/Graphics/Resources/Buffer.cs +++ b/src/Graphics/Resources/Buffer.cs @@ -30,94 +30,6 @@ namespace MoonWorks.Graphics ); } - /// - /// Asynchronously copies data into the buffer. - /// - /// An array of data to copy into the buffer. - /// Specifies where to start copying out of the array. - /// Specifies how many elements to copy. - public unsafe void SetData( - T[] data, - uint offsetInElements, - uint lengthInElements - ) where T : unmanaged - { - var elementSize = Marshal.SizeOf(); - - fixed (T* ptr = &data[0]) - { - Refresh.Refresh_SetBufferData( - Device.Handle, - Handle, - (uint) (offsetInElements * elementSize), - (IntPtr) ptr, - (uint) (lengthInElements * elementSize) - ); - } - } - - /// - /// Asynchronously copies data into the buffer. - /// This variant of this method copies the entire array. - /// - /// An array of data to copy. - public unsafe void SetData( - T[] data - ) where T : unmanaged - { - fixed (T* ptr = &data[0]) - { - Refresh.Refresh_SetBufferData( - Device.Handle, - Handle, - 0, - (IntPtr)ptr, - (uint) (data.Length * Marshal.SizeOf()) - ); - } - } - - /// - /// Asynchronously copies data into the buffer. - /// - /// A pointer to an array. - /// Specifies where to start copying the data, in bytes. - /// Specifies how many bytes of data to copy. - public void SetData( - IntPtr data, - uint offsetInBytes, - uint dataLengthInBytes - ) { - Refresh.Refresh_SetBufferData( - Device.Handle, - Handle, - offsetInBytes, - data, - dataLengthInBytes - ); - } - - /// - /// Asynchronously copies data into the buffer. - /// - /// A pointer to an array. - /// Specifies where to start copying the data, in bytes. - /// Specifies how many bytes of data to copy. - public unsafe void SetData( - T* data, - uint offsetInElements, - uint lengthInElements - ) where T : unmanaged { - var elementSize = Marshal.SizeOf(); - Refresh.Refresh_SetBufferData( - Device.Handle, - Handle, - (uint) (offsetInElements * elementSize), - (IntPtr) data, - (uint) (lengthInElements * elementSize) - ); - } - /// /// Reads data out of a buffer and into an array. /// This operation is only guaranteed to read up-to-date data if GraphicsDevice.Wait is called first.