Port the whole Gpu native methods

With additionnally ported necessary classes in `Mediapipe.Net.Gpu`
to make the types check
This commit is contained in:
Speykious
2022-01-15 13:33:59 +01:00
parent d4f028d52f
commit 84d5fdc5ca
23 changed files with 885 additions and 0 deletions

19
Mediapipe.Net/Gpu/Gl.cs Normal file
View File

@ -0,0 +1,19 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using Mediapipe.Net.Native;
namespace Mediapipe.Net.Gpu
{
public class Gl
{
public const uint GL_TEXTURE_2D = 0x0DE1;
public static void Flush() => UnsafeNativeMethods.glFlush();
public static void ReadPixels(int x, int y, int width, int height, uint glFormat, uint glType, IntPtr pixels)
=> UnsafeNativeMethods.glReadPixels(x, y, width, height, glFormat, glType, pixels);
}
}

View File

@ -0,0 +1,79 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using Mediapipe.Net.Core;
using Mediapipe.Net.Native;
namespace Mediapipe.Net.Gpu
{
public class GlContext : MpResourceHandle
{
private SharedPtrHandle? sharedPtrHandle;
public static GlContext? GetCurrent()
{
UnsafeNativeMethods.mp_GlContext_GetCurrent(out var glContextPtr).Assert();
return glContextPtr == IntPtr.Zero ? null : new GlContext(glContextPtr);
}
public GlContext(IntPtr ptr, bool isOwner = true) : base(isOwner)
{
sharedPtrHandle = new SharedGlContextPtr(ptr, isOwner);
Ptr = sharedPtrHandle.Get();
}
protected override void DisposeManaged()
{
if (sharedPtrHandle != null)
{
sharedPtrHandle.Dispose();
sharedPtrHandle = null;
}
base.DisposeManaged();
}
protected override void DeleteMpPtr()
{
// Do nothing
}
public IntPtr SharedPtr => sharedPtrHandle == null ? IntPtr.Zero : sharedPtrHandle.MpPtr;
// #if LINUX || ANDROID
public IntPtr EglDisplay => SafeNativeMethods.mp_GlContext__egl_display(MpPtr);
public IntPtr EglConfig => SafeNativeMethods.mp_GlContext__egl_config(MpPtr);
public IntPtr EglContext => SafeNativeMethods.mp_GlContext__egl_context(MpPtr);
// #endif
// #if OSX
// NOTE: (from homuler) On macOS, native libs cannot be built with GPU enabled, so it cannot be used actually.
public IntPtr NsglContext => SafeNativeMethods.mp_GlContext__nsgl_context(MpPtr);
// #elif IOS
public IntPtr EaglContext => SafeNativeMethods.mp_GlContext__eagl_context(MpPtr);
// #endif
public bool IsCurrent() => SafeNativeMethods.mp_GlContext__IsCurrent(MpPtr);
public int GlMajorVersion => SafeNativeMethods.mp_GlContext__gl_major_version(MpPtr);
public int GlMinorVersion => SafeNativeMethods.mp_GlContext__gl_minor_version(MpPtr);
public long GlFinishCount => SafeNativeMethods.mp_GlContext__gl_finish_count(MpPtr);
// TODO: Put it in its own file
private class SharedGlContextPtr : SharedPtrHandle
{
public SharedGlContextPtr(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
protected override void DeleteMpPtr() => UnsafeNativeMethods.mp_SharedGlContext__delete(Ptr);
public override IntPtr Get() => SafeNativeMethods.mp_SharedGlContext__get(MpPtr);
public override void Reset() => UnsafeNativeMethods.mp_SharedGlContext__reset(MpPtr);
}
}
}

View File

@ -0,0 +1,70 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using Mediapipe.Net.Core;
using Mediapipe.Net.Native;
namespace Mediapipe.Net.Gpu
{
public class GlSyncPoint : MpResourceHandle
{
private SharedPtrHandle? sharedPtrHandle;
public GlSyncPoint(IntPtr ptr) : base(ptr)
{
sharedPtrHandle = new SharedGlSyncPointPtr(ptr);
Ptr = sharedPtrHandle.Get();
}
protected override void DisposeManaged()
{
if (sharedPtrHandle != null)
{
sharedPtrHandle.Dispose();
sharedPtrHandle = null;
}
base.DisposeManaged();
}
protected override void DeleteMpPtr()
{
// Do nothing
}
public IntPtr SharedPtr => sharedPtrHandle == null ? IntPtr.Zero : sharedPtrHandle.MpPtr;
public void Wait() => UnsafeNativeMethods.mp_GlSyncPoint__Wait(MpPtr).Assert();
public void WaitOnGpu() => UnsafeNativeMethods.mp_GlSyncPoint__WaitOnGpu(MpPtr).Assert();
public bool IsReady()
{
UnsafeNativeMethods.mp_GlSyncPoint__IsReady(MpPtr, out var value).Assert();
GC.KeepAlive(this);
return value;
}
public GlContext GetContext()
{
UnsafeNativeMethods.mp_GlSyncPoint__GetContext(MpPtr, out var sharedGlContextPtr).Assert();
GC.KeepAlive(this);
return new GlContext(sharedGlContextPtr);
}
// TODO: Put it in its own file
private class SharedGlSyncPointPtr : SharedPtrHandle
{
public SharedGlSyncPointPtr(IntPtr ptr) : base(ptr) { }
protected override void DeleteMpPtr() => UnsafeNativeMethods.mp_GlSyncToken__delete(Ptr);
public override IntPtr Get() => SafeNativeMethods.mp_GlSyncToken__get(MpPtr);
public override void Reset() => UnsafeNativeMethods.mp_GlSyncToken__reset(MpPtr);
}
}
}

View File

@ -0,0 +1,102 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using Mediapipe.Net.Core;
using Mediapipe.Net.Native;
namespace Mediapipe.Net.Gpu
{
public class GlTextureBuffer : MpResourceHandle
{
private SharedPtrHandle? sharedPtrHandle;
/// <remarks>
/// In the original MediaPipe repo, DeletionCallback only receives GlSyncToken.
/// However, IL2CPP does not support marshaling delegates that point to instance methods to native code,
/// so it receives also the texture name to specify the target instance.
/// </remarks>
public delegate void DeletionCallback(uint name, IntPtr glSyncToken);
public GlTextureBuffer(IntPtr ptr, bool isOwner = true) : base(isOwner)
{
sharedPtrHandle = new SharedGlTextureBufferPtr(ptr, isOwner);
Ptr = sharedPtrHandle.Get();
}
/// <param name="callback">
/// A function called when the texture buffer is deleted.
/// Make sure that this function doesn't throw exceptions and won't be GCed.
/// </param>
public GlTextureBuffer(uint target, uint name, int width, int height,
GpuBufferFormat format, DeletionCallback callback, GlContext? glContext)
{
var sharedContextPtr = glContext == null ? IntPtr.Zero : glContext.SharedPtr;
UnsafeNativeMethods.mp_SharedGlTextureBuffer__ui_ui_i_i_ui_PF_PSgc(
target, name, width, height, format, callback, sharedContextPtr, out var ptr).Assert();
sharedPtrHandle = new SharedGlTextureBufferPtr(ptr);
Ptr = sharedPtrHandle.Get();
}
public GlTextureBuffer(uint name, int width, int height, GpuBufferFormat format, DeletionCallback callback, GlContext? glContext = null) :
this(Gl.GL_TEXTURE_2D, name, width, height, format, callback, glContext)
{ }
protected override void DisposeManaged()
{
if (sharedPtrHandle != null)
{
sharedPtrHandle.Dispose();
sharedPtrHandle = null;
}
base.DisposeManaged();
}
protected override void DeleteMpPtr()
{
// Do nothing
}
public IntPtr SharedPtr => sharedPtrHandle == null ? IntPtr.Zero : sharedPtrHandle.MpPtr;
public uint Name() => SafeNativeMethods.mp_GlTextureBuffer__name(MpPtr);
public uint Target() => SafeNativeMethods.mp_GlTextureBuffer__target(MpPtr);
public int Width() => SafeNativeMethods.mp_GlTextureBuffer__width(MpPtr);
public int Height() => SafeNativeMethods.mp_GlTextureBuffer__height(MpPtr);
public GpuBufferFormat Format() => SafeNativeMethods.mp_GlTextureBuffer__format(MpPtr);
public void WaitUntilComplete() => UnsafeNativeMethods.mp_GlTextureBuffer__WaitUntilComplete(MpPtr).Assert();
public void WaitOnGpu() => UnsafeNativeMethods.mp_GlTextureBuffer__WaitOnGpu(MpPtr).Assert();
public void Reuse() => UnsafeNativeMethods.mp_GlTextureBuffer__Reuse(MpPtr).Assert();
public void Updated(GlSyncPoint prodToken) => UnsafeNativeMethods.mp_GlTextureBuffer__Updated__Pgst(MpPtr, prodToken.SharedPtr).Assert();
public void DidRead(GlSyncPoint consToken) => UnsafeNativeMethods.mp_GlTextureBuffer__DidRead__Pgst(MpPtr, consToken.SharedPtr).Assert();
public void WaitForConsumers() => UnsafeNativeMethods.mp_GlTextureBuffer__WaitForConsumers(MpPtr).Assert();
public void WaitForConsumersOnGpu() => UnsafeNativeMethods.mp_GlTextureBuffer__WaitForConsumersOnGpu(MpPtr).Assert();
public GlContext GetProducerContext() => new GlContext(SafeNativeMethods.mp_GlTextureBuffer__GetProducerContext(MpPtr), false);
// TODO: Put it in its own file
private class SharedGlTextureBufferPtr : SharedPtrHandle
{
public SharedGlTextureBufferPtr(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
protected override void DeleteMpPtr() => UnsafeNativeMethods.mp_SharedGlTextureBuffer__delete(Ptr);
public override IntPtr Get() => SafeNativeMethods.mp_SharedGlTextureBuffer__get(MpPtr);
public override void Reset() => UnsafeNativeMethods.mp_SharedGlTextureBuffer__reset(MpPtr);
}
}
}

View File

@ -0,0 +1,17 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Gpu
{
[StructLayout(LayoutKind.Sequential)]
public struct GlTextureInfo
{
public int GlInternalFormat;
public uint GlFormat;
public uint GlType;
public int Downscale;
}
}

View File

@ -0,0 +1,13 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
namespace Mediapipe.Net.Gpu
{
public enum GlVersion : uint
{
KGl = 1,
KGles2 = 2,
KGles3 = 3,
}
}

View File

@ -0,0 +1,39 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using Mediapipe.Net.Framework.Format;
using Mediapipe.Net.Native;
namespace Mediapipe.Net.Gpu
{
public enum GpuBufferFormat : uint
{
KUnknown = 0,
KBgra32 = ('B' << 24) + ('G' << 16) + ('R' << 8) + 'A',
kGrayFloat32 = ('L' << 24) + ('0' << 16) + ('0' << 8) + 'f',
kGrayHalf16 = ('L' << 24) + ('0' << 16) + ('0' << 8) + 'h',
kOneComponent8 = ('L' << 24) + ('0' << 16) + ('0' << 8) + '8',
kTwoComponentHalf16 = ('2' << 24) + ('C' << 16) + ('0' << 8) + 'h',
kTwoComponentFloat32 = ('2' << 24) + ('C' << 16) + ('0' << 8) + 'f',
kBiPlanar420YpCbCr8VideoRange = ('4' << 24) + ('2' << 16) + ('0' << 8) + 'v',
kBiPlanar420YpCbCr8FullRange = ('4' << 24) + ('2' << 16) + ('0' << 8) + 'f',
kRgb24 = 0x00000018, // Note: prefer Bgra32 whenever possible.
kRgbaHalf64 = ('R' << 24) + ('G' << 16) + ('h' << 8) + 'A',
kRgbaFloat128 = ('R' << 24) + ('G' << 16) + ('f' << 8) + 'A',
}
public static class GpuBufferFormatExtension
{
public static ImageFormat ImageFormatFor(this GpuBufferFormat gpuBufferFormat)
{
return SafeNativeMethods.mp__ImageFormatForGpuBufferFormat__ui(gpuBufferFormat);
}
public static GlTextureInfo GlTextureInfoFor(this GpuBufferFormat gpuBufferFormat, int plane, GlVersion glVersion = GlVersion.KGles3)
{
UnsafeNativeMethods.mp__GlTextureInfoForGpuBufferFormat__ui_i_ui(gpuBufferFormat, plane, glVersion, out var glTextureInfo).Assert();
return glTextureInfo;
}
}
}

View File

@ -0,0 +1,18 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
// #if LINUX || ANDROID
[Pure, DllImport(MEDIAPIPE_LIBRARY)]
public static extern IntPtr eglGetCurrentContext();
// #endif
}
}

