Commit ff5eab5c authored by Alexis Hetu's avatar Alexis Hetu Committed by Commit Bot

Enable Swiftshader on MacOS

This cl enables experimental support for SwiftShader on MacOS. It is
still disabled by default since use_egl_on_mac is still false in
ui/gl/features.gni.

Bug: 726075
Cq-Include-Trybots: luci.chromium.try:linux_optional_gpu_tests_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I01093a2203a94d05e0588ff1deeb8016848d82b9
Reviewed-on: https://chromium-review.googlesource.com/955949
Commit-Queue: Alexis Hétu <sugoi@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544185}
parent ed208302
......@@ -968,10 +968,11 @@ if (is_win) {
}
if (use_egl) {
# We need to copy the ANGLE libraries so that the bundle_data dependencies
# have a "copy" target type. Otherwise for "shared_library" target types
# it will try to link things into Chromium Framework when we want to keep
# the ANGLE libraries separate instead.
# We need to copy the ANGLE and SwiftShader libraries so that the
# bundle_data dependencies have a "copy" target type. Otherwise for
# "shared_library" target types it will try to link things into
# Chromium Framework when we want to keep the ANGLE and SwiftShader
# libraries separate instead.
copy("angle_library_copy") {
sources = [
"$root_out_dir/libEGL.dylib",
......@@ -999,6 +1000,34 @@ if (is_win) {
":angle_library_copy",
]
}
copy("swiftshader_library_copy") {
sources = [
"$root_out_dir/libswiftshader_libEGL.dylib",
"$root_out_dir/libswiftshader_libGLESv2.dylib",
]
outputs = [
"$root_out_dir/egl_intermediates/{{source_file_part}}",
]
deps = [
"//third_party/swiftshader/src/OpenGL/libEGL:swiftshader_libEGL",
"//third_party/swiftshader/src/OpenGL/libGLESv2:swiftshader_libGLESv2",
]
}
# Add the SwiftShader .dylibs in the MODULE_DIR of Chromium.app
bundle_data("swiftshader_binaries") {
sources = [
"$root_out_dir/egl_intermediates/libswiftshader_libEGL.dylib",
"$root_out_dir/egl_intermediates/libswiftshader_libGLESv2.dylib",
]
outputs = [
"{{bundle_contents_dir}}/Libraries/{{source_file_part}}",
]
public_deps = [
":swiftshader_library_copy",
]
}
}
group("angle_library") {
......@@ -1009,6 +1038,14 @@ if (is_win) {
}
}
group("swiftshader_library") {
if (use_egl) {
deps = [
":swiftshader_binaries",
]
}
}
_should_bundle_widevine =
(is_chrome_branded || enable_widevine) && enable_library_cdms
if (_should_bundle_widevine) {
......@@ -1288,6 +1325,7 @@ if (is_win) {
":chrome_framework_resources",
":chrome_framework_services",
":packed_resources",
":swiftshader_library",
":widevine_cdm_library",
"//build/config:exe_and_shlib_deps",
"//chrome/app/nibs:chrome_xibs",
......
......@@ -54,6 +54,7 @@ scoped_refptr<gl::GLSurface> ImageTransportSurface::CreateNativeSurface(
case gl::kGLImplementationDesktopGLCoreProfile:
case gl::kGLImplementationAppleGL:
case gl::kGLImplementationEGLGLES2:
case gl::kGLImplementationSwiftShaderGL:
return base::WrapRefCounted<gl::GLSurface>(
new ImageTransportSurfaceOverlayMac(delegate));
case gl::kGLImplementationMockGL:
......
......@@ -11,7 +11,8 @@ import("//ui/ozone/ozone.gni")
import("//testing/test.gni")
declare_args() {
enable_swiftshader = (is_win || (is_linux && use_x11) ||
enable_swiftshader =
(is_win || (is_linux && use_x11) || (is_mac && use_egl) ||
(is_chromeos && ozone_platform_x11)) &&
(target_cpu == "x86" || target_cpu == "x64")
}
......@@ -332,6 +333,7 @@ component("gl") {
data_deps += [
"//third_party/angle:libEGL",
"//third_party/angle:libGLESv2",
"//third_party/swiftshader",
]
}
}
......
......@@ -182,7 +182,8 @@ GLenum ConvertRequestedInternalFormat(GLenum internalformat) {
GLImageIOSurface* GLImageIOSurface::Create(const gfx::Size& size,
unsigned internalformat) {
#if BUILDFLAG(USE_EGL_ON_MAC)
if (GLContext::GetCurrent()->GetVersionInfo()->is_angle) {
if (GLContext::GetCurrent()->GetVersionInfo()->is_angle ||
GLContext::GetCurrent()->GetVersionInfo()->is_swiftshader) {
return new GLImageIOSurfaceEGL(size, internalformat);
}
#endif // BUILDFLAG(USE_EGL_ON_MAC)
......
......@@ -67,6 +67,7 @@ std::vector<GLImplementation> GetAllowedGLImplementations() {
impls.push_back(kGLImplementationDesktopGLCoreProfile);
#if BUILDFLAG(USE_EGL_ON_MAC)
impls.push_back(kGLImplementationEGLGLES2);
impls.push_back(kGLImplementationSwiftShaderGL);
#endif // BUILDFLAG(USE_EGL_ON_MAC)
impls.push_back(kGLImplementationDesktopGL);
impls.push_back(kGLImplementationAppleGL);
......@@ -90,6 +91,7 @@ scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group,
compatible_surface, attribs);
#if BUILDFLAG(USE_EGL_ON_MAC)
case kGLImplementationEGLGLES2:
case kGLImplementationSwiftShaderGL:
return InitializeGLContext(new GLContextEGL(share_group),
compatible_surface, attribs);
#endif // BUILDFLAG(USE_EGL_ON_MAC)
......@@ -116,7 +118,8 @@ scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) {
case kGLImplementationDesktopGL:
case kGLImplementationDesktopGLCoreProfile:
case kGLImplementationAppleGL:
case kGLImplementationEGLGLES2: {
case kGLImplementationEGLGLES2:
case kGLImplementationSwiftShaderGL: {
NOTIMPLEMENTED() << "No onscreen support on Mac.";
return nullptr;
}
......@@ -147,6 +150,7 @@ scoped_refptr<GLSurface> CreateOffscreenGLSurfaceWithFormat(
new NoOpGLSurface(size), format);
#if BUILDFLAG(USE_EGL_ON_MAC)
case kGLImplementationEGLGLES2:
case kGLImplementationSwiftShaderGL:
if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() &&
size.width() == 0 && size.height() == 0) {
return InitializeGLSurfaceWithFormat(new SurfacelessEGL(size), format);
......
......@@ -137,23 +137,36 @@ bool InitializeStaticCGLInternal(GLImplementation implementation) {
const char kGLESv2ANGLELibraryName[] = "Libraries/libGLESv2.dylib";
const char kEGLANGLELibraryName[] = "Libraries/libEGL.dylib";
const char kGLESv2SwiftShaderLibraryName[] =
"Libraries/libswiftshader_libGLESv2.dylib";
const char kEGLSwiftShaderLibraryName[] =
"Libraries/libswiftshader_libEGL.dylib";
bool InitializeStaticEGLInternal(GLImplementation implementation) {
if (implementation == kGLImplementationSwiftShaderGL) {
base::FilePath module_path;
if (!PathService::Get(base::DIR_MODULE, &module_path)) {
return false;
}
base::FilePath module_path;
if (!PathService::Get(base::DIR_MODULE, &module_path)) {
base::FilePath glesv2_path;
base::FilePath egl_path;
if (implementation == kGLImplementationSwiftShaderGL) {
#if BUILDFLAG(ENABLE_SWIFTSHADER)
glesv2_path = module_path.Append(kGLESv2SwiftShaderLibraryName);
egl_path = module_path.Append(kEGLSwiftShaderLibraryName);
#else
return false;
#endif
} else {
glesv2_path = module_path.Append(kGLESv2ANGLELibraryName);
egl_path = module_path.Append(kEGLANGLELibraryName);
}
base::FilePath glesv2_path = module_path.Append(kGLESv2ANGLELibraryName);
base::NativeLibrary gles_library = LoadLibraryAndPrintError(glesv2_path);
if (!gles_library) {
return false;
}
base::FilePath egl_path = module_path.Append(kEGLANGLELibraryName);
base::NativeLibrary egl_library = LoadLibraryAndPrintError(egl_path);
if (!egl_library) {
base::UnloadNativeLibrary(gles_library);
......@@ -172,9 +185,11 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) {
}
SetGLGetProcAddressProc(get_proc_address);
AddGLNativeLibrary(egl_library);
// FIXME: SwiftShader must load symbols from libGLESv2 before libEGL on MacOS
// currently
AddGLNativeLibrary(gles_library);
SetGLImplementation(kGLImplementationEGLGLES2);
AddGLNativeLibrary(egl_library);
SetGLImplementation(implementation);
InitializeStaticGLBindingsGL();
InitializeStaticGLBindingsEGL();
......@@ -197,6 +212,7 @@ bool InitializeGLOneOffPlatform() {
return true;
#if BUILDFLAG(USE_EGL_ON_MAC)
case kGLImplementationEGLGLES2:
case kGLImplementationSwiftShaderGL:
if (!GLSurfaceEGL::InitializeOneOff(0)) {
LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
return false;
......@@ -229,6 +245,7 @@ bool InitializeStaticGLBindings(GLImplementation implementation) {
return InitializeStaticCGLInternal(implementation);
#if BUILDFLAG(USE_EGL_ON_MAC)
case kGLImplementationEGLGLES2:
case kGLImplementationSwiftShaderGL:
return InitializeStaticEGLInternal(implementation);
#endif // BUILDFLAG(USE_EGL_ON_MAC)
case kGLImplementationMockGL:
......
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