Commit 264eba9c authored by Alexis Hetu's avatar Alexis Hetu Committed by Commit Bot

SwiftShader WebGL fallback fix for MacOS

The SwiftShader library was failing to load properly when used as a WebGL
fallback because of a sandboxing issue. This cl works around that issue
by changing where the SwiftShader initializatin is done.

Credit to zmo@ for this fix, which I cherry picked from:
https://chromium-review.googlesource.com/c/chromium/src/+/1005017/20..21

Fixes:
gpu_tests.gpu_process_integration_test.GpuProcessIntegrationTest.GpuProcess_feature_status_under_swiftshader

Bug: chromium:726075
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I56a00cef70cb630bbf6d5fe7f342a8d5b1c2211d
Reviewed-on: https://chromium-review.googlesource.com/1042496
Commit-Queue: Alexis Hétu <sugoi@chromium.org>
Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556163}
parent 45ab3fe6
...@@ -51,16 +51,22 @@ base::OnceClosure MaybeWrapWithGPUSandboxHook( ...@@ -51,16 +51,22 @@ base::OnceClosure MaybeWrapWithGPUSandboxHook(
gpu::SwitchValueToGpuPreferences(value, &gpu_preferences); gpu::SwitchValueToGpuPreferences(value, &gpu_preferences);
CHECK(success); CHECK(success);
} }
bool needs_more_info = false;
gpu::GpuFeatureInfo gpu_feature_info = gpu::ComputeGpuFeatureInfo( gpu::GpuFeatureInfo gpu_feature_info = gpu::ComputeGpuFeatureInfo(
gpu_info, gpu_preferences.ignore_gpu_blacklist, gpu_info, gpu_preferences.ignore_gpu_blacklist,
gpu_preferences.disable_gpu_driver_bug_workarounds, gpu_preferences.disable_gpu_driver_bug_workarounds,
gpu_preferences.log_gpu_control_list_decisions, command_line, gpu_preferences.log_gpu_control_list_decisions, command_line,
nullptr); &needs_more_info);
gpu::CacheGpuFeatureInfo(gpu_feature_info); gpu::CacheGpuFeatureInfo(gpu_feature_info);
if (gpu::SwitchableGPUsSupported(gpu_info, *command_line)) { if (gpu::SwitchableGPUsSupported(gpu_info, *command_line)) {
gpu::InitializeSwitchableGPUs( gpu::InitializeSwitchableGPUs(
gpu_feature_info.enabled_gpu_driver_bug_workarounds); gpu_feature_info.enabled_gpu_driver_bug_workarounds);
} }
// Calling ShouldEnableSwiftShader will append the proper command line
// switch in order to enable SwiftShader if required.
gpu::ShouldEnableSwiftShader(
command_line, gpu_feature_info,
gpu_preferences.disable_software_rasterizer, needs_more_info);
// Preload either the desktop GL or the osmesa so, depending on the // Preload either the desktop GL or the osmesa so, depending on the
// --use-gl flag. // --use-gl flag.
gl::init::InitializeGLOneOff(); gl::init::InitializeGLOneOff();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "gpu/config/gpu_blacklist.h" #include "gpu/config/gpu_blacklist.h"
#include "gpu/config/gpu_crash_keys.h" #include "gpu/config/gpu_crash_keys.h"
#include "gpu/config/gpu_driver_bug_list.h" #include "gpu/config/gpu_driver_bug_list.h"
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
#include "gpu/config/gpu_info_collector.h" #include "gpu/config/gpu_info_collector.h"
#include "gpu/config/gpu_switches.h" #include "gpu/config/gpu_switches.h"
#include "ui/gl/extension_set.h" #include "ui/gl/extension_set.h"
#include "ui/gl/gl_features.h"
#include "ui/gl/gl_switches.h" #include "ui/gl/gl_switches.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -481,4 +483,27 @@ bool InitializeGLThreadSafe(base::CommandLine* command_line, ...@@ -481,4 +483,27 @@ bool InitializeGLThreadSafe(base::CommandLine* command_line,
} }
#endif // OS_ANDROID #endif // OS_ANDROID
bool ShouldEnableSwiftShader(base::CommandLine* command_line,
const GpuFeatureInfo& gpu_feature_info,
bool disable_software_rasterizer,
bool blacklist_needs_more_info) {
#if BUILDFLAG(ENABLE_SWIFTSHADER)
if (disable_software_rasterizer)
return false;
// Don't overwrite user preference.
if (command_line->HasSwitch(switches::kUseGL))
return false;
if (!blacklist_needs_more_info &&
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGL] !=
kGpuFeatureStatusEnabled) {
command_line->AppendSwitchASCII(
switches::kUseGL, gl::kGLImplementationSwiftShaderForWebGLName);
return true;
}
return false;
#else
return false;
#endif
}
} // namespace gpu } // namespace gpu
...@@ -68,6 +68,13 @@ GPU_EXPORT bool InitializeGLThreadSafe(base::CommandLine* command_line, ...@@ -68,6 +68,13 @@ GPU_EXPORT bool InitializeGLThreadSafe(base::CommandLine* command_line,
GpuFeatureInfo* out_gpu_feature_info); GpuFeatureInfo* out_gpu_feature_info);
#endif // OS_ANDROID #endif // OS_ANDROID
// Returns whether SwiftShader should be enabled. If true, the proper command
// line switch to enable SwiftShader will be appended to 'command_line'.
GPU_EXPORT bool ShouldEnableSwiftShader(base::CommandLine* command_line,
const GpuFeatureInfo& gpu_feature_info,
bool disable_software_rasterizer,
bool blacklist_needs_more_info);
} // namespace gpu } // namespace gpu
#endif // GPU_CONFIG_GPU_UTIL_H_ #endif // GPU_CONFIG_GPU_UTIL_H_
...@@ -123,6 +123,8 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line, ...@@ -123,6 +123,8 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
#endif // !OS_ANDROID && !IS_CHROMECAST #endif // !OS_ANDROID && !IS_CHROMECAST
gpu_info_.in_process_gpu = false; gpu_info_.in_process_gpu = false;
bool use_swiftshader = false;
// GL bindings may have already been initialized, specifically on MacOSX. // GL bindings may have already been initialized, specifically on MacOSX.
bool gl_initialized = gl::GetGLImplementation() != gl::kGLImplementationNone; bool gl_initialized = gl::GetGLImplementation() != gl::kGLImplementationNone;
if (!gl_initialized) { if (!gl_initialized) {
...@@ -131,6 +133,10 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line, ...@@ -131,6 +133,10 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
gpu::InitializeSwitchableGPUs( gpu::InitializeSwitchableGPUs(
gpu_feature_info_.enabled_gpu_driver_bug_workarounds); gpu_feature_info_.enabled_gpu_driver_bug_workarounds);
} }
} else if (gl::GetGLImplementation() == gl::kGLImplementationSwiftShaderGL &&
command_line->GetSwitchValueASCII(switches::kUseGL) !=
gl::kGLImplementationSwiftShaderName) {
use_swiftshader = true;
} }
bool enable_watchdog = !gpu_preferences.disable_gpu_watchdog && bool enable_watchdog = !gpu_preferences.disable_gpu_watchdog &&
...@@ -194,8 +200,13 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line, ...@@ -194,8 +200,13 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
ui::OzonePlatform::InitializeForGPU(params); ui::OzonePlatform::InitializeForGPU(params);
#endif #endif
bool use_swiftshader = ShouldEnableSwiftShader(command_line, needs_more_info); if (!use_swiftshader) {
if (gl_initialized && use_swiftshader) { use_swiftshader = ShouldEnableSwiftShader(
command_line, gpu_feature_info_,
gpu_preferences.disable_software_rasterizer, needs_more_info);
}
if (gl_initialized && use_swiftshader &&
gl::GetGLImplementation() != gl::kGLImplementationSwiftShaderGL) {
gl::init::ShutdownGL(true); gl::init::ShutdownGL(true);
gl_initialized = false; gl_initialized = false;
} }
...@@ -222,7 +233,9 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line, ...@@ -222,7 +233,9 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
gpu_info_, gpu_preferences.ignore_gpu_blacklist, gpu_info_, gpu_preferences.ignore_gpu_blacklist,
gpu_preferences.disable_gpu_driver_bug_workarounds, gpu_preferences.disable_gpu_driver_bug_workarounds,
gpu_preferences.log_gpu_control_list_decisions, command_line, nullptr); gpu_preferences.log_gpu_control_list_decisions, command_line, nullptr);
use_swiftshader = ShouldEnableSwiftShader(command_line, false); use_swiftshader = ShouldEnableSwiftShader(
command_line, gpu_feature_info_,
gpu_preferences.disable_software_rasterizer, false);
if (use_swiftshader) { if (use_swiftshader) {
gl::init::ShutdownGL(true); gl::init::ShutdownGL(true);
if (!gl::init::InitializeGLNoExtensionsOneOff()) { if (!gl::init::InitializeGLNoExtensionsOneOff()) {
...@@ -304,7 +317,9 @@ void GpuInit::InitializeInProcess(base::CommandLine* command_line, ...@@ -304,7 +317,9 @@ void GpuInit::InitializeInProcess(base::CommandLine* command_line,
const GpuPreferences& gpu_preferences) { const GpuPreferences& gpu_preferences) {
gpu_preferences_ = gpu_preferences; gpu_preferences_ = gpu_preferences;
init_successful_ = true; init_successful_ = true;
DCHECK(!ShouldEnableSwiftShader(command_line, false)); DCHECK(!ShouldEnableSwiftShader(command_line, gpu_feature_info_,
gpu_preferences.disable_software_rasterizer,
false));
InitializeGLThreadSafe(command_line, gpu_preferences.ignore_gpu_blacklist, InitializeGLThreadSafe(command_line, gpu_preferences.ignore_gpu_blacklist,
gpu_preferences.disable_gpu_driver_bug_workarounds, gpu_preferences.disable_gpu_driver_bug_workarounds,
...@@ -346,7 +361,9 @@ void GpuInit::InitializeInProcess(base::CommandLine* command_line, ...@@ -346,7 +361,9 @@ void GpuInit::InitializeInProcess(base::CommandLine* command_line,
} }
#endif // !IS_CHROMECAST #endif // !IS_CHROMECAST
bool use_swiftshader = ShouldEnableSwiftShader(command_line, needs_more_info); bool use_swiftshader = ShouldEnableSwiftShader(
command_line, gpu_feature_info_,
gpu_preferences.disable_software_rasterizer, needs_more_info);
if (!gl::init::InitializeGLNoExtensionsOneOff()) { if (!gl::init::InitializeGLNoExtensionsOneOff()) {
VLOG(1) << "gl::init::InitializeGLNoExtensionsOneOff failed"; VLOG(1) << "gl::init::InitializeGLNoExtensionsOneOff failed";
return; return;
...@@ -359,7 +376,9 @@ void GpuInit::InitializeInProcess(base::CommandLine* command_line, ...@@ -359,7 +376,9 @@ void GpuInit::InitializeInProcess(base::CommandLine* command_line,
gpu_info_, gpu_preferences.ignore_gpu_blacklist, gpu_info_, gpu_preferences.ignore_gpu_blacklist,
gpu_preferences.disable_gpu_driver_bug_workarounds, gpu_preferences.disable_gpu_driver_bug_workarounds,
gpu_preferences.log_gpu_control_list_decisions, command_line, nullptr); gpu_preferences.log_gpu_control_list_decisions, command_line, nullptr);
use_swiftshader = ShouldEnableSwiftShader(command_line, false); use_swiftshader = ShouldEnableSwiftShader(
command_line, gpu_feature_info_,
gpu_preferences.disable_software_rasterizer, false);
if (use_swiftshader) { if (use_swiftshader) {
gl::init::ShutdownGL(true); gl::init::ShutdownGL(true);
if (!gl::init::InitializeGLNoExtensionsOneOff()) { if (!gl::init::InitializeGLNoExtensionsOneOff()) {
...@@ -387,27 +406,6 @@ void GpuInit::InitializeInProcess(base::CommandLine* command_line, ...@@ -387,27 +406,6 @@ void GpuInit::InitializeInProcess(base::CommandLine* command_line,
} }
#endif // OS_ANDROID #endif // OS_ANDROID
bool GpuInit::ShouldEnableSwiftShader(base::CommandLine* command_line,
bool blacklist_needs_more_info) {
#if BUILDFLAG(ENABLE_SWIFTSHADER)
if (gpu_preferences_.disable_software_rasterizer)
return false;
// Don't overwrite user preference.
if (command_line->HasSwitch(switches::kUseGL))
return false;
if (!blacklist_needs_more_info &&
gpu_feature_info_.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGL] !=
kGpuFeatureStatusEnabled) {
command_line->AppendSwitchASCII(
switches::kUseGL, gl::kGLImplementationSwiftShaderForWebGLName);
return true;
}
return false;
#else
return false;
#endif
}
void GpuInit::AdjustInfoToSwiftShader() { void GpuInit::AdjustInfoToSwiftShader() {
gpu_info_for_hardware_gpu_ = gpu_info_; gpu_info_for_hardware_gpu_ = gpu_info_;
gpu_feature_info_for_hardware_gpu_ = gpu_feature_info_; gpu_feature_info_for_hardware_gpu_ = gpu_feature_info_;
......
...@@ -74,8 +74,6 @@ class GPU_IPC_SERVICE_EXPORT GpuInit { ...@@ -74,8 +74,6 @@ class GPU_IPC_SERVICE_EXPORT GpuInit {
base::Optional<GPUInfo> gpu_info_for_hardware_gpu_; base::Optional<GPUInfo> gpu_info_for_hardware_gpu_;
base::Optional<GpuFeatureInfo> gpu_feature_info_for_hardware_gpu_; base::Optional<GpuFeatureInfo> gpu_feature_info_for_hardware_gpu_;
bool ShouldEnableSwiftShader(base::CommandLine* command_line,
bool blacklist_needs_more_info);
void AdjustInfoToSwiftShader(); void AdjustInfoToSwiftShader();
void AdjustInfoToNoGpu(); void AdjustInfoToNoGpu();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment