Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Enable shell_unittests on Fuchsia with Vulkan dependencies. #16376

Merged
merged 3 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ if (is_fuchsia) {
"//flutter/flow:flow_tests",
"//flutter/fml:fml_tests",
"//flutter/runtime:runtime_tests",
"//flutter/shell/common:shell_tests",
"//flutter/shell/platform/fuchsia/flutter:flutter_runner_scenic_tests",
"//flutter/shell/platform/fuchsia/flutter:flutter_runner_tests",
]
Expand Down
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ FILE: ../../../flutter/shell/common/shell_test_platform_view.cc
FILE: ../../../flutter/shell/common/shell_test_platform_view.h
FILE: ../../../flutter/shell/common/shell_test_platform_view_gl.cc
FILE: ../../../flutter/shell/common/shell_test_platform_view_gl.h
FILE: ../../../flutter/shell/common/shell_test_platform_view_vulkan.cc
FILE: ../../../flutter/shell/common/shell_test_platform_view_vulkan.h
FILE: ../../../flutter/shell/common/shell_unittests.cc
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.h
Expand Down
98 changes: 90 additions & 8 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,30 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//flutter/common/config.gni")
import("//flutter/shell/gpu/gpu.gni")
import("//flutter/testing/testing.gni")

if (is_fuchsia) {
import("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/fuchsia_archive.gni")
}

config("vulkan_config") {
if (using_fuchsia_sdk) {
include_dirs = [ "$fuchsia_sdk_root/vulkan/include" ]
} else if (is_fuchsia) {
include_dirs =
[ "//third_party/vulkan_loader_and_validation_layers/include" ]
} else {
include_dirs = [ "//third_party/vulkan/src" ]
}

if (is_fuchsia) {
defines = [ "VK_USE_PLATFORM_FUCHSIA=1" ]
}
}

# Template to generate a dart embedder resource.cc file.
# Required invoker inputs:
# String output (name of output file)
Expand Down Expand Up @@ -143,12 +164,19 @@ template("shell_host_executable") {
}
}

if (current_toolchain == host_toolchain) {
if (enable_unittests) {
declare_args() {
test_enable_vulkan = is_fuchsia
test_enable_gl = !is_fuchsia
test_enable_software = true
test_enable_metal = false
}

shell_gpu_configuration("shell_unittests_gpu_configuration") {
enable_software = true
enable_vulkan = false
enable_gl = true
enable_metal = false
enable_software = test_enable_software
enable_vulkan = test_enable_vulkan
enable_gl = test_enable_gl
enable_metal = test_enable_metal
}

test_fixtures("shell_unittests_fixtures") {
Expand All @@ -168,8 +196,6 @@ if (current_toolchain == host_toolchain) {
"shell_test.h",
"shell_test_platform_view.cc",
"shell_test_platform_view.h",
"shell_test_platform_view_gl.cc",
"shell_test_platform_view_gl.h",
"shell_unittests.cc",
"vsync_waiters_test.cc",
"vsync_waiters_test.h",
Expand All @@ -184,8 +210,64 @@ if (current_toolchain == host_toolchain) {
"//flutter/lib/ui:ui",
"//flutter/shell",
"//flutter/testing:dart",
"//flutter/testing:opengl",
]

if (!defined(defines)) {
defines = []
}

# SwiftShader only supports x86/x64_64
if (target_cpu == "x86" || target_cpu == "x64") {
if (test_enable_gl) {
sources += [
"shell_test_platform_view_gl.cc",
"shell_test_platform_view_gl.h",
]

deps += [ "//flutter/testing:opengl" ]

defines += [ "SHELL_ENABLE_GL" ]
}

if (test_enable_vulkan) {
sources += [
"shell_test_platform_view_vulkan.cc",
"shell_test_platform_view_vulkan.h",
]

deps += [
"//flutter/testing:vulkan",
"//flutter/vulkan",
]

defines += [ "SHELL_ENABLE_VULKAN" ]
}
}
}

if (is_fuchsia) {
fuchsia_test_archive("shell_tests") {
deps = [
":shell_unittests",
":shell_unittests_fixtures",
]

binary = "shell_unittests"

# TODO(gw280): https://github.com/flutter/flutter/issues/50294
# Right now we need to manually specify all the fixtures that are
# declared in the test_fixtures() call above.
resources = [
{
path = "$target_gen_dir/assets/kernel_blob.bin"
dest = "assets/kernel_blob.bin"
},
{
path = "$target_gen_dir/assets/shelltest_screenshot.png"
dest = "assets/shelltest_screenshot.png"
},
]
}
}

shell_host_executable("shell_benchmarks") {
Expand Down
7 changes: 4 additions & 3 deletions shell/common/animator_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ TEST_F(ShellTest, VSyncTargetTime) {
shell = Shell::Create(
task_runners, settings,
[vsync_clock, &create_vsync_waiter](Shell& shell) {
return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(),
vsync_clock,
std::move(create_vsync_waiter));
return ShellTestPlatformView::Create(
shell, shell.GetTaskRunners(), vsync_clock,
std::move(create_vsync_waiter),
ShellTestPlatformView::BackendType::kDefaultBackend);
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
Expand Down
7 changes: 4 additions & 3 deletions shell/common/shell_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ std::unique_ptr<Shell> ShellTest::CreateShell(Settings settings,
return Shell::Create(
task_runners, settings,
[vsync_clock, &create_vsync_waiter](Shell& shell) {
return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(),
vsync_clock,
std::move(create_vsync_waiter));
return ShellTestPlatformView::Create(
shell, shell.GetTaskRunners(), vsync_clock,
std::move(create_vsync_waiter),
ShellTestPlatformView::BackendType::kDefaultBackend);
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
Expand Down
29 changes: 26 additions & 3 deletions shell/common/shell_test_platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
// found in the LICENSE file.

#include "flutter/shell/common/shell_test_platform_view.h"

#ifdef SHELL_ENABLE_GL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when using Vulkan, we never have to link with libVulkan.so. So we will never get into a situation where where the test harness fails to link if Vulkan is not used. The exact same logic applies for OpenGL as well. As written, we will need two variants of the test runner for OpenGL and Vulkan. I suggest we have just one which is both OpenGL and Vulkan capable. At runtime, if the test or fixture asks use to initialize an unsupported client rendering API, we can skip the test or trip an assertion.

This way, all platforms will be Vulkan capable and their ability to actually exercise the Vulkan backend will depend on whether that platform can provide a libVulkan.so for proc resolution.

While we will always use the libVulkan.so from SwiftShader, this scheme should give us the flexibility to run with an alternative Vulkan implemenation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke offline about this - tried this but due to compilation issues this can't be done easily right now, and it's not worth blocking enabling these tests for this. Filed flutter/flutter#50298 detailing the problems.

#include "flutter/shell/common/shell_test_platform_view_gl.h"
#endif // SHELL_ENABLE_GL
#ifdef SHELL_ENABLE_VULKAN
#include "flutter/shell/common/shell_test_platform_view_vulkan.h"
#endif // SHELL_ENABLE_VULKAN

namespace flutter {
namespace testing {
Expand All @@ -12,9 +18,26 @@ std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter) {
return std::make_unique<ShellTestPlatformViewGL>(
delegate, task_runners, vsync_clock, create_vsync_waiter);
CreateVsyncWaiter create_vsync_waiter,
BackendType backend) {
// TODO(gw280): https://github.com/flutter/flutter/issues/50298
// Make this fully runtime configurable
switch (backend) {
case BackendType::kDefaultBackend:
#ifdef SHELL_ENABLE_GL
case BackendType::kGLBackend:
return std::make_unique<ShellTestPlatformViewGL>(
delegate, task_runners, vsync_clock, create_vsync_waiter);
#endif // SHELL_ENABLE_GL
#ifdef SHELL_ENABLE_VULKAN
case BackendType::kVulkanBackend:
return std::make_unique<ShellTestPlatformViewVulkan>(
delegate, task_runners, vsync_clock, create_vsync_waiter);
#endif // SHELL_ENABLE_VULKAN
default:
FML_LOG(FATAL) << "No backends supported for ShellTestPlatformView";
return nullptr;
}
}

} // namespace testing
Expand Down
9 changes: 8 additions & 1 deletion shell/common/shell_test_platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ namespace testing {

class ShellTestPlatformView : public PlatformView {
public:
enum class BackendType {
kGLBackend,
kVulkanBackend,
kDefaultBackend,
};

static std::unique_ptr<ShellTestPlatformView> Create(
PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter);
CreateVsyncWaiter create_vsync_waiter,
BackendType backend);

virtual void SimulateVSync() = 0;

Expand Down
49 changes: 49 additions & 0 deletions shell/common/shell_test_platform_view_vulkan.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 "flutter/shell/common/shell_test_platform_view_vulkan.h"
#include "flutter/shell/gpu/gpu_surface_vulkan.h"

namespace flutter {
namespace testing {

ShellTestPlatformViewVulkan::ShellTestPlatformViewVulkan(
PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter)
: ShellTestPlatformView(delegate, std::move(task_runners)),
create_vsync_waiter_(std::move(create_vsync_waiter)),
vsync_clock_(vsync_clock),
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {}

ShellTestPlatformViewVulkan::~ShellTestPlatformViewVulkan() = default;

std::unique_ptr<VsyncWaiter> ShellTestPlatformViewVulkan::CreateVSyncWaiter() {
return create_vsync_waiter_();
}

void ShellTestPlatformViewVulkan::SimulateVSync() {
vsync_clock_->SimulateVSync();
}

// |PlatformView|
std::unique_ptr<Surface> ShellTestPlatformViewVulkan::CreateRenderingSurface() {
return std::make_unique<GPUSurfaceVulkan>(this, nullptr, true);
}

// |PlatformView|
PointerDataDispatcherMaker ShellTestPlatformViewVulkan::GetDispatcherMaker() {
return [](DefaultPointerDataDispatcher::Delegate& delegate) {
return std::make_unique<SmoothPointerDataDispatcher>(delegate);
};
}

// |GPUSurfaceVulkanDelegate|
fml::RefPtr<vulkan::VulkanProcTable> ShellTestPlatformViewVulkan::vk() {
return proc_table_;
}

} // namespace testing
} // namespace flutter
51 changes: 51 additions & 0 deletions shell/common/shell_test_platform_view_vulkan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_
#define FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_

#include "flutter/shell/common/shell_test_platform_view.h"
#include "flutter/shell/gpu/gpu_surface_vulkan_delegate.h"

namespace flutter {
namespace testing {

class ShellTestPlatformViewVulkan : public ShellTestPlatformView,
public GPUSurfaceVulkanDelegate {
public:
ShellTestPlatformViewVulkan(PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter);

~ShellTestPlatformViewVulkan() override;

void SimulateVSync() override;

private:
CreateVsyncWaiter create_vsync_waiter_;

std::shared_ptr<ShellTestVsyncClock> vsync_clock_;

fml::RefPtr<vulkan::VulkanProcTable> proc_table_;

// |PlatformView|
std::unique_ptr<Surface> CreateRenderingSurface() override;

// |PlatformView|
std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;

// |PlatformView|
PointerDataDispatcherMaker GetDispatcherMaker() override;

// |GPUSurfaceVulkanDelegate|
fml::RefPtr<vulkan::VulkanProcTable> vk() override;

FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformViewVulkan);
};

} // namespace testing
} // namespace flutter

#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_
3 changes: 2 additions & 1 deletion shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ TEST_F(ShellTest,
[task_runners = shell.GetTaskRunners()]() {
return static_cast<std::unique_ptr<VsyncWaiter>>(
std::make_unique<VsyncWaiterFallback>(task_runners));
});
},
ShellTestPlatformView::BackendType::kDefaultBackend);
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
Expand Down
2 changes: 0 additions & 2 deletions shell/platform/fuchsia/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import("//flutter/tools/fuchsia/dart.gni")
import("//flutter/tools/fuchsia/fuchsia_host_bundle.gni")

if (using_fuchsia_sdk) {
testonly = true

product_suffix = ""
is_product = false

Expand Down
Loading