diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-09-06 12:41:14 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-09-06 12:41:14 +0200 |
commit | 954a41de9cde43f68eae0340cc1ed109257f9356 (patch) | |
tree | 2556c09a3e53c656fe265c20475476c5c31314a5 /src | |
parent | 239f2010f5b91117ecd485ac20c541a1e8ecd434 (diff) |
Explicit glFlush/glFinish before and after render operations to fix tearing and stutter on amd
Diffstat (limited to 'src')
-rw-r--r-- | src/capture/kms.c | 7 | ||||
-rw-r--r-- | src/capture/nvfbc.c | 6 | ||||
-rw-r--r-- | src/capture/portal.c | 42 | ||||
-rw-r--r-- | src/capture/xcomposite.c | 9 | ||||
-rw-r--r-- | src/egl.c | 2 | ||||
-rw-r--r-- | src/encoder/video/software.c | 3 |
6 files changed, 32 insertions, 37 deletions
diff --git a/src/capture/kms.c b/src/capture/kms.c index ce50d31..bdf3202 100644 --- a/src/capture/kms.c +++ b/src/capture/kms.c @@ -515,6 +515,9 @@ static int gsr_capture_kms_capture(gsr_capture *cap, AVFrame *frame, gsr_color_c if(!capture_is_combined_plane) capture_pos = (vec2i){drm_fd->x, drm_fd->y}; + self->params.egl->glFlush(); + self->params.egl->glFinish(); + gsr_color_conversion_draw(color_conversion, self->external_texture_fallback ? self->external_input_texture_id : self->input_texture_id, (vec2i){target_x, target_y}, self->capture_size, capture_pos, self->capture_size, @@ -530,8 +533,8 @@ static int gsr_capture_kms_capture(gsr_capture *cap, AVFrame *frame, gsr_color_c render_drm_cursor(self, color_conversion, cursor_drm_fd, target_x, target_y, texture_rotation); } - //self->params.egl->glFlush(); - //self->params.egl->glFinish(); + self->params.egl->glFlush(); + self->params.egl->glFinish(); return 0; } diff --git a/src/capture/nvfbc.c b/src/capture/nvfbc.c index 80fbaa8..b7e6bb5 100644 --- a/src/capture/nvfbc.c +++ b/src/capture/nvfbc.c @@ -408,11 +408,17 @@ static int gsr_capture_nvfbc_capture(gsr_capture *cap, AVFrame *frame, gsr_color return 0; } + cap_nvfbc->params.egl->glFlush(); + cap_nvfbc->params.egl->glFinish(); + gsr_color_conversion_draw(color_conversion, cap_nvfbc->setup_params.dwTextures[grab_params.dwTextureIndex], (vec2i){0, 0}, (vec2i){frame->width, frame->height}, (vec2i){0, 0}, (vec2i){frame->width, frame->height}, 0.0f, false); + cap_nvfbc->params.egl->glFlush(); + cap_nvfbc->params.egl->glFinish(); + return 0; } diff --git a/src/capture/portal.c b/src/capture/portal.c index 5d5acd7..7d50c0a 100644 --- a/src/capture/portal.c +++ b/src/capture/portal.c @@ -16,7 +16,6 @@ typedef struct { gsr_capture_portal_params params; gsr_texture_map texture_map; - unsigned int external_intermediate_texture; gsr_dbus dbus; char *session_handle; @@ -48,11 +47,6 @@ static void gsr_capture_portal_stop(gsr_capture_portal *self) { self->texture_map.external_texture_id = 0; } - if(self->external_intermediate_texture) { - self->params.egl->glDeleteTextures(1, &self->external_intermediate_texture); - self->external_intermediate_texture = 0; - } - if(self->texture_map.cursor_texture_id) { self->params.egl->glDeleteTextures(1, &self->texture_map.cursor_texture_id); self->texture_map.cursor_texture_id = 0; @@ -313,6 +307,14 @@ static int max_int(int a, int b) { return a > b ? a : b; } +static int gl_texture_get_internal_image_format(gsr_egl *egl, unsigned int texture) { + int internal_image_format = 0; + egl->glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture); + egl->glGetTexLevelParameteriv(GL_TEXTURE_EXTERNAL_OES, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_image_format); + egl->glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0); + return internal_image_format; +} + static int gsr_capture_portal_capture(gsr_capture *cap, AVFrame *frame, gsr_color_conversion *color_conversion) { (void)frame; (void)color_conversion; @@ -324,39 +326,21 @@ static int gsr_capture_portal_capture(gsr_capture *cap, AVFrame *frame, gsr_colo gsr_pipewire_region region = {0, 0, 0, 0}; gsr_pipewire_region cursor_region = {0, 0, 0, 0}; bool using_external_image = false; - bool resized = false; if(gsr_pipewire_map_texture(&self->pipewire, self->texture_map, ®ion, &cursor_region, self->plane_fds, &self->num_plane_fds, &using_external_image)) { if(region.width != self->capture_size.x || region.height != self->capture_size.y) { gsr_color_conversion_clear(color_conversion); self->capture_size.x = region.width; self->capture_size.y = region.height; - resized = true; } } - if(using_external_image && (self->external_intermediate_texture == 0 || resized)) { - if(self->external_intermediate_texture == 0) - self->params.egl->glGenTextures(1, &self->external_intermediate_texture); - self->params.egl->glBindTexture(GL_TEXTURE_2D, self->external_intermediate_texture); - self->params.egl->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, self->capture_size.x, self->capture_size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - self->params.egl->glBindTexture(GL_TEXTURE_2D, 0); - } - - /* The image glitches a lot unless this is done. TODO: Find a proper solution */ - if(using_external_image) { - self->params.egl->glCopyImageSubData(self->texture_map.external_texture_id, GL_TEXTURE_EXTERNAL_OES, 0, 0, 0, 0, - self->external_intermediate_texture, GL_TEXTURE_2D, 0, 0, 0, 0, - self->capture_size.x, self->capture_size.y, 1); - } + self->params.egl->glFlush(); + self->params.egl->glFinish(); const int target_x = max_int(0, frame->width / 2 - self->capture_size.x / 2); const int target_y = max_int(0, frame->height / 2 - self->capture_size.y / 2); - gsr_color_conversion_draw(color_conversion, using_external_image ? self->external_intermediate_texture : self->texture_map.texture_id, + gsr_color_conversion_draw(color_conversion, using_external_image ? self->texture_map.external_texture_id : self->texture_map.texture_id, (vec2i){target_x, target_y}, self->capture_size, (vec2i){region.x, region.y}, self->capture_size, 0.0f, false); @@ -376,8 +360,8 @@ static int gsr_capture_portal_capture(gsr_capture *cap, AVFrame *frame, gsr_colo self->params.egl->glDisable(GL_SCISSOR_TEST); } - //self->params.egl->glFlush(); - //self->params.egl->glFinish(); + self->params.egl->glFlush(); + self->params.egl->glFinish(); return 0; } diff --git a/src/capture/xcomposite.c b/src/capture/xcomposite.c index 899ffe0..4c54027 100644 --- a/src/capture/xcomposite.c +++ b/src/capture/xcomposite.c @@ -325,6 +325,9 @@ static int gsr_capture_xcomposite_capture(gsr_capture *cap, AVFrame *frame, gsr_ const int target_x = max_int(0, frame->width / 2 - self->texture_size.x / 2); const int target_y = max_int(0, frame->height / 2 - self->texture_size.y / 2); + self->params.egl->glFlush(); + self->params.egl->glFinish(); + gsr_color_conversion_draw(color_conversion, window_texture_get_opengl_texture_id(&self->window_texture), (vec2i){target_x, target_y}, self->texture_size, (vec2i){0, 0}, self->texture_size, @@ -349,10 +352,8 @@ static int gsr_capture_xcomposite_capture(gsr_capture *cap, AVFrame *frame, gsr_ self->params.egl->glDisable(GL_SCISSOR_TEST); } - // TODO: Do video encoder specific conversion here - - //self->params.egl->glFlush(); - //self->params.egl->glFinish(); + self->params.egl->glFlush(); + self->params.egl->glFinish(); return 0; } @@ -445,8 +445,6 @@ static bool gsr_egl_load_gl(gsr_egl *self, void *library) { { (void**)&self->glTexParameteriv, "glTexParameteriv" }, { (void**)&self->glGetTexLevelParameteriv, "glGetTexLevelParameteriv" }, { (void**)&self->glTexImage2D, "glTexImage2D" }, - { (void**)&self->glTexSubImage2D, "glTexSubImage2D" }, - { (void**)&self->glCopyImageSubData, "glCopyImageSubData" }, { (void**)&self->glGetTexImage, "glGetTexImage" }, { (void**)&self->glGenFramebuffers, "glGenFramebuffers" }, { (void**)&self->glBindFramebuffer, "glBindFramebuffer" }, diff --git a/src/encoder/video/software.c b/src/encoder/video/software.c index 89b2cf0..4a4b78a 100644 --- a/src/encoder/video/software.c +++ b/src/encoder/video/software.c @@ -112,6 +112,9 @@ static void gsr_video_encoder_software_copy_textures_to_frame(gsr_video_encoder } encoder_software->params.egl->glBindTexture(GL_TEXTURE_2D, 0); // cap_kms->kms.base.egl->eglSwapBuffers(cap_kms->kms.base.egl->egl_display, cap_kms->kms.base.egl->egl_surface); + + encoder_software->params.egl->glFlush(); + encoder_software->params.egl->glFinish(); } static void gsr_video_encoder_software_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) { |