rename CpuBuffer to TransferBuffer

what_if_no_video_threads
cosmonaut 2024-02-23 09:56:00 -08:00
parent 39496c37ea
commit 8648eef5d1
8 changed files with 50 additions and 50 deletions

@ -1 +1 @@
Subproject commit ad0b168c4794ee0377c825b0149a0d21bd856e43 Subproject commit 2e346d84016fb7b26dbe7c5b6c485109571c30f4

View File

@ -1888,7 +1888,7 @@ namespace MoonWorks.Graphics
/// You MAY assume that the copy has finished for subsequent commands. /// You MAY assume that the copy has finished for subsequent commands.
/// </summary> /// </summary>
public void UploadToTexture( public void UploadToTexture(
CpuBuffer cpuBuffer, TransferBuffer cpuBuffer,
in TextureSlice textureSlice, in TextureSlice textureSlice,
in BufferImageCopy copyParams in BufferImageCopy copyParams
) )
@ -1911,7 +1911,7 @@ namespace MoonWorks.Graphics
/// Uploads the contents of an entire buffer to a texture with no mips. /// Uploads the contents of an entire buffer to a texture with no mips.
/// </summary> /// </summary>
public void UploadToTexture( public void UploadToTexture(
CpuBuffer cpuBuffer, TransferBuffer cpuBuffer,
Texture texture Texture texture
) { ) {
UploadToTexture( UploadToTexture(
@ -1931,7 +1931,7 @@ namespace MoonWorks.Graphics
/// You MAY assume that the copy has finished for subsequent commands. /// You MAY assume that the copy has finished for subsequent commands.
/// </summary> /// </summary>
public void UploadToBuffer( public void UploadToBuffer(
CpuBuffer cpuBuffer, TransferBuffer cpuBuffer,
GpuBuffer gpuBuffer, GpuBuffer gpuBuffer,
in BufferCopy copyParams in BufferCopy copyParams
) { ) {
@ -1953,7 +1953,7 @@ namespace MoonWorks.Graphics
/// Copies the entire contents of a CpuBuffer to a GpuBuffer. /// Copies the entire contents of a CpuBuffer to a GpuBuffer.
/// </summary> /// </summary>
public void UploadToBuffer( public void UploadToBuffer(
CpuBuffer cpuBuffer, TransferBuffer cpuBuffer,
GpuBuffer gpuBuffer GpuBuffer gpuBuffer
) { ) {
#if DEBUG #if DEBUG
@ -1978,7 +1978,7 @@ namespace MoonWorks.Graphics
/// </summary> /// </summary>
public void DownloadFromTexture( public void DownloadFromTexture(
in TextureSlice textureSlice, in TextureSlice textureSlice,
CpuBuffer cpuBuffer, TransferBuffer cpuBuffer,
in BufferImageCopy copyParams in BufferImageCopy copyParams
) { ) {
#if DEBUG #if DEBUG
@ -2000,7 +2000,7 @@ namespace MoonWorks.Graphics
/// </summary> /// </summary>
public void DownloadFromTexture( public void DownloadFromTexture(
Texture texture, Texture texture,
CpuBuffer cpuBuffer TransferBuffer cpuBuffer
) { ) {
DownloadFromTexture( DownloadFromTexture(
new TextureSlice(texture), new TextureSlice(texture),
@ -2018,7 +2018,7 @@ namespace MoonWorks.Graphics
/// </summary> /// </summary>
public void DownloadFromBuffer( public void DownloadFromBuffer(
GpuBuffer gpuBuffer, GpuBuffer gpuBuffer,
CpuBuffer cpuBuffer, TransferBuffer cpuBuffer,
in BufferCopy copyParams in BufferCopy copyParams
) { ) {
#if DEBUG #if DEBUG

View File

@ -51,8 +51,8 @@ namespace MoonWorks.Graphics.Font
ImageUtils.ImageInfoFromFile(imagePath, out var width, out var height, out var sizeInBytes); ImageUtils.ImageInfoFromFile(imagePath, out var width, out var height, out var sizeInBytes);
var texture = Texture.CreateTexture2D(graphicsDevice, width, height, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler); var texture = Texture.CreateTexture2D(graphicsDevice, width, height, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
var cpuBuffer = new CpuBuffer(graphicsDevice, sizeInBytes); var cpuBuffer = new TransferBuffer(graphicsDevice, sizeInBytes);
ImageUtils.DecodeIntoCpuBuffer( ImageUtils.DecodeIntoTransferBuffer(
imagePath, imagePath,
cpuBuffer, cpuBuffer,
0, 0,

View File

@ -17,7 +17,7 @@ namespace MoonWorks.Graphics.Font
public GpuBuffer IndexBuffer { get; protected set; } = null; public GpuBuffer IndexBuffer { get; protected set; } = null;
public uint PrimitiveCount { get; protected set; } public uint PrimitiveCount { get; protected set; }
private CpuBuffer TransferBuffer; private TransferBuffer TransferBuffer;
public Font CurrentFont { get; private set; } public Font CurrentFont { get; private set; }
@ -35,7 +35,7 @@ namespace MoonWorks.Graphics.Font
VertexBuffer = GpuBuffer.Create<Vertex>(GraphicsDevice, BufferUsageFlags.Vertex, INITIAL_VERTEX_COUNT); VertexBuffer = GpuBuffer.Create<Vertex>(GraphicsDevice, BufferUsageFlags.Vertex, INITIAL_VERTEX_COUNT);
IndexBuffer = GpuBuffer.Create<uint>(GraphicsDevice, BufferUsageFlags.Index, INITIAL_INDEX_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. // Call this to initialize or reset the batch.
@ -119,7 +119,7 @@ namespace MoonWorks.Graphics.Font
if (newTransferBufferNeeded) if (newTransferBufferNeeded)
{ {
TransferBuffer.Dispose(); TransferBuffer.Dispose();
TransferBuffer = new CpuBuffer(GraphicsDevice, VertexBuffer.Size + IndexBuffer.Size); TransferBuffer = new TransferBuffer(GraphicsDevice, VertexBuffer.Size + IndexBuffer.Size);
} }
if (vertexDataLengthInBytes > 0 && indexDataLengthInBytes > 0) if (vertexDataLengthInBytes > 0 && indexDataLengthInBytes > 0)

View File

@ -146,56 +146,56 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Decodes image data into a CpuBuffer to prepare for image upload. /// Decodes image data into a TransferBuffer to prepare for image upload.
/// </summary> /// </summary>
public static unsafe uint DecodeIntoCpuBuffer( public static unsafe uint DecodeIntoTransferBuffer(
Span<byte> data, Span<byte> data,
CpuBuffer cpuBuffer, TransferBuffer transferBuffer,
uint bufferOffsetInBytes, uint bufferOffsetInBytes,
SetDataOptions option SetDataOptions option
) { ) {
var pixelData = GetPixelDataFromBytes(data, out var w, out var h, out var sizeInBytes); 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); FreePixelData(pixelData);
return length; return length;
} }
/// <summary> /// <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> /// </summary>
public static unsafe uint DecodeIntoCpuBuffer( public static unsafe uint DecodeIntoTransferBuffer(
Stream stream, Stream stream,
CpuBuffer cpuBuffer, TransferBuffer transferBuffer,
uint bufferOffsetInBytes, uint bufferOffsetInBytes,
SetDataOptions option SetDataOptions option
) { ) {
var pixelData = GetPixelDataFromStream(stream, out var w, out var h, out var sizeInBytes); 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); FreePixelData(pixelData);
return length; return length;
} }
/// <summary> /// <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> /// </summary>
public static unsafe uint DecodeIntoCpuBuffer( public static unsafe uint DecodeIntoTransferBuffer(
string path, string path,
CpuBuffer cpuBuffer, TransferBuffer transferBuffer,
uint bufferOffsetInBytes, uint bufferOffsetInBytes,
SetDataOptions option SetDataOptions option
) { ) {
var pixelData = GetPixelDataFromFile(path, out var w, out var h, out var sizeInBytes); 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); FreePixelData(pixelData);
return length; return length;
} }
/// <summary> /// <summary>
/// Saves pixel data contained in a CpuBuffer to a PNG file. /// Saves pixel data contained in a TransferBuffer to a PNG file.
/// </summary> /// </summary>
public static unsafe void SavePNG( public static unsafe void SavePNG(
string path, string path,
CpuBuffer cpuBuffer, TransferBuffer transferBuffer,
uint bufferOffsetInBytes, uint bufferOffsetInBytes,
int width, int width,
int height, int height,
@ -206,7 +206,7 @@ namespace MoonWorks.Graphics
var pixelsPtr = NativeMemory.Alloc((nuint) sizeInBytes); var pixelsPtr = NativeMemory.Alloc((nuint) sizeInBytes);
var pixelsSpan = new Span<byte>(pixelsPtr, sizeInBytes); var pixelsSpan = new Span<byte>(pixelsPtr, sizeInBytes);
cpuBuffer.GetData(pixelsSpan, bufferOffsetInBytes); transferBuffer.GetData(pixelsSpan, bufferOffsetInBytes);
if (bgra) if (bgra)
{ {

View File

@ -12,7 +12,7 @@ namespace MoonWorks.Graphics
/// </summary> /// </summary>
public unsafe class ResourceInitializer : GraphicsResource public unsafe class ResourceInitializer : GraphicsResource
{ {
CpuBuffer TransferBuffer; TransferBuffer TransferBuffer;
byte* data; byte* data;
uint dataOffset = 0; uint dataOffset = 0;
@ -96,7 +96,7 @@ namespace MoonWorks.Graphics
if (TransferBuffer == null || TransferBuffer.Size < dataSize) if (TransferBuffer == null || TransferBuffer.Size < dataSize)
{ {
TransferBuffer?.Dispose(); TransferBuffer?.Dispose();
TransferBuffer = new CpuBuffer(Device, dataSize); TransferBuffer = new TransferBuffer(Device, dataSize);
} }
TransferBuffer.SetData(data, new BufferCopy(0, 0, dataSize), SetDataOptions.Discard); TransferBuffer.SetData(data, new BufferCopy(0, 0, dataSize), SetDataOptions.Discard);

View File

@ -4,9 +4,9 @@ using RefreshCS;
namespace MoonWorks.Graphics 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> /// <summary>
/// Size in bytes. /// Size in bytes.
@ -20,28 +20,28 @@ namespace MoonWorks.Graphics
/// <param name="device">The GraphicsDevice.</param> /// <param name="device">The GraphicsDevice.</param>
/// <param name="elementCount">How many elements of type T the buffer will contain.</param> /// <param name="elementCount">How many elements of type T the buffer will contain.</param>
/// <returns></returns> /// <returns></returns>
public unsafe static CpuBuffer Create<T>( public unsafe static TransferBuffer Create<T>(
GraphicsDevice device, GraphicsDevice device,
uint elementCount uint elementCount
) where T : unmanaged ) where T : unmanaged
{ {
return new CpuBuffer( return new TransferBuffer(
device, device,
(uint) Marshal.SizeOf<T>() * elementCount (uint) Marshal.SizeOf<T>() * elementCount
); );
} }
/// <summary> /// <summary>
/// Creates a CpuBuffer. /// Creates a TransferBuffer.
/// </summary> /// </summary>
/// <param name="device">An initialized GraphicsDevice.</param> /// <param name="device">An initialized GraphicsDevice.</param>
/// <param name="sizeInBytes">The length of the buffer. Cannot be resized.</param> /// <param name="sizeInBytes">The length of the buffer. Cannot be resized.</param>
public CpuBuffer( public TransferBuffer(
GraphicsDevice device, GraphicsDevice device,
uint sizeInBytes uint sizeInBytes
) : base(device) ) : base(device)
{ {
Handle = Refresh.Refresh_CreateCpuBuffer( Handle = Refresh.Refresh_CreateTransferBuffer(
device.Handle, device.Handle,
sizeInBytes sizeInBytes
); );
@ -49,12 +49,12 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <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. /// 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. /// this could cause a data race.
/// </summary> /// </summary>
public unsafe void SetData( public unsafe void SetData(
@ -72,13 +72,13 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <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. /// 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. /// 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. /// the data will be overwritten immediately, which could cause a data race.
/// </summary> /// </summary>
public unsafe uint SetData<T>( public unsafe uint SetData<T>(
@ -103,13 +103,13 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <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. /// 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. /// 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. /// the data will be overwritten immediately, which could cause a data race.
/// </summary> /// </summary>
public unsafe uint SetData<T>( public unsafe uint SetData<T>(
@ -121,7 +121,7 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Immediately copies data from the CpuBuffer into a data pointer. /// Immediately copies data from the TransferBuffer into a data pointer.
/// </summary> /// </summary>
public unsafe void GetData( public unsafe void GetData(
byte* dataPtr, byte* dataPtr,
@ -136,7 +136,7 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Immediately copies data from the CpuBuffer into a Span. /// Immediately copies data from the TransferBuffer into a Span.
/// </summary> /// </summary>
public unsafe void GetData<T>( public unsafe void GetData<T>(
Span<T> data, Span<T> data,

View File

@ -28,7 +28,7 @@ namespace MoonWorks.Video
private Texture vTexture = null; private Texture vTexture = null;
private Sampler LinearSampler; private Sampler LinearSampler;
private CpuBuffer TransferBuffer; private TransferBuffer TransferBuffer;
private int currentFrame; private int currentFrame;
@ -111,7 +111,7 @@ namespace MoonWorks.Video
TransferBuffer.Dispose(); TransferBuffer.Dispose();
} }
TransferBuffer = new CpuBuffer(Device, yTexture.Size + uTexture.Size + vTexture.Size); TransferBuffer = new TransferBuffer(Device, yTexture.Size + uTexture.Size + vTexture.Size);
} }
Video = video; Video = video;