View File

@ -0,0 +1,23 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern uint mp_GlCalculatorHelper__framebuffer(IntPtr glCalculatorHelper);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlCalculatorHelper__GetGlContext(IntPtr glCalculatorHelper);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool mp_GlCalculatorHelper__Initialized(IntPtr glCalculatorHelper);
}
}

View File

@ -0,0 +1,58 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
#region GlContext
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_SharedGlContext__get(IntPtr sharedGlContext);
// #if LINUX || ANDROID
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__egl_display(IntPtr glContext);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__egl_config(IntPtr glContext);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__egl_context(IntPtr glContext);
// #endif
// #if IOS
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__eagl_context(IntPtr glContext);
// #elif OSX
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__nsgl_context(IntPtr glContext);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__nsgl_pixel_format(IntPtr glContext);
// #endif
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool mp_GlContext__IsCurrent(IntPtr glContext);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern int mp_GlContext__gl_major_version(IntPtr glContext);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern int mp_GlContext__gl_minor_version(IntPtr glContext);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern long mp_GlContext__gl_finish_count(IntPtr glContext);
#endregion
#region GlSyncToken
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlSyncToken__get(IntPtr glSyncToken);
#endregion
}
}

View File

@ -0,0 +1,25 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern int mp_GlTexture__width(IntPtr glTexture);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern int mp_GlTexture__height(IntPtr glTexture);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern uint mp_GlTexture__target(IntPtr glTexture);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern uint mp_GlTexture__name(IntPtr glTexture);
}
}

View File

@ -0,0 +1,39 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using Mediapipe.Net.Gpu;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
#region GlTextureBuffer
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern uint mp_GlTextureBuffer__name(IntPtr glTextureBuffer);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern uint mp_GlTextureBuffer__target(IntPtr glTextureBuffer);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern int mp_GlTextureBuffer__width(IntPtr glTextureBuffer);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern int mp_GlTextureBuffer__height(IntPtr glTextureBuffer);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern GpuBufferFormat mp_GlTextureBuffer__format(IntPtr glTextureBuffer);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlTextureBuffer__GetProducerContext(IntPtr glTextureBuffer);
#endregion
#region SharedGlTextureBuffer
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_SharedGlTextureBuffer__get(IntPtr glTextureBuffer);
#endregion
}
}

View File

@ -0,0 +1,34 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using Mediapipe.Net.Gpu;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
// #if UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX || UNITY_ANDROID
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GpuBuffer__GetGlTextureBufferSharedPtr(IntPtr gpuBuffer);
// #endif
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern int mp_GpuBuffer__width(IntPtr gpuBuffer);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern int mp_GpuBuffer__height(IntPtr gpuBuffer);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern GpuBufferFormat mp_GpuBuffer__format(IntPtr gpuBuffer);
#region StatusOr
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool mp_StatusOrGpuBuffer__ok(IntPtr statusOrGpuBuffer);
#endregion
}
}

