From 1f0ea70c366f8b2f033d0d49f93172e85c8f0f78 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 24 Dec 2025 18:56:01 +0100 Subject: [PATCH] wip sync --- TODO | 5 ++++- include/egl.h | 10 ++++++++++ src/capture/kms.c | 12 ++++++++++++ src/egl.c | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index aba7edf..8055608 100644 --- a/TODO +++ b/TODO @@ -375,4 +375,7 @@ Taking a screenshot of camera with mjpeg doesn't work correctly because it updat Make capture from multiple sources work on nvidia x11 when capturing monitor + window. It doesn't work right now because monitor requires glx (nvfbc) while window requires egl. -Support v4l2 mplane on devices where it's supported (where it's more efficient). My camera doesn't support mplane. \ No newline at end of file +Support v4l2 mplane on devices where it's supported (where it's more efficient). My camera doesn't support mplane. + +Implement v4l2 yuyv nvidia capture by capturing rg88 yuyv to rgb as is done now for screenshot, but also do that for video by creating an intermediate rgb texture for the camera. Then render that rgb texture to the video texture. + This is needed to properly scale the yuyv texture without messing it up (the texture indexing). \ No newline at end of file diff --git a/include/egl.h b/include/egl.h index d4fed98..2927b53 100644 --- a/include/egl.h +++ b/include/egl.h @@ -40,6 +40,7 @@ typedef struct __GLXFBConfigRec *GLXFBConfig; typedef struct __GLXcontextRec *GLXContext; typedef XID GLXDrawable; typedef void(*__GLXextFuncPtr)(void); +typedef struct __GLsync *GLsync; #define EGL_SUCCESS 0x3000 #define EGL_BUFFER_SIZE 0x3020 @@ -151,6 +152,11 @@ typedef void(*__GLXextFuncPtr)(void); #define GL_COMPILE_STATUS 0x8B81 #define GL_LINK_STATUS 0x8B82 +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_CONDITION_SATISFIED 0x911C +#define GL_ALREADY_SIGNALED 0x911A + typedef unsigned int (*FUNC_eglExportDMABUFImageQueryMESA)(EGLDisplay dpy, EGLImageKHR image, int *fourcc, int *num_planes, uint64_t *modifiers); typedef unsigned int (*FUNC_eglExportDMABUFImageMESA)(EGLDisplay dpy, EGLImageKHR image, int *fds, int32_t *strides, int32_t *offsets); typedef void (*FUNC_glEGLImageTargetTexture2DOES)(unsigned int target, GLeglImageOES image); @@ -309,6 +315,10 @@ struct gsr_egl { void* (*glMapBufferRange)(unsigned int target, intptr_t offset, ssize_t length, unsigned int access); unsigned char (*glUnmapBuffer)(unsigned int target); void (*glGetIntegerv)(unsigned int pname, int *params); + + GLsync (*glFenceSync)(unsigned int condition, unsigned int flags); + void (*glDeleteSync)(GLsync sync); + unsigned int (*glClientWaitSync)(GLsync sync, unsigned int flags, uint64_t timeout); }; bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture, bool enable_debug); diff --git a/src/capture/kms.c b/src/capture/kms.c index 4f2eb7d..c0bb54b 100644 --- a/src/capture/kms.c +++ b/src/capture/kms.c @@ -628,6 +628,18 @@ static int gsr_capture_kms_capture(gsr_capture *cap, gsr_capture_metadata *captu } } + // static GLsync sync = NULL; + + // if(sync) { + // const unsigned int r = self->params.egl->glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, 1000 * 1000 * 1000); + // if(r != GL_CONDITION_SATISFIED && r != GL_ALREADY_SIGNALED) { + // fprintf(stderr, "failed sync: %u\n", r); + // } + // self->params.egl->glDeleteSync(sync); + // } + + // sync = self->params.egl->glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + //self->params.egl->glFlush(); //self->params.egl->glFinish(); diff --git a/src/egl.c b/src/egl.c index 81d39f1..83c4bd6 100644 --- a/src/egl.c +++ b/src/egl.c @@ -333,6 +333,10 @@ static bool gsr_egl_load_gl(gsr_egl *self, void *library) { { (void**)&self->glUnmapBuffer, "glUnmapBuffer" }, { (void**)&self->glGetIntegerv, "glGetIntegerv" }, + { (void**)&self->glFenceSync, "glFenceSync" }, + { (void**)&self->glDeleteSync, "glDeleteSync" }, + { (void**)&self->glClientWaitSync, "glClientWaitSync" }, + { NULL, NULL } };