From cee712105850ac3385cd0091a923438167433f9f Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Sat, 8 Apr 2023 01:22:00 +0200 Subject: Move solution and projects to src --- src/Ryujinx.Graphics.Vulkan/NativeArray.cs | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/Ryujinx.Graphics.Vulkan/NativeArray.cs (limited to 'src/Ryujinx.Graphics.Vulkan/NativeArray.cs') diff --git a/src/Ryujinx.Graphics.Vulkan/NativeArray.cs b/src/Ryujinx.Graphics.Vulkan/NativeArray.cs new file mode 100644 index 00000000..3a851287 --- /dev/null +++ b/src/Ryujinx.Graphics.Vulkan/NativeArray.cs @@ -0,0 +1,48 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace Ryujinx.Graphics.Vulkan +{ + unsafe class NativeArray : IDisposable where T : unmanaged + { + public T* Pointer { get; private set; } + public int Length { get; } + + public ref T this[int index] + { + get => ref Pointer[Checked(index)]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private int Checked(int index) + { + if ((uint)index >= (uint)Length) + { + throw new IndexOutOfRangeException(); + } + + return index; + } + + public NativeArray(int length) + { + Pointer = (T*)Marshal.AllocHGlobal(checked(length * Unsafe.SizeOf())); + Length = length; + } + + public Span AsSpan() + { + return new Span(Pointer, Length); + } + + public void Dispose() + { + if (Pointer != null) + { + Marshal.FreeHGlobal((IntPtr)Pointer); + Pointer = null; + } + } + } +} -- cgit v1.2.3