View File

@ -0,0 +1,20 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using Mediapipe.Net.Framework.Format;
using Mediapipe.Net.Gpu;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern ImageFormat mp__ImageFormatForGpuBufferFormat__ui(GpuBufferFormat format);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern ImageFormat mp__GpuBufferFormatForImageFormat__ui(ImageFormat format);
}
}

View File

@ -0,0 +1,25 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
// #if UNITY_IOS
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GpuResources__ios_gpu_data(IntPtr gpuResources);
// #endif
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_SharedGpuResources__get(IntPtr gpuResources);
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool mp_StatusOrGpuResources__ok(IntPtr statusOrGpuResources);
}
}

View File

@ -0,0 +1,18 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Native
{
internal partial class UnsafeNativeMethods : NativeMethods
{
[DllImport(MEDIAPIPE_LIBRARY)]
public static extern void glFlush();
[DllImport(MEDIAPIPE_LIBRARY)]
public static extern void glReadPixels(int x, int y, int width, int height, uint glFormat, uint glType, IntPtr pixels);
}
}

View File

@ -0,0 +1,53 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Runtime.InteropServices;
using Mediapipe.Net.Gpu;
namespace Mediapipe.Net.Native
{
internal partial class UnsafeNativeMethods : NativeMethods
{
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__(out IntPtr glCalculatorHelper);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_GlCalculatorHelper__delete(IntPtr glCalculatorHelper);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__InitializeForTest__Pgr(IntPtr glCalculatorHelper, IntPtr gpuResources);
// TODO: Make it ba a member of GlCalculatorHelper
public delegate IntPtr NativeGlStatusFunction();
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__RunInGlContext__PF(
IntPtr glCalculatorHelper, [MarshalAs(UnmanagedType.FunctionPtr)] NativeGlStatusFunction glFunc, out IntPtr status);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__CreateSourceTexture__Rif(
IntPtr glCalculatorHelper, IntPtr imageFrame, out IntPtr glTexture);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__CreateSourceTexture__Rgb(
IntPtr glCalculatorHelper, IntPtr gpuBuffer, out IntPtr glTexture);
// #if IOS
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__CreateSourceTexture__Rgb_i(
IntPtr glCalculatorHelper, IntPtr gpuBuffer, int plane, out IntPtr glTexture);
// #endif
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__CreateDestinationTexture__i_i_ui(
IntPtr glCalculatorHelper, int outputWidth, int outputHeight, GpuBufferFormat formatCode, out IntPtr glTexture);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__CreateDestinationTexture__Rgb(
IntPtr glCalculatorHelper, IntPtr gpuBuffer, out IntPtr glTexture);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__BindFrameBuffer__Rtexture(IntPtr glCalculatorHelper, IntPtr glTexture);
}
}

View File

@ -0,0 +1,61 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Native
{
internal partial class UnsafeNativeMethods : NativeMethods
{
#region GlContext
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_SharedGlContext__delete(IntPtr sharedGlContext);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_SharedGlContext__reset(IntPtr sharedGlContext);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlContext_GetCurrent(out IntPtr sharedGlContext);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlContext_Create__P_b([MarshalAs(UnmanagedType.I1)] bool createThread, out IntPtr statusOrSharedGlContext);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlContext_Create__Rgc_b(
IntPtr shareContext, [MarshalAs(UnmanagedType.I1)] bool createThread, out IntPtr statusOrSharedGlContext);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlContext_Create__ui_b(
uint shareContext, [MarshalAs(UnmanagedType.I1)] bool createThread, out IntPtr statusOrSharedGlContext);
// #if IOS
// TODO: iOS support?
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlContext_Create__Pes_b(
IntPtr sharegroup, [MarshalAs(UnmanagedType.I1)] bool createThread, out IntPtr statusOrSharedGlContext);
// #endif
#endregion
#region GlSyncToken
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_GlSyncToken__delete(IntPtr glSyncToken);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_GlSyncToken__reset(IntPtr glSyncToken);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlSyncPoint__Wait(IntPtr glSyncPoint);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlSyncPoint__WaitOnGpu(IntPtr glSyncPoint);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlSyncPoint__IsReady(IntPtr glSyncPoint, out bool value);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlSyncPoint__GetContext(IntPtr glSyncPoint, out IntPtr sharedGlContext);
#endregion
}
}

View File

@ -0,0 +1,24 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Native
{
internal partial class UnsafeNativeMethods : NativeMethods
{
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlTexture__(out IntPtr glTexture);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_GlTexture__delete(IntPtr glTexture);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlTexture__Release(IntPtr glTexture);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlTexture__GetGpuBufferFrame(IntPtr glTexture, out IntPtr gpuBuffer);
}
}

View File

@ -0,0 +1,50 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Runtime.InteropServices;
using Mediapipe.Net.Gpu;
namespace Mediapipe.Net.Native
{
internal partial class UnsafeNativeMethods : NativeMethods
{
#region GlTextureBuffer
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlTextureBuffer__WaitUntilComplete(IntPtr glTextureBuffer);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlTextureBuffer__WaitOnGpu(IntPtr glTextureBuffer);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlTextureBuffer__Reuse(IntPtr glTextureBuffer);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlTextureBuffer__Updated__Pgst(IntPtr glTextureBuffer, IntPtr prodToken);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlTextureBuffer__DidRead__Pgst(IntPtr glTextureBuffer, IntPtr consToken);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlTextureBuffer__WaitForConsumers(IntPtr glTextureBuffer);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlTextureBuffer__WaitForConsumersOnGpu(IntPtr glTextureBuffer);
#endregion
#region SharedGlTextureBuffer
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_SharedGlTextureBuffer__delete(IntPtr glTextureBuffer);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_SharedGlTextureBuffer__reset(IntPtr glTextureBuffer);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_SharedGlTextureBuffer__ui_ui_i_i_ui_PF_PSgc(
uint target, uint name, int width, int height, GpuBufferFormat format,
[MarshalAs(UnmanagedType.FunctionPtr)] GlTextureBuffer.DeletionCallback deletionCallback,
IntPtr producerContext, out IntPtr sharedGlTextureBuffer);
#endregion
}
}

View File

@ -0,0 +1,49 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Native
{
internal partial class UnsafeNativeMethods : NativeMethods
{
// #if LINUX || ANDROID
// TODO: What preprocessing directive for this?
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GpuBuffer__PSgtb(IntPtr glTextureBuffer, out IntPtr gpuBuffer);
// #endif
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_GpuBuffer__delete(IntPtr gpuBuffer);
#region StatusOr
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_StatusOrGpuBuffer__delete(IntPtr statusOrGpuBuffer);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_StatusOrGpuBuffer__status(IntPtr statusOrGpuBuffer, out IntPtr status);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_StatusOrGpuBuffer__value(IntPtr statusOrGpuBuffer, out IntPtr gpuBuffer);
#endregion
#region Packet
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp__MakeGpuBufferPacket__Rgb(IntPtr gpuBuffer, out IntPtr packet);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp__MakeGpuBufferPacket_At__Rgb_Rts(IntPtr gpuBuffer, IntPtr timestamp, out IntPtr packet);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_Packet__ConsumeGpuBuffer(IntPtr packet, out IntPtr statusOrGpuBuffer);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_Packet__GetGpuBuffer(IntPtr packet, out IntPtr gpuBuffer);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_Packet__ValidateAsGpuBuffer(IntPtr packet, out IntPtr status);
#endregion
}
}

View File

@ -0,0 +1,16 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System.Runtime.InteropServices;
using Mediapipe.Net.Gpu;
namespace Mediapipe.Net.Native
{
internal partial class UnsafeNativeMethods : NativeMethods
{
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp__GlTextureInfoForGpuBufferFormat__ui_i_ui(
GpuBufferFormat format, int plane, GlVersion glVersion, out GlTextureInfo glTextureInfo);
}
}

View File

@ -0,0 +1,33 @@
// Copyright (c) homuler and Vignette
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Runtime.InteropServices;
namespace Mediapipe.Net.Native
{
internal partial class UnsafeNativeMethods : NativeMethods
{
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_SharedGpuResources__delete(IntPtr gpuResources);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_SharedGpuResources__reset(IntPtr gpuResources);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GpuResources_Create(out IntPtr statusOrGpuResources);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GpuResources_Create__Pv(IntPtr externalContext, out IntPtr statusOrGpuResources);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_StatusOrGpuResources__delete(IntPtr statusOrGpuResources);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_StatusOrGpuResources__status(IntPtr statusOrGpuResources, out IntPtr status);
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_StatusOrGpuResources__value(IntPtr statusOrGpuResources, out IntPtr gpuResources);
}
}