GLES: Perform additional transport flushes 02/243502/3
authorLukasz Kostyra <l.kostyra@samsung.com>
Mon, 7 Sep 2020 09:04:56 +0000 (11:04 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Tue, 8 Sep 2020 14:34:41 +0000 (16:34 +0200)
On some rare cases there still was a multithreading issue with resource
sharing across GL contexts. Ensuring glBind*() calls flush the transport
queue eliminates these cases.

Additionally removed sharegroup locking and flushing for Framebuffer
objects - these, according to specification, are not shared between
contexts (and so, between threads) and thus don't require extra
implicit synchronization.

Change-Id: If696ab64d553f6aadca39cd0044c533d35c064d8

EGL/yagl_egl_calls.c
GLES_common/yagl_gles_calls.c
GLES_common/yagl_host_gles_calls.c

index db484df23b5203d64705ead020affe0355865074..ce71728a6eec6d371b636d6563b138844efe9a85 100644 (file)
@@ -1757,6 +1757,18 @@ YAGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy_,
                         target,
                         buffer);
 
+    if (!yagl_validate_display(dpy_, &dpy)) {
+        goto out;
+    }
+
+    if (target == EGL_GL_TEXTURE_2D_KHR) {
+        if (!yagl_validate_context(dpy, ctx_, &ctx)) {
+            goto out;
+        }
+
+        yagl_sharegroup_mutex_lock_if_shared(ctx->client_ctx->sg);
+    }
+
     iface = yagl_get_any_client_interface();
 
     if (!iface) {
@@ -1769,10 +1781,6 @@ YAGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy_,
         goto out;
     }
 
-    if (!yagl_validate_display(dpy_, &dpy)) {
-        goto out;
-    }
-
     switch (target) {
     case EGL_NATIVE_PIXMAP_KHR:
         if (!dpy->native_dpy->platform->pixmaps_supported) {
@@ -1862,19 +1870,11 @@ YAGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy_,
             }
         }
 
-        if (!yagl_validate_context(dpy, ctx_, &ctx)) {
-            goto out;
-        }
-
-        yagl_sharegroup_mutex_lock_if_shared(ctx->client_ctx->sg);
-
         image = yagl_get_backend()->create_image_gl_texture_2d(dpy,
                                                                ctx,
                                                                (yagl_object_name)VOIDP2INT(buffer),
                                                                iface);
 
-        yagl_sharegroup_mutex_unlock_if_shared(ctx->client_ctx->sg);
-
         if (!image) {
             goto out;
         }
@@ -1919,6 +1919,10 @@ YAGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy_,
 out:
     yagl_image_release(image);
 
+    if (target == EGL_GL_TEXTURE_2D_KHR) {
+        yagl_sharegroup_mutex_unlock_if_shared(ctx->client_ctx->sg);
+    }
+
     yagl_context_release(ctx);
 
     YAGL_LOG_FUNC_EXIT("%p", ret);
index 41e336852b0bfdd474fd50baee838e7e1fbfea50..69de0c3c55f8026ac3797c5dda718e807de7fbd3 100644 (file)
@@ -456,8 +456,6 @@ void glBindFramebuffer(GLenum target, GLuint framebuffer)
 
     YAGL_GET_CTX();
 
-    yagl_sharegroup_mutex_lock_if_shared(ctx->base.sg);
-
     if (framebuffer != 0) {
         framebuffer_obj = (struct yagl_gles_framebuffer*)yagl_namespace_acquire(&ctx->framebuffers,
             framebuffer);
@@ -479,8 +477,6 @@ void glBindFramebuffer(GLenum target, GLuint framebuffer)
 out:
     yagl_gles_framebuffer_release(framebuffer_obj);
 
-    yagl_sharegroup_mutex_unlock_if_shared(ctx->base.sg);
-
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1070,8 +1066,6 @@ void glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
 
     YAGL_GET_CTX();
 
-    yagl_sharegroup_mutex_lock_if_shared(ctx->base.sg);
-
     if (n < 0) {
         YAGL_SET_ERR(GL_INVALID_VALUE);
         goto out;
@@ -1087,8 +1081,6 @@ void glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
     }
 
 out:
-    yagl_sharegroup_mutex_unlock_if_shared(ctx->base.sg);
-
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -1499,8 +1491,6 @@ void glGenFramebuffers(GLsizei n, GLuint *framebuffer_names)
 
     YAGL_GET_CTX();
 
-    yagl_sharegroup_mutex_lock_if_shared(ctx->base.sg);
-
     if (n < 0) {
         YAGL_SET_ERR(GL_INVALID_VALUE);
         goto out;
@@ -1531,8 +1521,6 @@ out:
     }
     yagl_free(framebuffers);
 
-    yagl_sharegroup_mutex_unlock_if_shared(ctx->base.sg);
-
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
index df7a6280cd66feb7f774504a64a994f9ad9cac43..6f2c01d7bfecb3799835d138184dde8abadd1f74 100644 (file)
@@ -420,6 +420,7 @@ void yagl_host_glBindBuffer(GLenum target, GLuint buffer)
     yagl_transport_put_out_GLenum(t, target);
     yagl_transport_put_out_GLuint(t, buffer);
     yagl_transport_end(t);
+    yagl_transport_flush(t, NULL);
 }
 
 /*
@@ -534,6 +535,7 @@ void yagl_host_glBindTexture(GLenum target, GLuint texture)
     yagl_transport_put_out_GLenum(t, target);
     yagl_transport_put_out_GLuint(t, texture);
     yagl_transport_end(t);
+    yagl_transport_flush(t, NULL);
 }
 
 /*
@@ -978,7 +980,6 @@ void yagl_host_glGenFramebuffers(const GLuint *framebuffers, int32_t framebuffer
     yagl_transport_begin(t, yagl_api_id_gles, 63, 2 * 8, 0 * 8 + yagl_transport_array_size(framebuffers, framebuffers_count, sizeof(GLuint)));
     yagl_transport_put_out_array(t, framebuffers, framebuffers_count, sizeof(GLuint));
     yagl_transport_end(t);
-    yagl_transport_flush(t, NULL);
 }
 
 /*
@@ -1184,6 +1185,7 @@ void yagl_host_glBindRenderbuffer(GLenum target, GLuint renderbuffer)
     yagl_transport_put_out_GLenum(t, target);
     yagl_transport_put_out_GLuint(t, renderbuffer);
     yagl_transport_end(t);
+    yagl_transport_flush(t, NULL);
 }
 
 /*