-
-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of GpuBuffer with WebCamTexture / support for iOS Metal API #768
Comments
Please don't leave the
What kind of support do you expect? |
Sorry for a late response, I was trying to implement your comment. GpuBufferIn the Estimator class, I added 2 logs, so it's visible which part of the code still gets executed and which does not. There is no exception thrown or anything. I never receive a result from the graph. Is there something I'm doing wrong? CodeBelow is the relevant code:
EstimationManager (MonoBehaviour):
Estimator:
Graph that I use:
Working caseIf I use
then pass this ImageFrame to the graph it works (obviously I change the graph to expect ImageFrame instead of GpuBuffer). MetalFor Metal support I meant, if it's possible to pass Metal's pointer to MediaPipe like we're doing with GLES. Reason for tihs is that we do not want to pass texture from GPU to CPU and back to GPU. |
What is the return value? (if it returned
I am aware that this problem exists, and I'd like to implement the feature if I had unlimited time, but it's not really a high priority because I'm not sure if it really improves the plugin's performance (if the sample app runs at 60fps and the inference step takes less than 1/60 sec, it may not make many differences if any). |
I haven't yet tried the app on newer iOS devices, so it's possible that Metal support for this won't be possible as you said 😄. |
Do you maybe have/use some community channel like discord group? |
Hmm, I don't know. On my Android device, it certainly works when I applied the below patch. diff --git a/Assets/MediaPipeUnity/Samples/Common/Scripts/Solution.cs b/Assets/MediaPipeUnity/Samples/Common/Scripts/Solution.cs
index 813c66a..a6f4322 100644
--- a/Assets/MediaPipeUnity/Samples/Common/Scripts/Solution.cs
+++ b/Assets/MediaPipeUnity/Samples/Common/Scripts/Solution.cs
@@ -76,7 +76,7 @@ namespace Mediapipe.Unity
if (textureType == typeof(WebCamTexture))
{
- textureFrame.ReadTextureFromOnCPU((WebCamTexture)sourceTexture);
+ textureFrame.ReadTextureFromOnGPU((WebCamTexture)sourceTexture);
}
else if (textureType == typeof(Texture2D))
{ The possible reasons I can come up with are:
To be precise, supporting Metal itself is possible, but it's not a high priority for now.
No, I don't. |
By the way, TextureFormat of the camera is "R8G8B8A8_UNorm". So I guess this could be the problem, since it's RGBA32 instead of ARGB32? Also a note, that |
OpenGL ES 3.2 is required to share the context with MediaPipe (that's why even |
Hey there once more, I would very much appreciate it, if you could please verify that ReadTextureFromOnGPU works on your side. Usage of ReadTextureFromOnCPUI tested it on 2 GPUs ARM Mali-G71 MP20 and Xclipse 920, which both support GL ES 3.2 |
I confirmed (see #768 (comment)). |
I think you should display the target texture (after calling |
Mind if I ask which device you tried it on or which GPU it uses ? |
Pixel 6. |
Sorry for a late response.
The following is the process of applying
Output processing:
This code works if I change |
Which log is output on your device? (maybe you need to build your apk with MediaPipeUnityPlugin/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/GpuManager.cs Lines 78 to 87 in 391d7d9
Hmm, interesting. I guess this code wouldn't work on my Pixel 6 rather (I need to do |
Hey,
This does show the camera preview on the screen. But if I use
Output is the following: |
Some additional information: I checked additional data in I have also tested your sample app on Pixel 6 with ReadTextureFromOnGPU set and it's the same outcome. |
I managed to find out the cause of this issue 😅 MediaPipeUnityPlugin/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSourceSolution.cs Lines 71 to 73 in 6b8c674
I had to change the format of the pool from TextureFormat.RGBA32 to TextureFormat.ARGB32 . I think there's a typo in the comment :)
Also this works on GLES 3.1, so 3.2 is not mandatory |
So it seems that the cause was:
The following comment is not a typo (cf. https://github.com/google/mediapipe/blob/7a6ae97a0ef298014aaf5e1370cb6f8237f2ac21/mediapipe/gpu/gpu_buffer_format.cc#L64-L78).
However, at least in Unity, this assumption does not always hold (the input format can be RGBA or ARGB, etc...).
Indeed, I was wrong about this, and it seems that OpenGL ES 3.2 is not required to create a context. |
Yes, that was the cause :)
Ah okay 👍🏼, wasn't sure. Is there any way to not block the CPU while MediaPipeUnityPlugin/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/TextureFramePool.cs Line 121 in 6b8c674
MediaPipeUnityPlugin/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/TextureFrame.cs Lines 268 to 281 in 6b8c674
Or will this unsync the GPU & CPU and result in uncontrollable crashes? I'd like to achieve relatively smooth performance on old devices (e.g. Samsung Galaxy J7). Currently this on average causes 90-100 ms of lag. |
Do you mean |
Does changing MediaPipeUnityPlugin/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/TextureFramePool.cs Line 18 in 391d7d9
|
No, not at all. |
@tealm |
Plugin Version or Commit ID
v0.10.1
Unity Version
2022.2
Your Host OS
macOS Monterey 12.6
Target Platform
Android, iOS
Description
1. Is it possible to use GpuBuffer with WebCamTexture?
I tried creating GpuBuffer with Texture.GetNativeTexturePtr, It compiled fine and the app never crashed. TryGetNext is never true, feels like the result is never provided. There is also no exception thrown, I had Logcat is attached to the device with mediapipe dbg build. I used https://github.com/homuler/MediaPipeUnityPlugin/wiki/API-Overview#gpubuffer ,
MediaPipeUnityPlugin/Assets/Mediapipe/Samples/Scripts/DemoGraph.cs
Lines 99 to 112 in 92cad4b
MediaPipeUnityPlugin/Assets/MediaPipe/Examples/Scripts/DemoGraph.cs
Lines 54 to 63 in 18e00a8
I saw that there are different texture formats (SRGBA from WebCamTexture and BGRA for GpuBuffer), could this be the problem?
MediaPipeUnityPlugin/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSourceSolution.cs
Line 72 in 6b8c674
My goal is to skip copying data from GPU to CPU and then passing it back to GPU (MP). It is a huge bottleneck on older devices. I also tried reading the texture of WebCamTexture from a thread, but it can only be read from the main thread.
Calculator I used:
https://github.com/homuler/MediaPipeUnityPlugin/blob/6b8c6743f23539f7604e74dc260b01e0f58f1707/Assets/MediaPipeUnity/Samples/Scenes/Pose%20Tracking/pose_tracking_opengles.txt
2. Support for Metal API
I looked around the repo, but I couldn't figure it out, if there is a support for Metal API?
If not, is it planned to be added in the future?
Code to Reproduce the issue
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: