update buffer upload ABI

main
cosmonaut 2022-01-13 14:29:08 -08:00
parent 7d7437721c
commit a5c8ebfc3a
3 changed files with 87 additions and 89 deletions

@ -1 +1 @@
Subproject commit 34bf0b69aedfdb50ce4d161173a955998746dad8 Subproject commit 07449cfef8aac872e6e89d085e4732e23314e4ab

View File

@ -668,6 +668,92 @@ namespace MoonWorks.Graphics
); );
} }
/// <summary>
/// Copies arbitrary data into a buffer.
/// </summary>
/// <param name="buffer">The buffer to copy into.</param>
/// <param name="dataPtr">Pointer to the data to copy into the buffer.</param>
/// <param name="bufferOffsetInBytes">Specifies where in the buffer to copy data.</param>
/// <param name="dataLengthInBytes">The length of data that should be copied.</param>
/// <param name="setDataOption">Specifies whether the buffer should be copied in immediate or deferred mode. When in doubt, use deferred.</param>
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
);
}
/// <summary>
/// Copies array data into a buffer.
/// </summary>
/// <param name="buffer">The buffer to copy to.</param>
/// <param name="data">The array to copy from.</param>
/// <param name="bufferOffsetInBytes">Specifies where in the buffer to start copying.</param>
/// <param name="startElement">The index of the first element to copy from the array.</param>
/// <param name="numElements">How many elements to copy.</param>
/// <param name="setDataOption">Specifies whether the buffer should be copied in immediate or deferred mode. When in doubt, use deferred.</param>
public unsafe void SetBufferData<T>(
Buffer buffer,
T[] data,
uint bufferOffsetInBytes,
uint startElement,
uint numElements,
Refresh.SetDataOptions setDataOption = Refresh.SetDataOptions.Deferred
) where T : unmanaged
{
var elementSize = Marshal.SizeOf<T>();
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
);
}
}
/// <summary>
/// Copies array data into a buffer.
/// </summary>
/// <param name="buffer">The buffer to copy to.</param>
/// <param name="data">The array to copy from.</param>
/// <param name="bufferOffsetInBytes">Specifies where in the buffer to start copying.</param>
/// <param name="setDataOption">Specifies whether the buffer should be copied in immediate or deferred mode. When in doubt, use deferred.</param>
public unsafe void SetBufferData<T>(
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
);
}
/// <summary> /// <summary>
/// Asynchronously copies data into a texture. /// Asynchronously copies data into a texture.
/// </summary> /// </summary>

View File

@ -30,94 +30,6 @@ namespace MoonWorks.Graphics
); );
} }
/// <summary>
/// Asynchronously copies data into the buffer.
/// </summary>
/// <param name="data">An array of data to copy into the buffer.</param>
/// <param name="offsetInElements">Specifies where to start copying out of the array.</param>
/// <param name="lengthInElements">Specifies how many elements to copy.</param>
public unsafe void SetData<T>(
T[] data,
uint offsetInElements,
uint lengthInElements
) where T : unmanaged
{
var elementSize = Marshal.SizeOf<T>();
fixed (T* ptr = &data[0])
{
Refresh.Refresh_SetBufferData(
Device.Handle,
Handle,
(uint) (offsetInElements * elementSize),
(IntPtr) ptr,
(uint) (lengthInElements * elementSize)
);
}
}
/// <summary>
/// Asynchronously copies data into the buffer.
/// This variant of this method copies the entire array.
/// </summary>
/// <param name="data">An array of data to copy.</param>
public unsafe void SetData<T>(
T[] data
) where T : unmanaged
{
fixed (T* ptr = &data[0])
{
Refresh.Refresh_SetBufferData(
Device.Handle,
Handle,
0,
(IntPtr)ptr,
(uint) (data.Length * Marshal.SizeOf<T>())
);
}
}
/// <summary>
/// Asynchronously copies data into the buffer.
/// </summary>
/// <param name="data">A pointer to an array.</param>
/// <param name="offsetInBytes">Specifies where to start copying the data, in bytes.</param>
/// <param name="dataLengthInBytes">Specifies how many bytes of data to copy.</param>
public void SetData(
IntPtr data,
uint offsetInBytes,
uint dataLengthInBytes
) {
Refresh.Refresh_SetBufferData(
Device.Handle,
Handle,
offsetInBytes,
data,
dataLengthInBytes
);
}
/// <summary>
/// Asynchronously copies data into the buffer.
/// </summary>
/// <param name="data">A pointer to an array.</param>
/// <param name="offsetInBytes">Specifies where to start copying the data, in bytes.</param>
/// <param name="dataLengthInBytes">Specifies how many bytes of data to copy.</param>
public unsafe void SetData<T>(
T* data,
uint offsetInElements,
uint lengthInElements
) where T : unmanaged {
var elementSize = Marshal.SizeOf<T>();
Refresh.Refresh_SetBufferData(
Device.Handle,
Handle,
(uint) (offsetInElements * elementSize),
(IntPtr) data,
(uint) (lengthInElements * elementSize)
);
}
/// <summary> /// <summary>
/// Reads data out of a buffer and into an array. /// 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. /// This operation is only guaranteed to read up-to-date data if GraphicsDevice.Wait is called first.