Skip to content

Commit

Permalink
Add new flag to allow using SwANGLE as WebGL fallback
Browse files Browse the repository at this point in the history
Currently, Chrome uses legacy SwiftShader GL as the WebGL fallback when
a hardware GPU isn't usable for the purpuse of rendering WebGL content.

As we're in the process of changing legacy SwiftShader GL to SwANGLE,
this CL adds a new flag which allows using SwANGLE for WebGL only.

To clarify, current switches with legacy SwiftShader GL:
Software GL: --use-gl=swiftshader
Software WebGL only: --use-gl=swiftshader-webgl

With SwANGLE, the new switches will be:
Software GL: --use-gl=angle --use-angle=swiftshader
Software WebGL only: --use-gl=angle --use-angle=swiftshader-webgl

Bug: chromium:1060139
Change-Id: I8d0382ac3a12c1578dfc0e62fc1949a0a9c66bd7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2845229
Commit-Queue: Alexis Hétu <sugoi@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Jonah Ryan-Davis <jonahr@google.com>
Cr-Commit-Position: refs/heads/master@{#876794}
  • Loading branch information
sugoi1 authored and Chromium LUCI CQ committed Apr 27, 2021
1 parent da7eb09 commit d20ff67
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 3 deletions.
39 changes: 39 additions & 0 deletions docs/gpu/swiftshader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Using Chromium with SwiftShader

SwiftShader is an open-source high-performance implementation of the Vulkan and OpenGL ES graphics APIs which runs purely on the CPU. Thus no graphics processor (GPU) is required for advanced (3D) graphics.

Chromium uses SwiftShader in two different ways:

1) **As the OpenGL ES driver**

When Chromium uses SwiftShader as the OpenGL ES driver, Chromium behaves as if it was running a on regular GPU, while actually running on SwiftShader. This allows Chromium to exercise hardware only code paths on GPU-less bots.

2) **As the WebGL fallback**

When Chromium uses SwiftShader as the WebGL fallback, Chromium runs in all software mode and only uses SwiftShader to render WebGL content.

SwiftShader also provides 2 different libraries:

1) **The legacy SwiftShader Open GL ES libraries**

Legacy SwiftShader includes a GLES library and an EGL library, in order to provide a complete solution to run OpenGL ES content.

*Do not use these libraries if possible, they are being phased out in favor of SwANGLE (ANGLE + SwiftShader Vulkan).*

2) **The SwiftShader Vulkan library**

SwiftShader Vulkan can be used both to render Vulkan content directly, or OpenGL ES content when use in conjunction with the ANGLE library.

## Relevant Chromium command line switches

When running the **chrome** executable from the command line, SwiftShader can be enabled using the following Switches:
1) As the OpenGL ES driver, SwANGLE (ANGLE + SwiftShader Vulkan)
>**\-\-use-gl=angle \-\-use-angle=swiftshader**
2) As the WebGL fallback, SwANGLE (ANGLE + SwiftShader Vulkan)
>**\-\-use-gl=angle \-\-use-angle=swiftshader-webgl**
3) As the OpenGL ES driver, legacy SwiftShader Open GL ES libraries
> **\-\-use-gl=swiftshader**
4) As the WebGL fallback, legacy SwiftShader Open GL ES libraries
>**\-\-use-gl=swiftshader-webgl**
5) As the Vulkan driver (requires the [enable_swiftshader_vulkan](https://source.chromium.org/chromium/chromium/src/+/master:gpu/vulkan/features.gni;l=16) feature)
>**--use-vulkan=swiftshader**
4 changes: 3 additions & 1 deletion gpu/command_buffer/service/feature_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ void FeatureInfo::InitializeBasicState(const base::CommandLine* command_line) {
const auto useANGLE = command_line->GetSwitchValueASCII(switches::kUseANGLE);

feature_flags_.is_swiftshader_for_webgl =
(useGL == gl::kGLImplementationSwiftShaderForWebGLName);
(useGL == gl::kGLImplementationSwiftShaderForWebGLName) ||
((useGL == gl::kGLImplementationANGLEName) &&
(useANGLE == gl::kANGLEImplementationSwiftShaderForWebGLName));

// The shader translator is needed to translate from WebGL-conformant GLES SL
// to normal GLES SL, enforce WebGL conformance, translate from GLES SL 1.0 to
Expand Down
2 changes: 2 additions & 0 deletions gpu/config/gpu_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ GpuFeatureInfo ComputeGpuFeatureInfo(const GPUInfo& gpu_info,
command_line->GetSwitchValueASCII(switches::kUseANGLE);
if (use_angle == gl::kANGLEImplementationSwiftShaderName)
use_swift_shader = true;
else if (use_angle == gl::kANGLEImplementationSwiftShaderForWebGLName)
return ComputeGpuFeatureInfoForSwiftShader();
}
} else if (use_gl == gl::kGLImplementationSwiftShaderForWebGLName)
return ComputeGpuFeatureInfoForSwiftShader();
Expand Down
7 changes: 6 additions & 1 deletion gpu/ipc/service/gpu_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,13 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
// In SwiftShader case, the implementation is actually EGLGLES2.
if (!gl_use_swiftshader_ && command_line->HasSwitch(switches::kUseGL)) {
std::string use_gl = command_line->GetSwitchValueASCII(switches::kUseGL);
std::string use_angle =
command_line->GetSwitchValueASCII(switches::kUseANGLE);
if (use_gl == gl::kGLImplementationSwiftShaderName ||
use_gl == gl::kGLImplementationSwiftShaderForWebGLName) {
use_gl == gl::kGLImplementationSwiftShaderForWebGLName ||
(use_gl == gl::kGLImplementationANGLEName &&
(use_angle == gl::kANGLEImplementationSwiftShaderName ||
use_angle == gl::kANGLEImplementationSwiftShaderForWebGLName))) {
gl_use_swiftshader_ = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion ui/gl/gl_surface_egl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,8 @@ void GetEGLInitDisplays(bool supports_angle_d3d,
}

if (supports_angle_swiftshader) {
if (requested_renderer == kANGLEImplementationSwiftShaderName) {
if (requested_renderer == kANGLEImplementationSwiftShaderName ||
requested_renderer == kANGLEImplementationSwiftShaderForWebGLName) {
AddInitDisplay(init_displays, ANGLE_SWIFTSHADER);
}
}
Expand Down
1 change: 1 addition & 0 deletions ui/gl/gl_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const char kANGLEImplementationOpenGLESEGLName[] = "gles-egl";
const char kANGLEImplementationNullName[] = "null";
const char kANGLEImplementationVulkanName[] = "vulkan";
const char kANGLEImplementationSwiftShaderName[] = "swiftshader";
const char kANGLEImplementationSwiftShaderForWebGLName[] = "swiftshader-webgl";
const char kANGLEImplementationMetalName[] = "metal";
const char kANGLEImplementationNoneName[] = "";

Expand Down
1 change: 1 addition & 0 deletions ui/gl/gl_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ GL_EXPORT extern const char kANGLEImplementationOpenGLESEGLName[];
GL_EXPORT extern const char kANGLEImplementationNullName[];
GL_EXPORT extern const char kANGLEImplementationVulkanName[];
GL_EXPORT extern const char kANGLEImplementationSwiftShaderName[];
GL_EXPORT extern const char kANGLEImplementationSwiftShaderForWebGLName[];
GL_EXPORT extern const char kANGLEImplementationMetalName[];
GL_EXPORT extern const char kANGLEImplementationNoneName[];

Expand Down

0 comments on commit d20ff67

Please sign in to comment.