diff --git a/lib/RefreshCS b/lib/RefreshCS index ad0b168..2e346d8 160000 --- a/lib/RefreshCS +++ b/lib/RefreshCS @@ -1 +1 @@ -Subproject commit ad0b168c4794ee0377c825b0149a0d21bd856e43 +Subproject commit 2e346d84016fb7b26dbe7c5b6c485109571c30f4 diff --git a/src/Graphics/CommandBuffer.cs b/src/Graphics/CommandBuffer.cs index cf1f534..60e98b5 100644 --- a/src/Graphics/CommandBuffer.cs +++ b/src/Graphics/CommandBuffer.cs @@ -1888,7 +1888,7 @@ namespace MoonWorks.Graphics /// You MAY assume that the copy has finished for subsequent commands. /// 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. /// 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. /// 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. /// public void UploadToBuffer( - CpuBuffer cpuBuffer, + TransferBuffer cpuBuffer, GpuBuffer gpuBuffer ) { #if DEBUG @@ -1978,7 +1978,7 @@ namespace MoonWorks.Graphics /// public void DownloadFromTexture( in TextureSlice textureSlice, - CpuBuffer cpuBuffer, + TransferBuffer cpuBuffer, in BufferImageCopy copyParams ) { #if DEBUG @@ -2000,7 +2000,7 @@ namespace MoonWorks.Graphics /// public void DownloadFromTexture( Texture texture, - CpuBuffer cpuBuffer + TransferBuffer cpuBuffer ) { DownloadFromTexture( new TextureSlice(texture), @@ -2018,7 +2018,7 @@ namespace MoonWorks.Graphics /// public void DownloadFromBuffer( GpuBuffer gpuBuffer, - CpuBuffer cpuBuffer, + TransferBuffer cpuBuffer, in BufferCopy copyParams ) { #if DEBUG diff --git a/src/Graphics/Font/Font.cs b/src/Graphics/Font/Font.cs index 109badb..e9bd7f8 100644 --- a/src/Graphics/Font/Font.cs +++ b/src/Graphics/Font/Font.cs @@ -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, diff --git a/src/Graphics/Font/TextBatch.cs b/src/Graphics/Font/TextBatch.cs index 3dd301b..caf6962 100644 --- a/src/Graphics/Font/TextBatch.cs +++ b/src/Graphics/Font/TextBatch.cs @@ -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(GraphicsDevice, BufferUsageFlags.Vertex, INITIAL_VERTEX_COUNT); IndexBuffer = GpuBuffer.Create(GraphicsDevice, BufferUsageFlags.Index, INITIAL_INDEX_COUNT); - TransferBuffer = CpuBuffer.Create(GraphicsDevice, VertexBuffer.Size + IndexBuffer.Size); + TransferBuffer = TransferBuffer.Create(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) diff --git a/src/Graphics/ImageUtils.cs b/src/Graphics/ImageUtils.cs index 8d108bf..de6f2f4 100644 --- a/src/Graphics/ImageUtils.cs +++ b/src/Graphics/ImageUtils.cs @@ -146,56 +146,56 @@ namespace MoonWorks.Graphics } /// - /// Decodes image data into a CpuBuffer to prepare for image upload. + /// Decodes image data into a TransferBuffer to prepare for image upload. /// - public static unsafe uint DecodeIntoCpuBuffer( + public static unsafe uint DecodeIntoTransferBuffer( Span 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((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option); + var length = transferBuffer.SetData(new Span((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option); FreePixelData(pixelData); return length; } /// - /// Decodes an image stream into a CpuBuffer to prepare for image upload. + /// Decodes an image stream into a TransferBuffer to prepare for image upload. /// - 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((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option); + var length = transferBuffer.SetData(new Span((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option); FreePixelData(pixelData); return length; } /// - /// Decodes an image file into a CpuBuffer to prepare for image upload. + /// Decodes an image file into a TransferBuffer to prepare for image upload. /// - 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((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option); + var length = transferBuffer.SetData(new Span((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option); FreePixelData(pixelData); return length; } /// - /// Saves pixel data contained in a CpuBuffer to a PNG file. + /// Saves pixel data contained in a TransferBuffer to a PNG file. /// 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(pixelsPtr, sizeInBytes); - cpuBuffer.GetData(pixelsSpan, bufferOffsetInBytes); + transferBuffer.GetData(pixelsSpan, bufferOffsetInBytes); if (bgra) { diff --git a/src/Graphics/ResourceInitializer.cs b/src/Graphics/ResourceInitializer.cs index 31298a5..027ddbd 100644 --- a/src/Graphics/ResourceInitializer.cs +++ b/src/Graphics/ResourceInitializer.cs @@ -12,7 +12,7 @@ namespace MoonWorks.Graphics /// 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); diff --git a/src/Graphics/Resources/CpuBuffer.cs b/src/Graphics/Resources/CpuBuffer.cs index 3988ff7..b8f75ab 100644 --- a/src/Graphics/Resources/CpuBuffer.cs +++ b/src/Graphics/Resources/CpuBuffer.cs @@ -4,9 +4,9 @@ using RefreshCS; namespace MoonWorks.Graphics { - public unsafe class CpuBuffer : RefreshResource + public unsafe class TransferBuffer : RefreshResource { - protected override Action QueueDestroyFunction => Refresh.Refresh_QueueDestroyCpuBuffer; + protected override Action QueueDestroyFunction => Refresh.Refresh_QueueDestroyTransferBuffer; /// /// Size in bytes. @@ -20,28 +20,28 @@ namespace MoonWorks.Graphics /// The GraphicsDevice. /// How many elements of type T the buffer will contain. /// - public unsafe static CpuBuffer Create( + public unsafe static TransferBuffer Create( GraphicsDevice device, uint elementCount ) where T : unmanaged { - return new CpuBuffer( + return new TransferBuffer( device, (uint) Marshal.SizeOf() * elementCount ); } /// - /// Creates a CpuBuffer. + /// Creates a TransferBuffer. /// /// An initialized GraphicsDevice. /// The length of the buffer. Cannot be resized. - 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 } /// - /// 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. /// public unsafe void SetData( @@ -72,13 +72,13 @@ namespace MoonWorks.Graphics } /// - /// 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. /// public unsafe uint SetData( @@ -103,13 +103,13 @@ namespace MoonWorks.Graphics } /// - /// 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. /// public unsafe uint SetData( @@ -121,7 +121,7 @@ namespace MoonWorks.Graphics } /// - /// Immediately copies data from the CpuBuffer into a data pointer. + /// Immediately copies data from the TransferBuffer into a data pointer. /// public unsafe void GetData( byte* dataPtr, @@ -136,7 +136,7 @@ namespace MoonWorks.Graphics } /// - /// Immediately copies data from the CpuBuffer into a Span. + /// Immediately copies data from the TransferBuffer into a Span. /// public unsafe void GetData( Span data, diff --git a/src/Video/VideoPlayer.cs b/src/Video/VideoPlayer.cs index f2c83bb..381b49e 100644 --- a/src/Video/VideoPlayer.cs +++ b/src/Video/VideoPlayer.cs @@ -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;