Skip to content
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

visionbuf use EGL texture #310

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ if arch == "Darwin":
vipc_frameworks.append('OpenCL')
else:
vipc_libs.append('OpenCL')
vipc_libs.append('EGL')
envCython.Program('visionipc/visionipc_pyx.so', 'visionipc/visionipc_pyx.pyx',
LIBS=vipc_libs, FRAMEWORKS=vipc_frameworks)

Expand Down
10 changes: 10 additions & 0 deletions visionipc/visionbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include <CL/cl.h>
#endif

#define EGL_EGLEXT_PROTOTYPES
#define EGL_NO_X11
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <drm/drm_fourcc.h>

#define VISIONBUF_SYNC_FROM_DEVICE 0
#define VISIONBUF_SYNC_TO_DEVICE 1

Expand Down Expand Up @@ -51,12 +57,16 @@ class VisionBuf {
cl_mem buf_cl = nullptr;
cl_command_queue copy_q = nullptr;

// OpenGL
EGLImageKHR egl_image = EGL_NO_IMAGE_KHR;

// ion
int handle = 0;

void allocate(size_t len);
void import();
void init_cl(cl_device_id device_id, cl_context ctx);
void init_gl();
void init_rgb(size_t width, size_t height, size_t stride);
void init_yuv(size_t width, size_t height, size_t stride, size_t uv_offset);
int sync(int dir);
Expand Down
21 changes: 21 additions & 0 deletions visionipc/visionbuf_ion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ void VisionBuf::init_cl(cl_device_id device_id, cl_context ctx) {
assert(err == 0);
}

void VisionBuf::init_gl() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to do this here instead of UI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the image/texture is linked to the shared buffers, so it requires a texture pointer for every visionbuf object, so I guess it makes more sense to put it there

EGLDisplay display = eglGetCurrentDisplay();
EGLContext context = eglGetCurrentContext();

EGLint img_attrs[] = {
EGL_WIDTH, (int)this->width,
EGL_HEIGHT, (int)this->height, // 1000 // hack until stride is real
EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_NV12,
EGL_DMA_BUF_PLANE0_FD_EXT, this->fd,
EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
EGL_DMA_BUF_PLANE0_PITCH_EXT, (int)this->stride,
EGL_DMA_BUF_PLANE1_FD_EXT, this->fd,
EGL_DMA_BUF_PLANE1_OFFSET_EXT, (int)this->uv_offset,
EGL_DMA_BUF_PLANE1_PITCH_EXT, (int)this->stride,
EGL_NONE
};
this->egl_image = eglCreateImageKHR(display, context, EGL_LINUX_DMA_BUF_EXT, 0, img_attrs);
printf("got %p %p gl image %p (%lux%lu) with fd %d error 0x%x\n", display, EGL_NO_CONTEXT,
this->egl_image, this->width, this->height,
this->fd, eglGetError());
}

int VisionBuf::sync(int dir) {
struct ion_flush_data flush_data = {0};
Expand Down