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) { ...@@ -968,10 +968,11 @@ if (is_win) {
} }
if (use_egl) { if (use_egl) {
# We need to copy the ANGLE libraries so that the bundle_data dependencies # We need to copy the ANGLE and SwiftShader libraries so that the
# have a "copy" target type. Otherwise for "shared_library" target types # bundle_data dependencies have a "copy" target type. Otherwise for
# it will try to link things into Chromium Framework when we want to keep # "shared_library" target types it will try to link things into
# the ANGLE libraries separate instead. # Chromium Framework when we want to keep the ANGLE and SwiftShader
# libraries separate instead.
copy("angle_library_copy") { copy("angle_library_copy") {
sources = [ sources = [
"$root_out_dir/libEGL.dylib", "$root_out_dir/libEGL.dylib",
...@@ -999,6 +1000,34 @@ if (is_win) { ...@@ -999,6 +1000,34 @@ if (is_win) {
":angle_library_copy", ":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") { group("angle_library") {
...@@ -1009,6 +1038,14 @@ if (is_win) { ...@@ -1009,6 +1038,14 @@ if (is_win) {
} }
} }
group("swiftshader_library") {
if (use_egl) {
deps = [
":swiftshader_binaries",
]
}
}
_should_bundle_widevine = _should_bundle_widevine =
(is_chrome_branded || enable_widevine) && enable_library_cdms (is_chrome_branded || enable_widevine) && enable_library_cdms
if (_should_bundle_widevine) { if (_should_bundle_widevine) {
...@@ -1288,6 +1325,7 @@ if (is_win) { ...@@ -1288,6 +1325,7 @@ if (is_win) {
":chrome_framework_resources", ":chrome_framework_resources",
":chrome_framework_services", ":chrome_framework_services",
":packed_resources", ":packed_resources",
":swiftshader_library",
":widevine_cdm_library", ":widevine_cdm_library",
"//build/config:exe_and_shlib_deps", "//build/config:exe_and_shlib_deps",
"//chrome/app/nibs:chrome_xibs", "//chrome/app/nibs:chrome_xibs",
......
...@@ -54,6 +54,7 @@ scoped_refptr<gl::GLSurface> ImageTransportSurface::CreateNativeSurface( ...@@ -54,6 +54,7 @@ scoped_refptr<gl::GLSurface> ImageTransportSurface::CreateNativeSurface(
case gl::kGLImplementationDesktopGLCoreProfile: case gl::kGLImplementationDesktopGLCoreProfile:
case gl::kGLImplementationAppleGL: case gl::kGLImplementationAppleGL:
case gl::kGLImplementationEGLGLES2: case gl::kGLImplementationEGLGLES2:
case gl::kGLImplementationSwiftShaderGL:
return base::WrapRefCounted<gl::GLSurface>( return base::WrapRefCounted<gl::GLSurface>(
new ImageTransportSurfaceOverlayMac(delegate)); new ImageTransportSurfaceOverlayMac(delegate));
case gl::kGLImplementationMockGL: case gl::kGLImplementationMockGL:
......
...@@ -11,9 +11,10 @@ import("//ui/ozone/ozone.gni") ...@@ -11,9 +11,10 @@ import("//ui/ozone/ozone.gni")
import("//testing/test.gni") import("//testing/test.gni")
declare_args() { declare_args() {
enable_swiftshader = (is_win || (is_linux && use_x11) || enable_swiftshader =
(is_chromeos && ozone_platform_x11)) && (is_win || (is_linux && use_x11) || (is_mac && use_egl) ||
(target_cpu == "x86" || target_cpu == "x64") (is_chromeos && ozone_platform_x11)) &&
(target_cpu == "x86" || target_cpu == "x64")
} }
use_glx = use_x11 || ozone_platform_x11 use_glx = use_x11 || ozone_platform_x11
...@@ -332,6 +333,7 @@ component("gl") { ...@@ -332,6 +333,7 @@ component("gl") {
data_deps += [ data_deps += [
"//third_party/angle:libEGL", "//third_party/angle:libEGL",
"//third_party/angle:libGLESv2", "//third_party/angle:libGLESv2",
"//third_party/swiftshader",
] ]
} }
} }
......
...@@ -182,7 +182,8 @@ GLenum ConvertRequestedInternalFormat(GLenum internalformat) { ...@@ -182,7 +182,8 @@ GLenum ConvertRequestedInternalFormat(GLenum internalformat) {
GLImageIOSurface* GLImageIOSurface::Create(const gfx::Size& size, GLImageIOSurface* GLImageIOSurface::Create(const gfx::Size& size,
unsigned internalformat) { unsigned internalformat) {
#if BUILDFLAG(USE_EGL_ON_MAC) #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); return new GLImageIOSurfaceEGL(size, internalformat);
} }
#endif // BUILDFLAG(USE_EGL_ON_MAC) #endif // BUILDFLAG(USE_EGL_ON_MAC)
......
...@@ -67,6 +67,7 @@ std::vector<GLImplementation> GetAllowedGLImplementations() { ...@@ -67,6 +67,7 @@ std::vector<GLImplementation> GetAllowedGLImplementations() {
impls.push_back(kGLImplementationDesktopGLCoreProfile); impls.push_back(kGLImplementationDesktopGLCoreProfile);
#if BUILDFLAG(USE_EGL_ON_MAC) #if BUILDFLAG(USE_EGL_ON_MAC)
impls.push_back(kGLImplementationEGLGLES2); impls.push_back(kGLImplementationEGLGLES2);
impls.push_back(kGLImplementationSwiftShaderGL);
#endif // BUILDFLAG(USE_EGL_ON_MAC) #endif // BUILDFLAG(USE_EGL_ON_MAC)
impls.push_back(kGLImplementationDesktopGL); impls.push_back(kGLImplementationDesktopGL);
impls.push_back(kGLImplementationAppleGL); impls.push_back(kGLImplementationAppleGL);
...@@ -90,6 +91,7 @@ scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, ...@@ -90,6 +91,7 @@ scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group,
compatible_surface, attribs); compatible_surface, attribs);
#if BUILDFLAG(USE_EGL_ON_MAC) #if BUILDFLAG(USE_EGL_ON_MAC)
case kGLImplementationEGLGLES2: case kGLImplementationEGLGLES2:
case kGLImplementationSwiftShaderGL:
return InitializeGLContext(new GLContextEGL(share_group), return InitializeGLContext(new GLContextEGL(share_group),
compatible_surface, attribs); compatible_surface, attribs);
#endif // BUILDFLAG(USE_EGL_ON_MAC) #endif // BUILDFLAG(USE_EGL_ON_MAC)
...@@ -116,7 +118,8 @@ scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { ...@@ -116,7 +118,8 @@ scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) {
case kGLImplementationDesktopGL: case kGLImplementationDesktopGL:
case kGLImplementationDesktopGLCoreProfile: case kGLImplementationDesktopGLCoreProfile:
case kGLImplementationAppleGL: case kGLImplementationAppleGL:
case kGLImplementationEGLGLES2: { case kGLImplementationEGLGLES2:
case kGLImplementationSwiftShaderGL: {
NOTIMPLEMENTED() << "No onscreen support on Mac."; NOTIMPLEMENTED() << "No onscreen support on Mac.";
return nullptr; return nullptr;
} }
...@@ -147,6 +150,7 @@ scoped_refptr<GLSurface> CreateOffscreenGLSurfaceWithFormat( ...@@ -147,6 +150,7 @@ scoped_refptr<GLSurface> CreateOffscreenGLSurfaceWithFormat(
new NoOpGLSurface(size), format); new NoOpGLSurface(size), format);
#if BUILDFLAG(USE_EGL_ON_MAC) #if BUILDFLAG(USE_EGL_ON_MAC)
case kGLImplementationEGLGLES2: case kGLImplementationEGLGLES2:
case kGLImplementationSwiftShaderGL:
if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() &&
size.width() == 0 && size.height() == 0) { size.width() == 0 && size.height() == 0) {
return InitializeGLSurfaceWithFormat(new SurfacelessEGL(size), format); return InitializeGLSurfaceWithFormat(new SurfacelessEGL(size), format);
......
...@@ -137,23 +137,36 @@ bool InitializeStaticCGLInternal(GLImplementation implementation) { ...@@ -137,23 +137,36 @@ bool InitializeStaticCGLInternal(GLImplementation implementation) {
const char kGLESv2ANGLELibraryName[] = "Libraries/libGLESv2.dylib"; const char kGLESv2ANGLELibraryName[] = "Libraries/libGLESv2.dylib";
const char kEGLANGLELibraryName[] = "Libraries/libEGL.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) { bool InitializeStaticEGLInternal(GLImplementation implementation) {
if (implementation == kGLImplementationSwiftShaderGL) { base::FilePath module_path;
if (!PathService::Get(base::DIR_MODULE, &module_path)) {
return false; return false;
} }
base::FilePath module_path; base::FilePath glesv2_path;
if (!PathService::Get(base::DIR_MODULE, &module_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; 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); base::NativeLibrary gles_library = LoadLibraryAndPrintError(glesv2_path);
if (!gles_library) { if (!gles_library) {
return false; return false;
} }
base::FilePath egl_path = module_path.Append(kEGLANGLELibraryName);
base::NativeLibrary egl_library = LoadLibraryAndPrintError(egl_path); base::NativeLibrary egl_library = LoadLibraryAndPrintError(egl_path);
if (!egl_library) { if (!egl_library) {
base::UnloadNativeLibrary(gles_library); base::UnloadNativeLibrary(gles_library);
...@@ -172,9 +185,11 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) { ...@@ -172,9 +185,11 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) {
} }
SetGLGetProcAddressProc(get_proc_address); SetGLGetProcAddressProc(get_proc_address);
AddGLNativeLibrary(egl_library); // FIXME: SwiftShader must load symbols from libGLESv2 before libEGL on MacOS
// currently
AddGLNativeLibrary(gles_library); AddGLNativeLibrary(gles_library);
SetGLImplementation(kGLImplementationEGLGLES2); AddGLNativeLibrary(egl_library);
SetGLImplementation(implementation);
InitializeStaticGLBindingsGL(); InitializeStaticGLBindingsGL();
InitializeStaticGLBindingsEGL(); InitializeStaticGLBindingsEGL();
...@@ -197,6 +212,7 @@ bool InitializeGLOneOffPlatform() { ...@@ -197,6 +212,7 @@ bool InitializeGLOneOffPlatform() {
return true; return true;
#if BUILDFLAG(USE_EGL_ON_MAC) #if BUILDFLAG(USE_EGL_ON_MAC)
case kGLImplementationEGLGLES2: case kGLImplementationEGLGLES2:
case kGLImplementationSwiftShaderGL:
if (!GLSurfaceEGL::InitializeOneOff(0)) { if (!GLSurfaceEGL::InitializeOneOff(0)) {
LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
return false; return false;
...@@ -229,6 +245,7 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { ...@@ -229,6 +245,7 @@ bool InitializeStaticGLBindings(GLImplementation implementation) {
return InitializeStaticCGLInternal(implementation); return InitializeStaticCGLInternal(implementation);
#if BUILDFLAG(USE_EGL_ON_MAC) #if BUILDFLAG(USE_EGL_ON_MAC)
case kGLImplementationEGLGLES2: case kGLImplementationEGLGLES2:
case kGLImplementationSwiftShaderGL:
return InitializeStaticEGLInternal(implementation); return InitializeStaticEGLInternal(implementation);
#endif // BUILDFLAG(USE_EGL_ON_MAC) #endif // BUILDFLAG(USE_EGL_ON_MAC)
case kGLImplementationMockGL: 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