Skip to content

Commit

Permalink
Allow --enable-vulkan with viz_unittests
Browse files Browse the repository at this point in the history
This will use GPU because we do not have vulkan software rasterization.
Main changes:

1) Have SkiaOutputSurfaceImplOnGpu create an offscreen render surface
   when there is no AcceleratedWidget to render to.

2) Have unittests create a VulkanInstance when making their own
   GpuServiceImpl.

Bug: 930740
Change-Id: Ie5b837bac1bcc5576913c8b1019d34196949d6de
Reviewed-on: https://chromium-review.googlesource.com/c/1464652
Commit-Queue: Jonathan Backer <backer@chromium.org>
Reviewed-by: kylechar <kylechar@chromium.org>
Reviewed-by: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631936}
  • Loading branch information
Jonathan Backer authored and Commit Bot committed Feb 13, 2019
1 parent de75013 commit 316ac19
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 145 deletions.
6 changes: 5 additions & 1 deletion cc/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2014 T/e Chromium Authors. All rights reserved.
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//gpu/vulkan/features.gni")

import("//cc/cc.gni")

Expand Down Expand Up @@ -548,6 +549,9 @@ cc_test_static_library("test_support") {
"//ui/gl:test_support",
"//ui/latency",
]
if (enable_vulkan) {
deps += [ "//gpu/vulkan/init" ]
}
if (!is_android) {
data_deps = [
"//third_party/mesa_headers",
Expand Down
3 changes: 3 additions & 0 deletions cc/test/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ specific_include_rules = {
"cc_test_suite\.cc": [
"+gpu/config",
],
"pixel_test\.cc": [
"+gpu/command_buffer/service/service_utils.h",
],
}
27 changes: 26 additions & 1 deletion cc/test/pixel_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "components/viz/test/test_shared_bitmap_manager.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "gpu/command_buffer/service/service_utils.h"
#include "gpu/config/gpu_feature_type.h"
#include "gpu/config/gpu_info.h"
#include "gpu/ipc/gpu_in_process_thread_service.h"
Expand All @@ -49,6 +50,11 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/init/gl_factory.h"

#if BUILDFLAG(ENABLE_VULKAN)
#include "gpu/vulkan/init/vulkan_factory.h"
#include "gpu/vulkan/vulkan_implementation.h"
#endif

namespace cc {

PixelTest::PixelTest()
Expand Down Expand Up @@ -241,16 +247,35 @@ void PixelTest::SetUpGLRenderer(bool flipped_output_surface) {

void PixelTest::SetUpGpuServiceOnGpuThread(base::WaitableEvent* event) {
ASSERT_TRUE(gpu_thread_->task_runner()->BelongsToCurrentThread());
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
gpu::GpuPreferences gpu_preferences =
gpu::gles2::ParseGpuPreferences(command_line);
if (gpu_preferences.enable_vulkan) {
#if BUILDFLAG(ENABLE_VULKAN)
vulkan_implementation_ = gpu::CreateVulkanImplementation();
if (!vulkan_implementation_ ||
!vulkan_implementation_->InitializeVulkanInstance()) {
LOG(FATAL) << "Failed to create and initialize Vulkan implementation.";
}
#else
NOTREACHED();
#endif
}
gpu::GpuFeatureInfo gpu_feature_info;
// To test SkiaRenderer with DDL, we need enable OOP-R.
gpu_feature_info.status_values[gpu::GPU_FEATURE_TYPE_OOP_RASTERIZATION] =
gpu::kGpuFeatureStatusEnabled;
gpu_service_ = std::make_unique<viz::GpuServiceImpl>(
gpu::GPUInfo(), nullptr /* watchdog_thread */, io_thread_->task_runner(),
gpu_feature_info, gpu::GpuPreferences(),
gpu_feature_info, gpu_preferences,
gpu::GPUInfo() /* gpu_info_for_hardware_gpu */,
gpu::GpuFeatureInfo() /* gpu_feature_info_for_hardware_gpu */,
#if BUILDFLAG(ENABLE_VULKAN)
vulkan_implementation_.get(),
#else
nullptr /* vulkan_implementation */,
#endif
base::DoNothing() /* exit_callback */);

// Uses a null gpu_host here, because we don't want to receive any message.
Expand Down
11 changes: 11 additions & 0 deletions cc/test/pixel_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "components/viz/service/display/software_renderer.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
#include "gpu/ipc/in_process_command_buffer.h"
#include "gpu/vulkan/buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gl/gl_implementation.h"
Expand All @@ -29,6 +30,12 @@ class ScopedFeatureList;
}
}

#if BUILDFLAG(ENABLE_VULKAN)
namespace gpu {
class VulkanImplementation;
}
#endif

namespace viz {
class CopyOutputResult;
class DirectRenderer;
Expand Down Expand Up @@ -121,6 +128,10 @@ class PixelTest : public testing::Test {

std::unique_ptr<gl::DisableNullDrawGLBindings> enable_pixel_output_;
std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_;

#if BUILDFLAG(ENABLE_VULKAN)
std::unique_ptr<gpu::VulkanImplementation> vulkan_implementation_;
#endif
};

template<typename RendererType>
Expand Down
4 changes: 4 additions & 0 deletions components/viz/service/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ viz_source_set("unit_tests") {
if (is_android) {
sources += [ "frame_sinks/external_begin_frame_source_android_unittest.cc" ]
}

if (enable_vulkan) {
deps += [ "//gpu/vulkan/init" ]
}
}

viz_source_set("perf_tests") {
Expand Down
Loading

0 comments on commit 316ac19

Please sign in to comment.