add WriteOptions.Unsafe

what_if_no_video_threads
cosmonaut 2024-03-11 10:18:41 -07:00
parent 929d8f5cc9
commit 23b6499479
5 changed files with 11 additions and 10 deletions

@ -1 +1 @@
Subproject commit 8f42783fd15cfea57cfae421fd6ab36070df9946
Subproject commit 1bf28f4397d1a8bc19a75d608f4022541af2080d

View File

@ -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);

View File

@ -306,13 +306,14 @@ namespace MoonWorks.Graphics
public enum TransferOptions
{
Cycle,
Overwrite
Unsafe
}
public enum WriteOptions
{
Cycle,
SafeOverwrite
Unsafe,
Safe
}
public enum Backend

View File

@ -45,7 +45,7 @@ namespace MoonWorks.Graphics
var lengthInBytes = (uint) (Marshal.SizeOf<T>() * 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<T>(Span<T> 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<byte>((void*) pixelData, (int) sizeInBytes);
SetTextureData(textureRegion, pixelSpan, WriteOptions.SafeOverwrite);
SetTextureData(textureRegion, pixelSpan, WriteOptions.Unsafe);
ImageUtils.FreePixelData(pixelData);
}

View File

@ -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();