From 23b6499479b89bc69fce88df973cac3c4ca529cc Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 11 Mar 2024 10:18:41 -0700 Subject: [PATCH] add WriteOptions.Unsafe --- lib/RefreshCS | 2 +- src/Graphics/Font/TextBatch.cs | 2 +- src/Graphics/RefreshEnums.cs | 5 +++-- src/Graphics/ResourceUploader.cs | 8 ++++---- src/Video/VideoPlayer.cs | 4 ++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/RefreshCS b/lib/RefreshCS index 8f42783..1bf28f4 160000 --- a/lib/RefreshCS +++ b/lib/RefreshCS @@ -1 +1 @@ -Subproject commit 8f42783fd15cfea57cfae421fd6ab36070df9946 +Subproject commit 1bf28f4397d1a8bc19a75d608f4022541af2080d diff --git a/src/Graphics/Font/TextBatch.cs b/src/Graphics/Font/TextBatch.cs index 8e20c6e..e6cfe0c 100644 --- a/src/Graphics/Font/TextBatch.cs +++ b/src/Graphics/Font/TextBatch.cs @@ -125,7 +125,7 @@ namespace MoonWorks.Graphics.Font if (vertexDataLengthInBytes > 0 && indexDataLengthInBytes > 0) { TransferBuffer.SetData(vertexSpan, TransferOptions.Cycle); - TransferBuffer.SetData(indexSpan, (uint) vertexSpan.Length, TransferOptions.Overwrite); + TransferBuffer.SetData(indexSpan, (uint) vertexSpan.Length, TransferOptions.Unsafe); commandBuffer.UploadToBuffer(TransferBuffer, VertexBuffer, new BufferCopy(0, 0, (uint) vertexSpan.Length), WriteOptions.Cycle); commandBuffer.UploadToBuffer(TransferBuffer, IndexBuffer, new BufferCopy((uint) vertexSpan.Length, 0, (uint) indexSpan.Length), WriteOptions.Cycle); diff --git a/src/Graphics/RefreshEnums.cs b/src/Graphics/RefreshEnums.cs index 0139690..0c89560 100644 --- a/src/Graphics/RefreshEnums.cs +++ b/src/Graphics/RefreshEnums.cs @@ -306,13 +306,14 @@ namespace MoonWorks.Graphics public enum TransferOptions { Cycle, - Overwrite + Unsafe } public enum WriteOptions { Cycle, - SafeOverwrite + Unsafe, + Safe } public enum Backend diff --git a/src/Graphics/ResourceUploader.cs b/src/Graphics/ResourceUploader.cs index c56fdac..ecc81e5 100644 --- a/src/Graphics/ResourceUploader.cs +++ b/src/Graphics/ResourceUploader.cs @@ -45,7 +45,7 @@ namespace MoonWorks.Graphics var lengthInBytes = (uint) (Marshal.SizeOf() * data.Length); var gpuBuffer = new GpuBuffer(Device, usageFlags, lengthInBytes); - SetBufferData(gpuBuffer, 0, data, WriteOptions.SafeOverwrite); + SetBufferData(gpuBuffer, 0, data, WriteOptions.Unsafe); return gpuBuffer; } @@ -74,7 +74,7 @@ namespace MoonWorks.Graphics public Texture CreateTexture2D(Span pixelData, uint width, uint height) where T : unmanaged { var texture = Texture.CreateTexture2D(Device, width, height, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler); - SetTextureData(texture, pixelData, WriteOptions.SafeOverwrite); + SetTextureData(texture, pixelData, WriteOptions.Unsafe); return texture; } @@ -164,7 +164,7 @@ namespace MoonWorks.Graphics Depth = 1 }; - SetTextureData(textureRegion, byteSpan, WriteOptions.SafeOverwrite); + SetTextureData(textureRegion, byteSpan, WriteOptions.Unsafe); NativeMemory.Free(byteBuffer); } @@ -187,7 +187,7 @@ namespace MoonWorks.Graphics var pixelData = ImageUtils.GetPixelDataFromBytes(compressedImageData, out var _, out var _, out var sizeInBytes); var pixelSpan = new Span((void*) pixelData, (int) sizeInBytes); - SetTextureData(textureRegion, pixelSpan, WriteOptions.SafeOverwrite); + SetTextureData(textureRegion, pixelSpan, WriteOptions.Unsafe); ImageUtils.FreePixelData(pixelData); } diff --git a/src/Video/VideoPlayer.cs b/src/Video/VideoPlayer.cs index ffebace..cf28976 100644 --- a/src/Video/VideoPlayer.cs +++ b/src/Video/VideoPlayer.cs @@ -244,8 +244,8 @@ namespace MoonWorks.Video TransferBuffer = new TransferBuffer(Device, TransferUsage.Texture, (uint) (ySpan.Length + uSpan.Length + vSpan.Length)); } TransferBuffer.SetData(ySpan, 0, TransferOptions.Cycle); - TransferBuffer.SetData(uSpan, (uint) ySpan.Length, TransferOptions.Overwrite); - TransferBuffer.SetData(vSpan, (uint) (ySpan.Length + uSpan.Length), TransferOptions.Overwrite); + TransferBuffer.SetData(uSpan, (uint) ySpan.Length, TransferOptions.Unsafe); + TransferBuffer.SetData(vSpan, (uint) (ySpan.Length + uSpan.Length), TransferOptions.Unsafe); commandBuffer.BeginCopyPass();