How to access(zero copy) android AHardWareBuffer and ANativeWindow_Buffer, with mali opencl?
please note, ANativeWindow_Buffer is not ANativeWindowBuffer.
AHardWareBuffer
https://developer.android.google.cn/ndk/reference/group/a-hardware-buffer
ANativeWindow_Buffer:
https://developer.android.google.cn/ndk/reference/group/a-native-window#group___a_native_window_1gad0983ca473ce36293baf5e51a14c3357
1, About AHardwareBuffer.
Can i use pass that buffer to eglCreateImageKHR to create an EGLImage resource type, then use clCreateFromEGLImageKHR to get a cl_mem?
there is some info below, about AHardwareBuffer, on https://developer.android.google.cn/ndk/guides/stable_apis#hardware_buffer_apis,
"You can allocate an AHardwareBuffer and use it to obtain an EGLClientBuffer resource type via the eglGetNativeClientBufferANDROID extension. You can pass that buffer to eglCreateImageKHR to create an EGLImage resource type, which may then be bound to a texture via glEGLImageTargetTexture2DOES on supported devices. This can be useful for creating textures that may be shared cross-process"
2, About ANativeWindow_Buffer.
Is there any other way to render the preview, with OPENCL? For real time preview, i wonder how to directly write the display buffer, with openCL.
there is a opencv sample , opencl can precess GL texture, but the preview is rendered via OpenGL textures other than OPENCL. docs.opencv.org/.../tutorial_android_ocl_intro.html
1. AHardwareBuffer
I started to think about this after posting my reply yesterday. This looks like it would be a plausible route but unfortunately the Mali driver doesn't support EGL_ANDROID_get_native_client_buffer.
2. ANativeWindow_Buffer
If rendering a texture with OpenGL is an acceptable solution, a possible route to explore would be:
- create an EGL image from a dma_buf allocation (via ION most likely)
- import it in CL using clCreateFromEGLImageKHR
- create a GL external texture from it
- write to it using CL
- render it using GL
This is definitely something that we support and validate.
Also, If I understand correctly, you're using OpenCV. You may want to have a look our compute library [1] (built on top of OpenCL) that has a number of algorithms optimised for Mali GPUs.
Lastly, I am going to be away for a couple of weeks and won't be able to reply until I get back but don't hesitate to keep posting your findings and questions. I'll pick up the thread when I'm back (and other might be able to help as well).
[1] github.com/.../ComputeLibrary
I have queried the system with huawei P30 pro, with eglQueryString, it looks like support the EGL_ANDROID_get_native_client_buffer.
EGL_EXTENSIONS:EGL_KHR_get_all_proc_addresses EGL_ANDROID_presentation_time EGL_KHR_swap_buffers_with_damage EGL_ANDROID_get_native_client_buffer EGL_ANDROID_front_buffer_auto_refresh EGL_ANDROID_get_frame_timestamps EGL_EXT_surface_SMPTE2086_metadata EGL_EXT_surface_CTA861_3_metadata EGL_KHR_image EGL_KHR_image_base EGL_EXT_image_gl_colorspace EGL_KHR_gl_colorspace EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image EGL_KHR_fence_sync EGL_KHR_create_context EGL_KHR_config_attribs EGL_KHR_surfaceless_context EGL_EXT_create_context_robustness EGL_ANDROID_image_native_buffer EGL_KHR_wait_sync EGL_ANDROID_recordable EGL_KHR_partial_update EGL_EXT_pixel_format_float EGL_KHR_mutable_render_buffer EGL_EXT_protected_content EGL_IMG_context_priority EGL_KHR_no_config_context
Yes, while we don't support this extension directly, it is indeed implemented in Android's EGL layer so you can rely on it. Have you been able to make the EGL route work?
Regards,
Kévin
Not yet.
Thanks for the update. Good luck and let us know how you get on.