-
-
Notifications
You must be signed in to change notification settings - Fork 475
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
Export CreateSyncToken from GlContext to csharp. #1154
Comments
Could you please tell me the relevant code you're using to input data into the CalculatorGraph? (e.g. copy from |
In
|
After digging more about it, member function |
I haven't investigated thoroughly yet, but I think at least the following two need to be ported to Unity.
I'm not sure if it's enough to just generate a |
I currently use GlContext::CreateSyncToken() and void GlTextureBuffer::Updated(std::shared_ptr) to set the sync point, but it's more complex than I think before using it.
Hope I could find a way to solve those issue. |
Finally, I managed to make it working.
MpReturnCode mp_GlTextureBuffer__InsertProducerSyncPoint(mediapipe::GlTextureBuffer* gl_texture_buffer) {
TRY_ALL
const auto& producerContext = gl_texture_buffer->GetProducerContext();
if (producerContext) {
gl_texture_buffer->Updated(mediapipe::GlContext::CreateSyncTokenForCurrentExternalContext(producerContext));
}
RETURN_CODE(MpReturnCode::Success);
CATCH_ALL
}
Calling After done all of this, the GPU readback of WebCamTexture on MainThread is gone, and flicks are also gone. But the latency grows to 40ms, some of them are missing parts of |
By the way, does it run faster when calling Line 130 in 9e2d601
|
I think no, I have tested not set the sync point, the latency is same to set a sync point, the my device is stronge enough to run 60 FPS on MainThread, so the readback on MainThread won't let time cost beyond 16ms, it won't affect latency. The bottleneck is compute dispatch and result readback on mediapipe thread. |
I got your point, async readback is sure a better way to reduce MainThread blocks in the existing GPU method(requires a readback). |
After profiled the GPU render stage, my device will use around 30ms to finish compute shader for pose landmark, so it might has no way to reduce latency unless use faster model(I already use the lite model with 320*240 camera texture resolution). |
Conclusion: The latency might be improved if the readback is too slow in current GPU method on your device, or be simliar if readback is quick enough. By the way, trigger the AddPacketToInputStream at |
Feature Description
Memeber function
CreateSyncTokenForCurrentExternalContext
ofGlContext
is not exported to c# side, it is required for sync texture copy when directly use texture on GPU without readback.Current Behaviour/State
Currently
WebCamTexture
will be readback to CPU and upload to GPU again to do the GPU calculation, but theWebCamTexture
can be copied toTextureFrame
directly on GPU side and feed to calculator directly on GPU side. It works on Android at least.But without sync point get from Unity side, calculator won't wait the copy finished by Unity and will result huge flicking, there is a static member function of
GlContext
calledCreateSyncTokenForCurrentExternalContext
is designed for this usage, please export it to c# side.Additional Context
Function position: https://github.com/google/mediapipe/blob/master/mediapipe/gpu/gl_context.h#L322
The text was updated successfully, but these errors were encountered: