Enable Skia's Vulkan backend on all non-mobile platforms, and test SwiftShader Vulkan on all GL unittests platforms (flutter/engine#29520)
This commit is contained in:
@@ -1538,8 +1538,11 @@ TEST_F(ShellTest, SetResourceCacheSize) {
|
||||
PumpOneFrame(shell.get());
|
||||
|
||||
// The Vulkan and GL backends set different default values for the resource
|
||||
// cache size.
|
||||
#ifdef SHELL_ENABLE_VULKAN
|
||||
// cache size. The default backend (specified by the default param of
|
||||
// `CreateShell` in this test) will only resolve to Vulkan (in
|
||||
// `ShellTestPlatformView::Create`) if GL is disabled. This situation arises
|
||||
// when targeting the Fuchsia Emulator.
|
||||
#if defined(SHELL_ENABLE_VULKAN) && !defined(SHELL_ENABLE_GL)
|
||||
EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
|
||||
vulkan::kGrCacheMaxByteSize);
|
||||
#else
|
||||
|
||||
@@ -4,16 +4,19 @@
|
||||
|
||||
declare_args() {
|
||||
shell_enable_gl = !is_fuchsia
|
||||
shell_enable_metal = false
|
||||
|
||||
# TODO(dworsham): Enable once Fuchsia supports Vulkan through the embedder.
|
||||
# The logic for enabling Vulkan and Metal is in tools/gn.
|
||||
shell_enable_metal = false
|
||||
shell_enable_vulkan = false
|
||||
|
||||
shell_enable_software = true
|
||||
}
|
||||
|
||||
declare_args() {
|
||||
test_enable_gl = shell_enable_gl
|
||||
test_enable_metal = shell_enable_metal
|
||||
test_enable_vulkan = is_fuchsia
|
||||
|
||||
# The Vulkan unittests are combined with the GL unittests.
|
||||
test_enable_vulkan = is_fuchsia || shell_enable_gl
|
||||
test_enable_software = shell_enable_software
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//flutter/common/config.gni")
|
||||
import("//flutter/shell/config.gni")
|
||||
|
||||
source_set("context") {
|
||||
sources = [
|
||||
@@ -16,4 +17,8 @@ source_set("context") {
|
||||
"//flutter/fml",
|
||||
"//third_party/skia",
|
||||
]
|
||||
|
||||
if (shell_enable_vulkan) {
|
||||
deps += [ "//flutter/vulkan" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//flutter/shell/config.gni")
|
||||
|
||||
source_set("surface") {
|
||||
sources = [
|
||||
"android_surface.cc",
|
||||
@@ -54,4 +56,8 @@ source_set("surface_mock") {
|
||||
"//third_party/googletest:gtest",
|
||||
"//third_party/skia",
|
||||
]
|
||||
|
||||
if (shell_enable_vulkan) {
|
||||
deps += [ "//flutter/vulkan" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ assert(is_ios)
|
||||
import("//build/config/ios/ios_sdk.gni")
|
||||
import("//build/toolchain/clang.gni")
|
||||
import("//flutter/common/config.gni")
|
||||
import("//flutter/shell/config.gni")
|
||||
import("//flutter/shell/gpu/gpu.gni")
|
||||
import("//flutter/shell/platform/darwin/common/framework_shared.gni")
|
||||
import("//flutter/testing/testing.gni")
|
||||
@@ -216,6 +217,10 @@ source_set("ios_test_flutter_mrc") {
|
||||
"//third_party/rapidjson",
|
||||
"//third_party/skia",
|
||||
]
|
||||
|
||||
if (shell_enable_vulkan) {
|
||||
deps += [ "//flutter/vulkan" ]
|
||||
}
|
||||
}
|
||||
|
||||
shared_library("ios_test_flutter") {
|
||||
|
||||
@@ -242,6 +242,13 @@ if (enable_unittests) {
|
||||
|
||||
deps += [ "//flutter/testing:metal" ]
|
||||
}
|
||||
|
||||
if (test_enable_vulkan) {
|
||||
deps += [
|
||||
"//flutter/testing:vulkan",
|
||||
"//flutter/vulkan",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
# Tests the build in FLUTTER_ENGINE_NO_PROTOTYPES mode.
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "flutter/shell/platform/embedder/tests/embedder_unittests_util.h"
|
||||
#include "flutter/testing/assertions_skia.h"
|
||||
#include "flutter/testing/test_gl_surface.h"
|
||||
#include "flutter/testing/test_vulkan_context.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
#include "third_party/skia/src/gpu/gl/GrGLDefines.h"
|
||||
@@ -39,6 +40,16 @@ namespace testing {
|
||||
|
||||
using EmbedderTest = testing::EmbedderTest;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// This is a sanity check to ensure Swiftshader Vulkan is working. Once Vulkan
|
||||
/// support lands in the embedder API, it'll be tested via a new
|
||||
/// EmbedderTestContext type/config.
|
||||
///
|
||||
TEST_F(EmbedderTest, CanInitializeTestVulkanContext) {
|
||||
TestVulkanContext ctx;
|
||||
ASSERT_TRUE(ctx.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(EmbedderTest, CanCreateOpenGLRenderingEngine) {
|
||||
EmbedderConfigBuilder builder(
|
||||
GetEmbedderContext(EmbedderTestContextType::kOpenGLContext));
|
||||
|
||||
@@ -125,9 +125,17 @@ if (enable_unittests) {
|
||||
source_set("vulkan") {
|
||||
testonly = true
|
||||
|
||||
sources = [
|
||||
"test_vulkan_context.cc",
|
||||
"test_vulkan_context.h",
|
||||
]
|
||||
|
||||
defines = [ "TEST_VULKAN_PROCS" ]
|
||||
|
||||
deps = [
|
||||
":skia",
|
||||
"//flutter/fml",
|
||||
"//flutter/vulkan",
|
||||
]
|
||||
|
||||
# SwiftShader only supports x86/x86_64
|
||||
@@ -174,9 +182,12 @@ if (enable_unittests) {
|
||||
"test_metal_surface_impl.mm",
|
||||
]
|
||||
|
||||
# Skia's Vulkan support is enabled for all platforms, and so parts of
|
||||
# Skia's graphics context reference Vulkan symbols.
|
||||
deps = [
|
||||
":skia",
|
||||
"//flutter/fml",
|
||||
"//flutter/vulkan",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -199,6 +210,7 @@ if (enable_unittests) {
|
||||
":testing",
|
||||
":testing_fixtures",
|
||||
"//flutter/runtime:libdart",
|
||||
"//flutter/vulkan",
|
||||
]
|
||||
|
||||
if (shell_enable_metal) {
|
||||
|
||||
52
engine/src/flutter/testing/test_vulkan_context.cc
Normal file
52
engine/src/flutter/testing/test_vulkan_context.cc
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "test_vulkan_context.h"
|
||||
|
||||
#include "flutter/vulkan/vulkan_proc_table.h"
|
||||
|
||||
#ifdef OS_MACOSX
|
||||
#define VULKAN_SO_PATH "libvk_swiftshader.dylib"
|
||||
#elif OS_WIN
|
||||
#define VULKAN_SO_PATH "vk_swiftshader.dll"
|
||||
#else
|
||||
#define VULKAN_SO_PATH "libvk_swiftshader.so"
|
||||
#endif
|
||||
|
||||
namespace flutter {
|
||||
|
||||
TestVulkanContext::TestVulkanContext() : valid_(false) {
|
||||
vk_ = fml::MakeRefCounted<vulkan::VulkanProcTable>(VULKAN_SO_PATH);
|
||||
if (!vk_ || !vk_->HasAcquiredMandatoryProcAddresses()) {
|
||||
FML_DLOG(ERROR) << "Proc table has not acquired mandatory proc addresses.";
|
||||
return;
|
||||
}
|
||||
|
||||
application_ = std::unique_ptr<vulkan::VulkanApplication>(
|
||||
new vulkan::VulkanApplication(*vk_, "Flutter Unittests", {}));
|
||||
if (!application_->IsValid()) {
|
||||
FML_DLOG(ERROR) << "Failed to initialize basic Vulkan state.";
|
||||
return;
|
||||
}
|
||||
if (!vk_->AreInstanceProcsSetup()) {
|
||||
FML_DLOG(ERROR) << "Failed to acquire full proc table.";
|
||||
return;
|
||||
}
|
||||
|
||||
logical_device_ = application_->AcquireFirstCompatibleLogicalDevice();
|
||||
if (!logical_device_ || !logical_device_->IsValid()) {
|
||||
FML_DLOG(ERROR) << "Failed to create compatible logical device.";
|
||||
return;
|
||||
}
|
||||
|
||||
valid_ = true;
|
||||
}
|
||||
|
||||
TestVulkanContext::~TestVulkanContext() = default;
|
||||
|
||||
bool TestVulkanContext::IsValid() {
|
||||
return valid_;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
33
engine/src/flutter/testing/test_vulkan_context.h
Normal file
33
engine/src/flutter/testing/test_vulkan_context.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_TESTING_TEST_VULKAN_CONTEXT_H_
|
||||
#define FLUTTER_TESTING_TEST_VULKAN_CONTEXT_H_
|
||||
|
||||
#include "flutter/vulkan/vulkan_application.h"
|
||||
#include "flutter/vulkan/vulkan_device.h"
|
||||
#include "flutter/vulkan/vulkan_proc_table.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
/// @brief Utility class to create a Vulkan device context, a corresponding
|
||||
/// Skia context, and device resources.
|
||||
class TestVulkanContext {
|
||||
public:
|
||||
TestVulkanContext();
|
||||
~TestVulkanContext();
|
||||
bool IsValid();
|
||||
|
||||
private:
|
||||
bool valid_ = false;
|
||||
fml::RefPtr<vulkan::VulkanProcTable> vk_;
|
||||
std::unique_ptr<vulkan::VulkanApplication> application_;
|
||||
std::unique_ptr<vulkan::VulkanDevice> logical_device_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(TestVulkanContext);
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_TESTING_TEST_VULKAN_CONTEXT_H_
|
||||
@@ -312,6 +312,17 @@ def to_gn_args(args):
|
||||
gn_args['skia_use_metal'] = True
|
||||
gn_args['shell_enable_metal'] = True
|
||||
|
||||
# Enable Vulkan on all platforms except for Android and iOS. This is just
|
||||
# to save on mobile binary size, as there's no reason the Vulkan embedder
|
||||
# features can't work on these platforms.
|
||||
if args.target_os not in ['android', 'ios']:
|
||||
gn_args['skia_use_vulkan'] = True
|
||||
gn_args['shell_enable_vulkan'] = True
|
||||
# Disable VMA's use of std::shared_mutex in environments where the
|
||||
# standard library doesn't support it.
|
||||
if args.target_os == 'ios' or sys.platform.startswith(('cygwin', 'win')):
|
||||
gn_args['skia_disable_vma_stl_shared_mutex'] = True
|
||||
|
||||
if sys.platform.startswith(('cygwin', 'win')):
|
||||
# The buildroot currently isn't set up to support Vulkan in the
|
||||
# Windows ANGLE build, so disable it regardless of enable_vulkan's value.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "vulkan_debug_report.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ bool VulkanImage::InsertImageMemoryBarrier(
|
||||
const VulkanCommandBuffer& command_buffer,
|
||||
VkPipelineStageFlagBits src_pipline_bits,
|
||||
VkPipelineStageFlagBits dest_pipline_bits,
|
||||
VkAccessFlagBits dest_access_flags,
|
||||
VkAccessFlags dest_access_flags,
|
||||
VkImageLayout dest_layout) {
|
||||
const VkImageMemoryBarrier image_memory_barrier = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
|
||||
@@ -26,7 +26,7 @@ class VulkanImage {
|
||||
const VulkanCommandBuffer& command_buffer,
|
||||
VkPipelineStageFlagBits src_pipline_bits,
|
||||
VkPipelineStageFlagBits dest_pipline_bits,
|
||||
VkAccessFlagBits dest_access_flags,
|
||||
VkAccessFlags dest_access_flags,
|
||||
VkImageLayout dest_layout);
|
||||
|
||||
private:
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include "vulkan_proc_table.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
#define ACQUIRE_PROC(name, context) \
|
||||
@@ -16,10 +14,12 @@
|
||||
|
||||
namespace vulkan {
|
||||
|
||||
VulkanProcTable::VulkanProcTable()
|
||||
VulkanProcTable::VulkanProcTable() : VulkanProcTable("libvulkan.so"){};
|
||||
|
||||
VulkanProcTable::VulkanProcTable(const char* path)
|
||||
: handle_(nullptr), acquired_mandatory_proc_addresses_(false) {
|
||||
acquired_mandatory_proc_addresses_ =
|
||||
OpenLibraryHandle() && SetupLoaderProcAddresses();
|
||||
OpenLibraryHandle(path) && SetupLoaderProcAddresses();
|
||||
}
|
||||
|
||||
VulkanProcTable::~VulkanProcTable() {
|
||||
@@ -43,7 +43,7 @@ bool VulkanProcTable::AreDeviceProcsSetup() const {
|
||||
}
|
||||
|
||||
bool VulkanProcTable::SetupLoaderProcAddresses() {
|
||||
if (handle_ == nullptr) {
|
||||
if (!handle_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ bool VulkanProcTable::SetupLoaderProcAddresses() {
|
||||
#if VULKAN_LINK_STATICALLY
|
||||
GetInstanceProcAddr = &vkGetInstanceProcAddr;
|
||||
#else // VULKAN_LINK_STATICALLY
|
||||
reinterpret_cast<PFN_vkGetInstanceProcAddr>(
|
||||
dlsym(handle_, "vkGetInstanceProcAddr"));
|
||||
reinterpret_cast<PFN_vkGetInstanceProcAddr>(const_cast<uint8_t*>(
|
||||
handle_->ResolveSymbol("vkGetInstanceProcAddr")));
|
||||
#endif // VULKAN_LINK_STATICALLY
|
||||
|
||||
if (!GetInstanceProcAddr) {
|
||||
@@ -129,6 +129,7 @@ bool VulkanProcTable::SetupDeviceProcAddresses(
|
||||
ACQUIRE_PROC(ResetCommandBuffer, handle);
|
||||
ACQUIRE_PROC(ResetFences, handle);
|
||||
ACQUIRE_PROC(WaitForFences, handle);
|
||||
#ifndef TEST_VULKAN_PROCS
|
||||
#if OS_ANDROID
|
||||
ACQUIRE_PROC(AcquireNextImageKHR, handle);
|
||||
ACQUIRE_PROC(CreateSwapchainKHR, handle);
|
||||
@@ -145,42 +146,23 @@ bool VulkanProcTable::SetupDeviceProcAddresses(
|
||||
ACQUIRE_PROC(SetBufferCollectionConstraintsFUCHSIAX, handle);
|
||||
ACQUIRE_PROC(GetBufferCollectionPropertiesFUCHSIAX, handle);
|
||||
#endif // OS_FUCHSIA
|
||||
#endif // TEST_VULKAN_PROCS
|
||||
device_ = {handle, nullptr};
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VulkanProcTable::OpenLibraryHandle() {
|
||||
bool VulkanProcTable::OpenLibraryHandle(const char* path) {
|
||||
#if VULKAN_LINK_STATICALLY
|
||||
static char kDummyLibraryHandle = '\0';
|
||||
handle_ = reinterpret_cast<decltype(handle_)>(&kDummyLibraryHandle);
|
||||
return true;
|
||||
handle_ = fml::NativeLibrary::CreateForCurrentProcess();
|
||||
#else // VULKAN_LINK_STATICALLY
|
||||
dlerror(); // clear existing errors on thread.
|
||||
handle_ = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
|
||||
if (handle_ == nullptr) {
|
||||
FML_DLOG(WARNING) << "Could not open the vulkan library: " << dlerror();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
handle_ = fml::NativeLibrary::Create(path);
|
||||
#endif // VULKAN_LINK_STATICALLY
|
||||
return !!handle_;
|
||||
}
|
||||
|
||||
bool VulkanProcTable::CloseLibraryHandle() {
|
||||
#if VULKAN_LINK_STATICALLY
|
||||
handle_ = nullptr;
|
||||
return true;
|
||||
#else
|
||||
if (handle_ != nullptr) {
|
||||
dlerror(); // clear existing errors on thread.
|
||||
if (dlclose(handle_) != 0) {
|
||||
FML_DLOG(ERROR) << "Could not close the vulkan library handle. This "
|
||||
"indicates a leak.";
|
||||
FML_DLOG(ERROR) << dlerror();
|
||||
}
|
||||
handle_ = nullptr;
|
||||
}
|
||||
return handle_ == nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
PFN_vkVoidFunction VulkanProcTable::AcquireProc(
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "flutter/fml/memory/ref_ptr.h"
|
||||
#include "flutter/fml/native_library.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h"
|
||||
#include "vulkan_handle.h"
|
||||
@@ -105,6 +106,7 @@ class VulkanProcTable : public fml::RefCountedThreadSafe<VulkanProcTable> {
|
||||
DEFINE_PROC(ResetCommandBuffer);
|
||||
DEFINE_PROC(ResetFences);
|
||||
DEFINE_PROC(WaitForFences);
|
||||
#ifndef TEST_VULKAN_PROCS
|
||||
#if OS_ANDROID
|
||||
DEFINE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR);
|
||||
DEFINE_PROC(GetPhysicalDeviceSurfaceFormatsKHR);
|
||||
@@ -123,18 +125,20 @@ class VulkanProcTable : public fml::RefCountedThreadSafe<VulkanProcTable> {
|
||||
DEFINE_PROC(SetBufferCollectionConstraintsFUCHSIAX);
|
||||
DEFINE_PROC(GetBufferCollectionPropertiesFUCHSIAX);
|
||||
#endif // OS_FUCHSIA
|
||||
#endif // TEST_VULKAN_PROCS
|
||||
|
||||
#undef DEFINE_PROC
|
||||
|
||||
private:
|
||||
void* handle_;
|
||||
fml::RefPtr<fml::NativeLibrary> handle_;
|
||||
bool acquired_mandatory_proc_addresses_;
|
||||
VulkanHandle<VkInstance> instance_;
|
||||
VulkanHandle<VkDevice> device_;
|
||||
|
||||
VulkanProcTable();
|
||||
VulkanProcTable(const char* path);
|
||||
~VulkanProcTable();
|
||||
bool OpenLibraryHandle();
|
||||
bool OpenLibraryHandle(const char* path);
|
||||
bool SetupLoaderProcAddresses();
|
||||
bool CloseLibraryHandle();
|
||||
PFN_vkVoidFunction AcquireProc(
|
||||
|
||||
Reference in New Issue
Block a user