|
8bb3c827
|
2021-07-22T19:06:40
|
|
Fix Multithreaded eglDestroyContext()/eglTerminate()
The following EGL calls can lead to a crash in eglMakeCurrent():
Thread A: eglMakeCurrent(context A)
Thread B: eglDestroyContext(context A)
B: eglTerminate() <<--- this release context A
Thread A: eglMakeCurrent(context B)
The eglMakeCurrent(context B) call will assert when attempting to
unMakeCurrent(), since thread A doesn't know that context A was already
destroyed by thread B.
To fix this:
1.) A Context will only be released once there are no Threads that
currently have a reference to it (no longer have the Context current).
- Context::mIsCurrent is being removed, since it was inaccurate and not
thread-safe. For example, when eglTerminate() was called, the
eglTerminate()'ing-Thread would "steal" the Context that was current on
another Thread to destroy it.
2.) A Display will only be fully terminated and its resources released
once all Contexts have been destroyed and are no longer current.
Otherwise, Display::terminate() will return if any Contexts are still in
use by a Thread.
EGL 1.5 Specification
3.2 Initialization
If contexts or surfaces, created with respect to dpy are current (see
section 3.7.3) to any thread, then they are not actually destroyed
while they remain current. If other resources created with respect to
dpy are in use by any current context or surface, then they are also
not destroyed until the corresponding context or surface is no longer
current.
With this fix, the app com.netmarble.sknightsmmo can start.
This also exposed an issue with GlslangFinalize(), since glslang can
only be initialized/finalized once per process. Otherwise, the
following EGL commands will call GlslangFinalize() without ever being
able to GlslangInitialize() again, leading to crashes since
GlslangFinalize() cleans up glslang for the entire process.
dpy1 = eglGetPlatformDisplay() |
eglInitialize(dpy1) | GlslangInitialize()
dpy2 = eglGetPlatformDisplay() |
eglInitialize(dpy2) | GlslangInitialize()
eglTerminate(dpy2) | GlslangFinalize()
eglInitialize(dpy1) | isInitialized() == true
Since Display::isInitialized() == true, the rest of
Display::initialize() is skipped and GlslangInitialize() is not called.
Later, the next test that attempts to compile a program will crash due
to glslang no longer being initialized.
Finally, this exposed the following tests leaking EGLContext handles:
- EGLSurfaceTest::initializeContext()
- EGLContextSharingTest.DisplayShareGroupContextCreation
- EGLCreateContextAttribsTest.IMGContextPriorityExtension
- EGLMultiContextTest.TestContextDestroySimple
Other tests were failing to reset the context, preventing the Display
from being terminated since there were still references to Contexts
owned by the display:
eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
Bug: angleproject:6208
Bug: angleproject:6304
Bug: angleproject:6322
Test: EGLContextSharingTest.EglTerminateMultiThreaded
Test: EGLContextSharingTestNoFixture.EglDestoryContextManyTimesSameContext
Test: Load com.netmarble.sknightsmmo
Change-Id: I160922af93db6cabe0ed396be77762fa8dfc7656
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3046961
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Tim Van Patten <timvp@google.com>
|