A conformant OpenGL ES implementation for Windows, Mac and Linux.
Перейти к файлу
Igor Nazarov 36c3e0f546 Implement "Shared Context Mutex" functionality.
Existing implementation uses single `GlobalMutex` for
- EGL calls
- GL calls for Contexts with concurrent access.

This CL introduces abstract `egl::ContextMutex` with two
implementations:
- SingleContextMutex;
- SharedContextMutex<Mutex>;

Note:
`std::mutex` is used in this commit. It is very easy to change mutex
type either at compile-time or at run-time (single type per Display).

When Context:
- is not Shared;
- does not use `EGLImage`s;
- does not use EGL_DISPLAY_TEXTURE_SHARE_GROUP_ANGLE
- does not use EGL_DISPLAY_SEMAPHORE_SHARE_GROUP_ANGLE
then it will be using `SingleContextMutex` with minimal overhead.

Before such Context is used as `shareContext` or uses `EGLImage`
its mutex replaced by `SharedContextMutex<Mutex>`.

The `GlobalMutex` is only used for EGL calls, while `egl::ContextMutex`
implementations for GL calls. Because some EGL calls use Context,
explicit `egl::ContextMutex` lock is required. This is implemented by
generating "egl_context_mutex_autogen.h" header, and insertion of
`ANGLE_EGL_SCOPED_CONTEXT_LOCK()` macro before `ANGLE_EGL_VALIDATE()`
in each EGL entry point. Implementation in "egl_context_lock_impl.h"
returns lock for required APIs. Special cases of `egl::ContextMutex`
lock handled separately. `std::unique_lock<>` is not used for
performance reasons.

`egl::ContextMutex` explicitly locked when capturing EGL calls.

Fixes EGLImage problem:
    e18240d136
    Mark contexts as shared when importing EGL images.

Details:
- EGLImage inherits Context's mutex when created.
  Mutex is used when the EGLImage accessed or destroyed.
- When EGLImage is used in Context with other `egl::ContextMutex`,
  two mutexes are merged into one.
- After the mutex merge, Context Groups will remain separate,
  but will not be able to run in parallel.

Fixes race when checking `context->isShared()` in the
`SCOPED_SHARE_CONTEXT_LOCK()` macro. One Context may start executing GL
call while not "Shared", but become "Shared" inside the call. New
(second) "Shared" Context may immediately start using GL and potentially
corrupt some "Shared" state.

Possible performance benefit: allows parallel execution in some cases,
when single `GlobalMutex` would block.

Important note:
    Process of replacing the `SingleContextMutex` by
    `SharedContextMutex<Mutex>` is not 100% safe. This mean that
    original Context may still be using `SingleContextMutex` after
    activating `SharedContextMutex<Mutex>`. However, this was always
    the case before introduction of this CL. Old `Context::mShared`
    member update was not synchronized in any way at all. In other
    words, this solution does not 100% fix the original problem.
    For 100% safe solution `SingleContextMutex` should not be used
    (always pass `SharedContextMutex<Mutex>` to the `gl::Context`
    constructor). See `lockAndActivateSharedContextMutex()` for more
    details.

CL adds new build option:
    angle_enable_shared_context_mutex = true

Behavior with other build options:
- When:
    `angle_enable_shared_context_mutex`    is disabled or
    `angle_enable_share_context_lock`      is disabled or
    `angle_force_context_check_every_call` is enabled,
  Contexts will always have `SingleContextMutex`, however it will be
  only used in special cases. `SCOPED_SHARE_CONTEXT_LOCK()` will use
  `GlobalMutex` when applicable.
- Otherwise, `SCOPED_SHARE_CONTEXT_LOCK()` will use `egl::ContextMutex`.

Some GFXBench "1080p Driver Overhead 2 Offscreen" performance numbers.
Tested on S906B (Samsung Galaxy S22+) on old ANGLE base:
    807c94ea85
    Capture/Replay: Adjust tests do adhere to capture limits

Each test result is an average frame number from 6 runs.

    SingleContextMutex                            6579 ( +0.13%)
    (old) GetContextLock() (mShared is false)     6570

Forced `mShared = true` or NOT using `SingleContextMutex`.

    SharedContextMutex<std::mutex> FORCE          5061 (-22.97%)
    (old) GetContextLock() FORCE                  4766 (-27.46%)

Bug: angleproject:6957
Bug: chromium:1336126
Change-Id: Idcd919f9d4bf482b9ae489bd8b4415ec96048e32
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4374545
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
2023-06-14 16:59:15 +00:00
android Removing deprecated generate_final_jni which is being deleted 2023-05-30 14:31:43 +00:00
build_overrides Use C++20 for MSVC builds as well 2023-02-27 20:33:05 +00:00
doc Add polygon mode extension stubs 2023-05-01 21:21:01 +00:00
extensions Allow glDelete* while PLS is active 2023-05-19 05:26:28 +00:00
gni Reland "Remove SPIRV_METAL references from .gn and tests" 2023-06-06 19:19:08 +00:00
include Disable hashes for ANGLE features generator 2023-06-12 22:14:32 +00:00
infra Android: Assert that CFI is disabled 2023-06-12 15:57:27 +00:00
samples Add trace_interface: functions and callbacks for traces 2023-06-08 20:06:15 +00:00
scripts Implement "Shared Context Mutex" functionality. 2023-06-14 16:59:15 +00:00
src Implement "Shared Context Mutex" functionality. 2023-06-14 16:59:15 +00:00
third_party Roll Chromium from d6f22a2a164b to 9e0b5e8b8a85 (1063 revisions) 2023-06-06 14:52:52 +00:00
tools Add all of tools/android to DEPS 2023-06-02 15:38:57 +00:00
util Disable clang-format on ANGLE features autogen outputs 2023-06-12 17:52:18 +00:00
.clang-format Update .clang-format. 2020-04-28 14:23:13 +00:00
.gitattributes infra: Trigger win-trace on angle_end2end_tests changes. 2021-11-26 20:53:49 +00:00
.gitignore Fix gitignore entries to ignore android_toolchain 2023-06-08 13:35:45 +00:00
.gn Roll Chromium from c83e966b4c7e to f7c2a70f23b1 (1902 revisions) 2023-03-29 19:36:29 +00:00
.style.yapf Update yapf style from "chromium" to "yapf" 2023-02-24 03:03:40 +00:00
.vpython Remove reference to policy_testserver.py 2022-02-15 16:18:29 +00:00
.vpython3 Update vpython3 requests 2023-06-02 13:38:24 +00:00
.yapfignore Add .yapfignore file 2019-10-14 17:57:09 +00:00
AUTHORS [riscv64][android] support 64-bit builds on riscv64 2023-05-17 01:16:21 +00:00
Android.mk Remove .find_ignore files 2021-05-20 18:35:26 +00:00
BUILD.gn Implement "Shared Context Mutex" functionality. 2023-06-14 16:59:15 +00:00
CONTRIBUTORS [riscv64][android] support 64-bit builds on riscv64 2023-05-17 01:16:21 +00:00
DEPS Roll vulkan-deps from 701c5daafb72 to cebf5626ca50 (30 revisions) 2023-06-14 10:56:48 +00:00
DIR_METADATA Move metadata in OWNERS files to DIR_METADATA files 2021-02-04 19:09:11 +00:00
LICENSE Update license and readme for use downstream 2018-03-27 20:53:53 +00:00
OWNERS Add srisser 2023-01-06 18:36:26 +00:00
PRESUBMIT.py Add kwargs to specialized error message 2023-06-06 17:06:23 +00:00
README.chromium Update license and readme for use downstream 2018-03-27 20:53:53 +00:00
README.md Update README about GLES1 2023-01-11 22:39:57 +00:00
WATCHLISTS WATCHLISTS: Remove timvp@ from 'vulkan' 2022-03-03 15:13:09 +00:00
additional_readme_paths.json Remove obsolete additional_readme_paths.json entries 2023-02-23 15:04:50 +00:00
codereview.settings Use "full" git cl format by default. 2019-10-24 23:14:12 +00:00
dotfile_settings.gni Remove Vulkan repos from exec script whitelist. 2019-10-20 16:26:45 +00:00

README.md

ANGLE - Almost Native Graphics Layer Engine

The goal of ANGLE is to allow users of multiple operating systems to seamlessly run WebGL and other OpenGL ES content by translating OpenGL ES API calls to one of the hardware-supported APIs available for that platform. ANGLE currently provides translation from OpenGL ES 2.0, 3.0 and 3.1 to Vulkan, desktop OpenGL, OpenGL ES, Direct3D 9, and Direct3D 11. Future plans include ES 3.2, translation to Metal and MacOS, Chrome OS, and Fuchsia support.

Level of OpenGL ES support via backing renderers

Direct3D 9 Direct3D 11 Desktop GL GL ES Vulkan Metal
OpenGL ES 2.0 complete complete complete complete complete complete
OpenGL ES 3.0 complete complete complete complete complete
OpenGL ES 3.1 incomplete complete complete complete
OpenGL ES 3.2 in progress in progress in progress

Additionally, OpenGL ES 1.1 is implemented in the front-end using OpenGL ES 3.0 features. This version of the specification is thus supported on all platforms specified above that support OpenGL ES 3.0 with known issues.

Platform support via backing renderers

Direct3D 9 Direct3D 11 Desktop GL GL ES Vulkan Metal
Windows complete complete complete complete complete
Linux complete complete
Mac OS X complete complete
iOS complete
Chrome OS complete planned
Android complete complete
GGP (Stadia) complete
Fuchsia complete

ANGLE v1.0.772 was certified compliant by passing the OpenGL ES 2.0.3 conformance tests in October 2011.

ANGLE has received the following certifications with the Vulkan backend:

  • OpenGL ES 2.0: ANGLE 2.1.0.d46e2fb1e341 (Nov, 2019)
  • OpenGL ES 3.0: ANGLE 2.1.0.f18ff947360d (Feb, 2020)
  • OpenGL ES 3.1: ANGLE 2.1.0.f5dace0f1e57 (Jul, 2020)

ANGLE also provides an implementation of the EGL 1.5 specification.

ANGLE is used as the default WebGL backend for both Google Chrome and Mozilla Firefox on Windows platforms. Chrome uses ANGLE for all graphics rendering on Windows, including the accelerated Canvas2D implementation and the Native Client sandbox environment.

Portions of the ANGLE shader compiler are used as a shader validator and translator by WebGL implementations across multiple platforms. It is used on Mac OS X, Linux, and in mobile variants of the browsers. Having one shader validator helps to ensure that a consistent set of GLSL ES shaders are accepted across browsers and platforms. The shader translator can be used to translate shaders to other shading languages, and to optionally apply shader modifications to work around bugs or quirks in the native graphics drivers. The translator targets Desktop GLSL, Vulkan GLSL, Direct3D HLSL, and even ESSL for native GLES2 platforms.

Sources

ANGLE repository is hosted by Chromium project and can be browsed online or cloned with

git clone https://chromium.googlesource.com/angle/angle

Building

View the Dev setup instructions.

Contributing