remove byte pointer interface from TransferBuffer
parent
ad97aed60f
commit
ecfcb666a8
|
@ -99,7 +99,8 @@ namespace MoonWorks.Graphics
|
||||||
TransferBuffer = new TransferBuffer(Device, dataSize);
|
TransferBuffer = new TransferBuffer(Device, dataSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
TransferBuffer.SetData(data, new BufferCopy(0, 0, dataSize), SetDataOptions.Discard);
|
var dataSpan = new Span<byte>(data, (int) dataSize);
|
||||||
|
TransferBuffer.SetData(dataSpan, SetDataOptions.Discard);
|
||||||
|
|
||||||
var commandBuffer = Device.AcquireCommandBuffer();
|
var commandBuffer = Device.AcquireCommandBuffer();
|
||||||
|
|
||||||
|
|
|
@ -48,29 +48,6 @@ namespace MoonWorks.Graphics
|
||||||
Size = sizeInBytes;
|
Size = sizeInBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Immediately copies data from a data pointer to the TransferBuffer.
|
|
||||||
///
|
|
||||||
/// If setDataOption is DISCARD and this TransferBuffer was used in an Upload command,
|
|
||||||
/// that command will still use the correct data at the cost of increased memory usage.
|
|
||||||
///
|
|
||||||
/// If setDataOption is OVERWRITE and this TransferBuffer was used in an Upload command,
|
|
||||||
/// this could cause a data race.
|
|
||||||
/// </summary>
|
|
||||||
public unsafe void SetData(
|
|
||||||
byte* dataPtr,
|
|
||||||
in BufferCopy copyParams,
|
|
||||||
SetDataOptions setDataOption
|
|
||||||
) {
|
|
||||||
Refresh.Refresh_SetData(
|
|
||||||
Device.Handle,
|
|
||||||
(nint) dataPtr,
|
|
||||||
Handle,
|
|
||||||
copyParams.ToRefresh(),
|
|
||||||
(Refresh.SetDataOptions) setDataOption
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Immediately copies data from a Span to the TransferBuffer.
|
/// Immediately copies data from a Span to the TransferBuffer.
|
||||||
/// Returns the length of the copy in bytes.
|
/// Returns the length of the copy in bytes.
|
||||||
|
@ -90,12 +67,23 @@ namespace MoonWorks.Graphics
|
||||||
var elementSize = Marshal.SizeOf<T>();
|
var elementSize = Marshal.SizeOf<T>();
|
||||||
var dataLengthInBytes = (uint) (elementSize * data.Length);
|
var dataLengthInBytes = (uint) (elementSize * data.Length);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
AssertBufferBoundsCheck(Size, bufferOffsetInBytes, dataLengthInBytes);
|
||||||
|
#endif
|
||||||
|
|
||||||
fixed (T* dataPtr = data)
|
fixed (T* dataPtr = data)
|
||||||
{
|
{
|
||||||
SetData(
|
Refresh.Refresh_SetData(
|
||||||
(byte*) dataPtr,
|
Device.Handle,
|
||||||
new BufferCopy(0, bufferOffsetInBytes, dataLengthInBytes),
|
(nint) dataPtr,
|
||||||
setDataOption
|
Handle,
|
||||||
|
new Refresh.BufferCopy
|
||||||
|
{
|
||||||
|
srcOffset = 0,
|
||||||
|
dstOffset = bufferOffsetInBytes,
|
||||||
|
size = dataLengthInBytes
|
||||||
|
},
|
||||||
|
(Refresh.SetDataOptions) setDataOption
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,21 +108,6 @@ namespace MoonWorks.Graphics
|
||||||
return SetData(data, 0, setDataOption);
|
return SetData(data, 0, setDataOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Immediately copies data from the TransferBuffer into a data pointer.
|
|
||||||
/// </summary>
|
|
||||||
public unsafe void GetData(
|
|
||||||
byte* dataPtr,
|
|
||||||
in BufferCopy copyParams
|
|
||||||
) {
|
|
||||||
Refresh.Refresh_GetData(
|
|
||||||
Device.Handle,
|
|
||||||
Handle,
|
|
||||||
(nint) dataPtr,
|
|
||||||
copyParams.ToRefresh()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Immediately copies data from the TransferBuffer into a Span.
|
/// Immediately copies data from the TransferBuffer into a Span.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -146,13 +119,34 @@ namespace MoonWorks.Graphics
|
||||||
var elementSize = Marshal.SizeOf<T>();
|
var elementSize = Marshal.SizeOf<T>();
|
||||||
var dataLengthInBytes = (uint) (elementSize * data.Length);
|
var dataLengthInBytes = (uint) (elementSize * data.Length);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
AssertBufferBoundsCheck(Size, bufferOffsetInBytes, dataLengthInBytes);
|
||||||
|
#endif
|
||||||
|
|
||||||
fixed (T* dataPtr = data)
|
fixed (T* dataPtr = data)
|
||||||
{
|
{
|
||||||
GetData(
|
Refresh.Refresh_GetData(
|
||||||
(byte*) dataPtr,
|
Device.Handle,
|
||||||
new BufferCopy(bufferOffsetInBytes, 0, dataLengthInBytes)
|
Handle,
|
||||||
|
(nint) dataPtr,
|
||||||
|
new Refresh.BufferCopy
|
||||||
|
{
|
||||||
|
srcOffset = bufferOffsetInBytes,
|
||||||
|
dstOffset = 0,
|
||||||
|
size = dataLengthInBytes
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
private void AssertBufferBoundsCheck(uint bufferLengthInBytes, uint offsetInBytes, uint copyLengthInBytes)
|
||||||
|
{
|
||||||
|
if (copyLengthInBytes > bufferLengthInBytes + offsetInBytes)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"SetData overflow! Transfer buffer length {bufferLengthInBytes}, offset {offsetInBytes}, copy length {copyLengthInBytes}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue