src/libANGLE/Thread.h


Log

Author Commit Date CI Message
Shahbaz Youssefi d193d51b 2024-06-17T22:46:08 Replace issue ids post migration to new issue tracker This change replaces anglebug.com/NNNN links. Bug: None Change-Id: I8ac3aec8d2a8a844b3d7b99fc0a6b2be8da31761 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5637912 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Igor Nazarov f1345d1c 2023-08-02T14:23:59 Call ReleaseThread() entry point from ThreadCleanupCallback Change relevant only for the Android platform. Fixes problems: 1. Current code calls `thread->setCurrent(nullptr)` in `Display::threadCleanup()` method, while not executing other code that will actually unmake Context from current. This will affect following EGL calls from the application's side in its own thread cleanup callback. For example, calls to `eglMakeCurrent()` (to unmake from current) or `eglReleaseThread()` will be no-op. This may lead to memory leak if context was previously marked for destruction. 2. The `Display::threadCleanup()` did not also clears the `CurrentValidContext`. This may cause crashes or other UB if an application will call some GLES API in its thread termination callback (for example `glFinish()`), if ANGLE already destroyed the context in its ThreadCleanupCallback (use after delete). 3. Context will remain current to a thread that terminated. Current implementation of GLES drivers on Mali/Adreno GPUs automatically unmade context from current, so the application may make this context current to some other thread. ANGLE should mimic this behavior to avoid possible bugs. All of the above problems may be fixed by simply calling from the ThreadCleanupCallback either: - MakeCurrent(t, d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) - ReleaseThread(t) This CL choose to call `ReleaseThread()` because this is the API that the application may call in its own thread cleanup callback. And if application's callback will be called later than ANGLE's callback, then application's `eglReleaseThread()` call we be a no-op. Even if the application does not have its own thread cleanup callback (like most of the applications), there is no harm to call `ReleaseThread()` anyway. The only difference with `MakeCurrent()` is that it will also cleanup invalid objects and some other memory depending on the backend. This CL naturally replaces existing logic with Display termination when there is no active threads thanks to the previous CL: "Perform Display terminate(InternalCleanup) from makeCurrent()". Bug: angleproject:6723 Bug: angleproject:8283 Test: angle_end2end_tests --gtest_filter=EGLContextSharingTest.ThreadCleanupCallback* Test: angle_end2end_tests --gtest_filter=EGLContextSharingTest.UnmakeFromCurrentOnThreadExit* Change-Id: I8c5b31f34f91c4bfdac165ac30c213ff5fef992e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4742383 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Igor Nazarov <i.nazarov@samsung.com>
Peng Huang b9fd47b8 2022-08-12T10:55:49 Not use Android TLS slot for chromium In the profile, GetGlobalContext() & GetValidGlobalContext() have extra overhead for checking angle::gUseAndroidOpenGLTlsSlot. Since angle::gUseAndroidOpenGLTlsSlot is always false for now, so add a build flag to disable it for chromium build. In the profile, with angle_use_android_tls_slot = false, GetValidGlobalContext() is reduced from 0.153% to 0.044%. Bug: chromium:1336126 Change-Id: Id5e1752b0a03289fb299e8de2ed6e962e35291c0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3827955 Reviewed-by: Geoff Lang <geofflang@chromium.org> Auto-Submit: Peng Huang <penghuang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
Mohan Maiya 12efe5b2 2022-06-21T15:43:42 Cleanup invalid EGL handles only if app called eglTermiate Maintain set of active threads instead of a global refCount and free display's invalid EGL resources iff - 1. app previously called eglTerminate on that display 2. there are no more active threads associated with that display Bug: angleproject:6723 Test: EGLMultiContextTest.RepeatedEglInitAndTerminate* Test: EGLMultiContextTest.ReuseUnterminatedDisplay* Change-Id: I868491bbbf0664e9129dcb0d1fa9e2243ef36d82 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3717277 Commit-Queue: mohan maiya <m.maiya@samsung.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Roman Lavrov <romanl@google.com>
Mohan Maiya 6c172e4b 2021-11-20T16:27:14 Add support for memory cleanup on process exit This patch adds a callback to cleanup memory on process exit. Bug: angleproject:6723 Test: Android CTS WrapperTest.testThreadCleanup Change-Id: Ia517d4c6ae280ddc1f17a3b6f77d437aaaad0678 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3294581 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Mohan Maiya <m.maiya@samsung.com>
Jamie Madill cfe14e28 2020-11-19T18:11:42 EGL: Remove egl::Error from validation code. Instead of using an egl::Error return value, errors are recorded on the egl::Thread immediately at the call site. This makes the code work the same way as in the GL entry points. Updates the EGL "try" macros to include a special handler for the EGL validation entry points. Uses a special ValidationContext helper class to preserve the existing info. Bug: angleproject:5378 Change-Id: I897f221a41fe406676950600e4ac559081b9f541 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2551790 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Tim Van Patten <timvp@google.com>
Jamie Madill cb286073 2020-09-20T21:59:24 Use c++ thread_local for current thread. This solves a race condition using the global context. Sadly we can't use an unprotected variable safely because it can be written/read from multiple threads doing MakeCurrent. Has about a 2 ns regression when tested in Linux/Release per call. "null" benchmark test went from 27 -> 29 ns/iteration. Fixes a TSAN warning that popped up in angle_end2end_tests. Test: DrawCallPerfBenchmark.Run/vulkan_null Test: EGLContextASANTest.DestroyContextInUse/ES3_Vulkan Bug: b/168744561 Change-Id: Ic56f3faae81c1087b942a3cfc0e011b9ab439e0f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2419641 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Stuart Morgan 9d737966 2019-08-14T12:25:12 Standardize copyright notices to project style For all "ANGLE Project" copyrights, standardize to the format specified by the style guide. Changes: - "Copyright (c)" and "Copyright(c)" changed to just "Copyright". - Removed the second half of date ranges ("Y1Y1-Y2Y2"->"Y1Y1"). - Fixed a small number of files that had no copyright date using the initial commit year from the version control history. - Fixed one instance of copyright being "The ANGLE Project" rather than "The ANGLE Project Authors" These changes are applied both to the copyright of source file, and where applicable to copyright statements that are generated by templates. BUG=angleproject:3811 Change-Id: I973dd65e4ef9deeba232d5be74c768256a0eb2e5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1754397 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi a254fa28 2019-04-09T14:25:59 Rename getCurrentDisplay to getDisplay There is always only one display that can be associated with a context, so get*Current*Display is confusing. Bug: None Change-Id: Iff3a9fc5ad1154b046bb30d7f46a468802ba7fcc Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1558958 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Geoff Lang 75359664 2018-04-11T01:42:27 Implement EGL_KHR_debug. BUG=angleproject:1618 Change-Id: I790944b49badc910b6c72266469fcb8e86ac4252 Reviewed-on: https://chromium-review.googlesource.com/1019387 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Jamie Madill 61e16b44 2017-06-19T11:13:23 Context: Bind current display/surface. Looking at the EGL spec, it says for eglGetCurrentDisplay: "The display for the current context in the calling thread, for the current rendering API, is returned." This implies that MakeCurrent binds a display to a Context. There's also pretty clear language for the read/draw Surface as well, that they can only be bound to one Context/thread at a time. Hence we don't need to duplicate this storage in the egl::Thread structure, merely storing a pointer to the current Context, which has access to the read/draw Surface and current Display. BUG=angleproject:1156 Change-Id: Ia3b99d50b3591012c43e851834c1af02ff62a33f Reviewed-on: https://chromium-review.googlesource.com/538865 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Geoff Lang 7b8f3c9b 2016-11-10T10:42:48 Encapsulate the thread local storage into an egl::Thread class. Instead of having separate GetGlobal* functions, interact with the global objects through a single Thread object. This reduces the number of TLS lookups in many EGL functions and allows the Thread object to be passed down to other objects if needed. BUG=angleproject:1618 Change-Id: I1f9a89e8899d637633f4e91fda0e38ac308dd020 Reviewed-on: https://chromium-review.googlesource.com/409637 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>