rename CpuBuffer to TransferBuffer
parent
39496c37ea
commit
8648eef5d1
|
@ -1 +1 @@
|
|||
Subproject commit ad0b168c4794ee0377c825b0149a0d21bd856e43
|
||||
Subproject commit 2e346d84016fb7b26dbe7c5b6c485109571c30f4
|
|
@ -1888,7 +1888,7 @@ namespace MoonWorks.Graphics
|
|||
/// You MAY assume that the copy has finished for subsequent commands.
|
||||
/// </summary>
|
||||
public void UploadToTexture(
|
||||
CpuBuffer cpuBuffer,
|
||||
TransferBuffer cpuBuffer,
|
||||
in TextureSlice textureSlice,
|
||||
in BufferImageCopy copyParams
|
||||
)
|
||||
|
@ -1911,7 +1911,7 @@ namespace MoonWorks.Graphics
|
|||
/// Uploads the contents of an entire buffer to a texture with no mips.
|
||||
/// </summary>
|
||||
public void UploadToTexture(
|
||||
CpuBuffer cpuBuffer,
|
||||
TransferBuffer cpuBuffer,
|
||||
Texture texture
|
||||
) {
|
||||
UploadToTexture(
|
||||
|
@ -1931,7 +1931,7 @@ namespace MoonWorks.Graphics
|
|||
/// You MAY assume that the copy has finished for subsequent commands.
|
||||
/// </summary>
|
||||
public void UploadToBuffer(
|
||||
CpuBuffer cpuBuffer,
|
||||
TransferBuffer cpuBuffer,
|
||||
GpuBuffer gpuBuffer,
|
||||
in BufferCopy copyParams
|
||||
) {
|
||||
|
@ -1953,7 +1953,7 @@ namespace MoonWorks.Graphics
|
|||
/// Copies the entire contents of a CpuBuffer to a GpuBuffer.
|
||||
/// </summary>
|
||||
public void UploadToBuffer(
|
||||
CpuBuffer cpuBuffer,
|
||||
TransferBuffer cpuBuffer,
|
||||
GpuBuffer gpuBuffer
|
||||
) {
|
||||
#if DEBUG
|
||||
|
@ -1978,7 +1978,7 @@ namespace MoonWorks.Graphics
|
|||
/// </summary>
|
||||
public void DownloadFromTexture(
|
||||
in TextureSlice textureSlice,
|
||||
CpuBuffer cpuBuffer,
|
||||
TransferBuffer cpuBuffer,
|
||||
in BufferImageCopy copyParams
|
||||
) {
|
||||
#if DEBUG
|
||||
|
@ -2000,7 +2000,7 @@ namespace MoonWorks.Graphics
|
|||
/// </summary>
|
||||
public void DownloadFromTexture(
|
||||
Texture texture,
|
||||
CpuBuffer cpuBuffer
|
||||
TransferBuffer cpuBuffer
|
||||
) {
|
||||
DownloadFromTexture(
|
||||
new TextureSlice(texture),
|
||||
|
@ -2018,7 +2018,7 @@ namespace MoonWorks.Graphics
|
|||
/// </summary>
|
||||
public void DownloadFromBuffer(
|
||||
GpuBuffer gpuBuffer,
|
||||
CpuBuffer cpuBuffer,
|
||||
TransferBuffer cpuBuffer,
|
||||
in BufferCopy copyParams
|
||||
) {
|
||||
#if DEBUG
|
||||
|
|
|
@ -51,8 +51,8 @@ namespace MoonWorks.Graphics.Font
|
|||
ImageUtils.ImageInfoFromFile(imagePath, out var width, out var height, out var sizeInBytes);
|
||||
var texture = Texture.CreateTexture2D(graphicsDevice, width, height, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
|
||||
|
||||
var cpuBuffer = new CpuBuffer(graphicsDevice, sizeInBytes);
|
||||
ImageUtils.DecodeIntoCpuBuffer(
|
||||
var cpuBuffer = new TransferBuffer(graphicsDevice, sizeInBytes);
|
||||
ImageUtils.DecodeIntoTransferBuffer(
|
||||
imagePath,
|
||||
cpuBuffer,
|
||||
0,
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace MoonWorks.Graphics.Font
|
|||
public GpuBuffer IndexBuffer { get; protected set; } = null;
|
||||
public uint PrimitiveCount { get; protected set; }
|
||||
|
||||
private CpuBuffer TransferBuffer;
|
||||
private TransferBuffer TransferBuffer;
|
||||
|
||||
public Font CurrentFont { get; private set; }
|
||||
|
||||
|
@ -35,7 +35,7 @@ namespace MoonWorks.Graphics.Font
|
|||
VertexBuffer = GpuBuffer.Create<Vertex>(GraphicsDevice, BufferUsageFlags.Vertex, INITIAL_VERTEX_COUNT);
|
||||
IndexBuffer = GpuBuffer.Create<uint>(GraphicsDevice, BufferUsageFlags.Index, INITIAL_INDEX_COUNT);
|
||||
|
||||
TransferBuffer = CpuBuffer.Create<byte>(GraphicsDevice, VertexBuffer.Size + IndexBuffer.Size);
|
||||
TransferBuffer = TransferBuffer.Create<byte>(GraphicsDevice, VertexBuffer.Size + IndexBuffer.Size);
|
||||
}
|
||||
|
||||
// Call this to initialize or reset the batch.
|
||||
|
@ -119,7 +119,7 @@ namespace MoonWorks.Graphics.Font
|
|||
if (newTransferBufferNeeded)
|
||||
{
|
||||
TransferBuffer.Dispose();
|
||||
TransferBuffer = new CpuBuffer(GraphicsDevice, VertexBuffer.Size + IndexBuffer.Size);
|
||||
TransferBuffer = new TransferBuffer(GraphicsDevice, VertexBuffer.Size + IndexBuffer.Size);
|
||||
}
|
||||
|
||||
if (vertexDataLengthInBytes > 0 && indexDataLengthInBytes > 0)
|
||||
|
|
|
@ -146,56 +146,56 @@ namespace MoonWorks.Graphics
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes image data into a CpuBuffer to prepare for image upload.
|
||||
/// Decodes image data into a TransferBuffer to prepare for image upload.
|
||||
/// </summary>
|
||||
public static unsafe uint DecodeIntoCpuBuffer(
|
||||
public static unsafe uint DecodeIntoTransferBuffer(
|
||||
Span<byte> data,
|
||||
CpuBuffer cpuBuffer,
|
||||
TransferBuffer transferBuffer,
|
||||
uint bufferOffsetInBytes,
|
||||
SetDataOptions option
|
||||
) {
|
||||
var pixelData = GetPixelDataFromBytes(data, out var w, out var h, out var sizeInBytes);
|
||||
var length = cpuBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
||||
var length = transferBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
||||
FreePixelData(pixelData);
|
||||
return length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes an image stream into a CpuBuffer to prepare for image upload.
|
||||
/// Decodes an image stream into a TransferBuffer to prepare for image upload.
|
||||
/// </summary>
|
||||
public static unsafe uint DecodeIntoCpuBuffer(
|
||||
public static unsafe uint DecodeIntoTransferBuffer(
|
||||
Stream stream,
|
||||
CpuBuffer cpuBuffer,
|
||||
TransferBuffer transferBuffer,
|
||||
uint bufferOffsetInBytes,
|
||||
SetDataOptions option
|
||||
) {
|
||||
var pixelData = GetPixelDataFromStream(stream, out var w, out var h, out var sizeInBytes);
|
||||
var length = cpuBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
||||
var length = transferBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
||||
FreePixelData(pixelData);
|
||||
return length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes an image file into a CpuBuffer to prepare for image upload.
|
||||
/// Decodes an image file into a TransferBuffer to prepare for image upload.
|
||||
/// </summary>
|
||||
public static unsafe uint DecodeIntoCpuBuffer(
|
||||
public static unsafe uint DecodeIntoTransferBuffer(
|
||||
string path,
|
||||
CpuBuffer cpuBuffer,
|
||||
TransferBuffer transferBuffer,
|
||||
uint bufferOffsetInBytes,
|
||||
SetDataOptions option
|
||||
) {
|
||||
var pixelData = GetPixelDataFromFile(path, out var w, out var h, out var sizeInBytes);
|
||||
var length = cpuBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
||||
var length = transferBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
||||
FreePixelData(pixelData);
|
||||
return length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves pixel data contained in a CpuBuffer to a PNG file.
|
||||
/// Saves pixel data contained in a TransferBuffer to a PNG file.
|
||||
/// </summary>
|
||||
public static unsafe void SavePNG(
|
||||
string path,
|
||||
CpuBuffer cpuBuffer,
|
||||
TransferBuffer transferBuffer,
|
||||
uint bufferOffsetInBytes,
|
||||
int width,
|
||||
int height,
|
||||
|
@ -206,7 +206,7 @@ namespace MoonWorks.Graphics
|
|||
var pixelsPtr = NativeMemory.Alloc((nuint) sizeInBytes);
|
||||
var pixelsSpan = new Span<byte>(pixelsPtr, sizeInBytes);
|
||||
|
||||
cpuBuffer.GetData(pixelsSpan, bufferOffsetInBytes);
|
||||
transferBuffer.GetData(pixelsSpan, bufferOffsetInBytes);
|
||||
|
||||
if (bgra)
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace MoonWorks.Graphics
|
|||
/// </summary>
|
||||
public unsafe class ResourceInitializer : GraphicsResource
|
||||
{
|
||||
CpuBuffer TransferBuffer;
|
||||
TransferBuffer TransferBuffer;
|
||||
|
||||
byte* data;
|
||||
uint dataOffset = 0;
|
||||
|
@ -96,7 +96,7 @@ namespace MoonWorks.Graphics
|
|||
if (TransferBuffer == null || TransferBuffer.Size < dataSize)
|
||||
{
|
||||
TransferBuffer?.Dispose();
|
||||
TransferBuffer = new CpuBuffer(Device, dataSize);
|
||||
TransferBuffer = new TransferBuffer(Device, dataSize);
|
||||
}
|
||||
|
||||
TransferBuffer.SetData(data, new BufferCopy(0, 0, dataSize), SetDataOptions.Discard);
|
||||
|
|
|
@ -4,9 +4,9 @@ using RefreshCS;
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public unsafe class CpuBuffer : RefreshResource
|
||||
public unsafe class TransferBuffer : RefreshResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyCpuBuffer;
|
||||
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTransferBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// Size in bytes.
|
||||
|
@ -20,28 +20,28 @@ namespace MoonWorks.Graphics
|
|||
/// <param name="device">The GraphicsDevice.</param>
|
||||
/// <param name="elementCount">How many elements of type T the buffer will contain.</param>
|
||||
/// <returns></returns>
|
||||
public unsafe static CpuBuffer Create<T>(
|
||||
public unsafe static TransferBuffer Create<T>(
|
||||
GraphicsDevice device,
|
||||
uint elementCount
|
||||
) where T : unmanaged
|
||||
{
|
||||
return new CpuBuffer(
|
||||
return new TransferBuffer(
|
||||
device,
|
||||
(uint) Marshal.SizeOf<T>() * elementCount
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a CpuBuffer.
|
||||
/// Creates a TransferBuffer.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="sizeInBytes">The length of the buffer. Cannot be resized.</param>
|
||||
public CpuBuffer(
|
||||
public TransferBuffer(
|
||||
GraphicsDevice device,
|
||||
uint sizeInBytes
|
||||
) : base(device)
|
||||
{
|
||||
Handle = Refresh.Refresh_CreateCpuBuffer(
|
||||
Handle = Refresh.Refresh_CreateTransferBuffer(
|
||||
device.Handle,
|
||||
sizeInBytes
|
||||
);
|
||||
|
@ -49,12 +49,12 @@ namespace MoonWorks.Graphics
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Immediately copies data from a data pointer to the CpuBuffer.
|
||||
/// Immediately copies data from a data pointer to the TransferBuffer.
|
||||
///
|
||||
/// If setDataOption is DISCARD and this CpuBuffer was used in an Upload command,
|
||||
/// 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 CpuBuffer was used in an Upload command,
|
||||
/// If setDataOption is OVERWRITE and this TransferBuffer was used in an Upload command,
|
||||
/// this could cause a data race.
|
||||
/// </summary>
|
||||
public unsafe void SetData(
|
||||
|
@ -72,13 +72,13 @@ namespace MoonWorks.Graphics
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Immediately copies data from a Span to the CpuBuffer.
|
||||
/// Immediately copies data from a Span to the TransferBuffer.
|
||||
/// Returns the length of the copy in bytes.
|
||||
///
|
||||
/// If setDataOption is DISCARD and this CpuBuffer was used in an Upload command,
|
||||
/// 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 CpuBuffer was used in an Upload command,
|
||||
/// If setDataOption is OVERWRITE and this TransferBuffer was used in an Upload command,
|
||||
/// the data will be overwritten immediately, which could cause a data race.
|
||||
/// </summary>
|
||||
public unsafe uint SetData<T>(
|
||||
|
@ -103,13 +103,13 @@ namespace MoonWorks.Graphics
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Immediately copies data from a Span to the CpuBuffer.
|
||||
/// Immediately copies data from a Span to the TransferBuffer.
|
||||
/// Returns the length of the copy in bytes.
|
||||
///
|
||||
/// If setDataOption is DISCARD and this CpuBuffer was used in an Upload command,
|
||||
/// 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 CpuBuffer was used in an Upload command,
|
||||
/// If setDataOption is OVERWRITE and this TransferBuffer was used in an Upload command,
|
||||
/// the data will be overwritten immediately, which could cause a data race.
|
||||
/// </summary>
|
||||
public unsafe uint SetData<T>(
|
||||
|
@ -121,7 +121,7 @@ namespace MoonWorks.Graphics
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Immediately copies data from the CpuBuffer into a data pointer.
|
||||
/// Immediately copies data from the TransferBuffer into a data pointer.
|
||||
/// </summary>
|
||||
public unsafe void GetData(
|
||||
byte* dataPtr,
|
||||
|
@ -136,7 +136,7 @@ namespace MoonWorks.Graphics
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Immediately copies data from the CpuBuffer into a Span.
|
||||
/// Immediately copies data from the TransferBuffer into a Span.
|
||||
/// </summary>
|
||||
public unsafe void GetData<T>(
|
||||
Span<T> data,
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace MoonWorks.Video
|
|||
private Texture vTexture = null;
|
||||
private Sampler LinearSampler;
|
||||
|
||||
private CpuBuffer TransferBuffer;
|
||||
private TransferBuffer TransferBuffer;
|
||||
|
||||
private int currentFrame;
|
||||
|
||||
|
@ -111,7 +111,7 @@ namespace MoonWorks.Video
|
|||
TransferBuffer.Dispose();
|
||||
}
|
||||
|
||||
TransferBuffer = new CpuBuffer(Device, yTexture.Size + uTexture.Size + vTexture.Size);
|
||||
TransferBuffer = new TransferBuffer(Device, yTexture.Size + uTexture.Size + vTexture.Size);
|
||||
}
|
||||
|
||||
Video = video;
|
||||
|
|
Loading…
Reference in New Issue