Skip to content

Commit

Permalink
Enable Vulkan validation layers for shell_test (flutter#17684)
Browse files Browse the repository at this point in the history
  • Loading branch information
George Wright authored Apr 17, 2020
1 parent 6c431f0 commit 9f31d81
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 48 deletions.
6 changes: 6 additions & 0 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import("//flutter/common/config.gni")
import("//flutter/shell/gpu/gpu.gni")
import("//flutter/testing/testing.gni")
import("//flutter/vulkan/config.gni")

if (is_fuchsia) {
import("//build/fuchsia/sdk.gni")
Expand Down Expand Up @@ -267,6 +268,11 @@ if (enable_unittests) {
dest = "assets/shelltest_screenshot.png"
},
]

if (test_enable_vulkan) {
libraries = vulkan_validation_libs
resources += vulkan_icds
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion shell/common/shell_test_platform_view_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "flutter/shell/common/shell_test_platform_view_vulkan.h"
#include "flutter/vulkan/vulkan_utilities.h"

namespace flutter {
namespace testing {
Expand Down Expand Up @@ -65,7 +66,8 @@ ShellTestPlatformViewVulkan::OffScreenSurface::OffScreenSurface(
};

application_ = std::make_unique<vulkan::VulkanApplication>(
*vk_, "FlutterTest", std::move(extensions));
*vk_, "FlutterTest", std::move(extensions), VK_MAKE_VERSION(1, 0, 0),
VK_MAKE_VERSION(1, 1, 0), true);

if (!application_->IsValid() || !vk_->AreInstanceProcsSetup()) {
// Make certain the application instance was created and it setup the
Expand Down
16 changes: 0 additions & 16 deletions shell/platform/fuchsia/flutter/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ flutter_runner("jit") {
extra_defines += [ "FLUTTER_PROFILE" ]
}

if (enable_vulkan_validation_layers) {
extra_defines += [ "VULKAN_VALIDATION_LAYERS_ENABLED" ]
}

extra_deps = [
"//third_party/dart/runtime:libdart_jit",
"//third_party/dart/runtime/platform:libdart_platform_jit",
Expand All @@ -50,10 +46,6 @@ flutter_runner("jit_product") {

extra_defines = [ "DART_PRODUCT" ]

if (enable_vulkan_validation_layers) {
extra_defines += [ "VULKAN_VALIDATION_LAYERS_ENABLED" ]
}

extra_deps = [
"//third_party/dart/runtime:libdart_jit_product",
"//third_party/dart/runtime/platform:libdart_platform_jit_product",
Expand All @@ -69,10 +61,6 @@ flutter_runner("aot") {
extra_defines += [ "FLUTTER_PROFILE" ]
}

if (enable_vulkan_validation_layers) {
extra_defines += [ "VULKAN_VALIDATION_LAYERS_ENABLED" ]
}

extra_deps = [
"//third_party/dart/runtime:libdart_precompiled_runtime",
"//third_party/dart/runtime/platform:libdart_platform_precompiled_runtime",
Expand All @@ -85,10 +73,6 @@ flutter_runner("aot_product") {

extra_defines = [ "DART_PRODUCT" ]

if (enable_vulkan_validation_layers) {
extra_defines += [ "VULKAN_VALIDATION_LAYERS_ENABLED" ]
}

extra_deps = [
"//third_party/dart/runtime:libdart_precompiled_runtime_product",
"//third_party/dart/runtime/platform:libdart_platform_precompiled_runtime_product",
Expand Down
4 changes: 4 additions & 0 deletions tools/fuchsia/fuchsia_archive.gni
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ template("fuchsia_test_archive") {
resources = invoker.resources
}

if (defined(invoker.libraries)) {
libraries += invoker.libraries
}

meta_dir = "//flutter/testing/fuchsia/meta"
cmx_file = "$meta_dir/fuchsia_test.cmx"
}
Expand Down
16 changes: 11 additions & 5 deletions vulkan/vulkan_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ VulkanApplication::VulkanApplication(
const std::string& application_name,
std::vector<std::string> enabled_extensions,
uint32_t application_version,
uint32_t api_version)
: vk(p_vk), api_version_(api_version), valid_(false) {
uint32_t api_version,
bool enable_validation_layers)
: vk(p_vk),
api_version_(api_version),
valid_(false),
enable_validation_layers_(enable_validation_layers) {
// Check if we want to enable debugging.
std::vector<VkExtensionProperties> supported_extensions =
GetSupportedInstanceExtensions(vk);
bool enable_instance_debugging =
IsDebuggingEnabled() &&
enable_validation_layers_ &&
ExtensionSupported(supported_extensions,
VulkanDebugReport::DebugExtensionName());

Expand Down Expand Up @@ -54,7 +58,8 @@ VulkanApplication::VulkanApplication(

// Configure layers.

const std::vector<std::string> enabled_layers = InstanceLayersToEnable(vk);
const std::vector<std::string> enabled_layers =
InstanceLayersToEnable(vk, enable_validation_layers_);

const char* layers[enabled_layers.size()];

Expand Down Expand Up @@ -172,7 +177,8 @@ std::vector<VkPhysicalDevice> VulkanApplication::GetPhysicalDevices() const {
std::unique_ptr<VulkanDevice>
VulkanApplication::AcquireFirstCompatibleLogicalDevice() const {
for (auto device_handle : GetPhysicalDevices()) {
auto logical_device = std::make_unique<VulkanDevice>(vk, device_handle);
auto logical_device = std::make_unique<VulkanDevice>(
vk, device_handle, enable_validation_layers_);
if (logical_device->IsValid()) {
return logical_device;
}
Expand Down
4 changes: 3 additions & 1 deletion vulkan/vulkan_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class VulkanApplication {
const std::string& application_name,
std::vector<std::string> enabled_extensions,
uint32_t application_version = VK_MAKE_VERSION(1, 0, 0),
uint32_t api_version = VK_MAKE_VERSION(1, 0, 0));
uint32_t api_version = VK_MAKE_VERSION(1, 0, 0),
bool enable_validation_layers = false);

~VulkanApplication();

Expand All @@ -48,6 +49,7 @@ class VulkanApplication {
uint32_t api_version_;
std::unique_ptr<VulkanDebugReport> debug_report_;
bool valid_;
bool enable_validation_layers_;

std::vector<VkPhysicalDevice> GetPhysicalDevices() const;
std::vector<VkExtensionProperties> GetSupportedInstanceExtensions(
Expand Down
3 changes: 1 addition & 2 deletions vulkan/vulkan_debug_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ VulkanDebugReport::VulkanDebugReport(
const VulkanProcTable& p_vk,
const VulkanHandle<VkInstance>& application)
: vk(p_vk), application_(application), valid_(false) {
if (!IsDebuggingEnabled() || !vk.CreateDebugReportCallbackEXT ||
!vk.DestroyDebugReportCallbackEXT) {
if (!vk.CreateDebugReportCallbackEXT || !vk.DestroyDebugReportCallbackEXT) {
return;
}

Expand Down
9 changes: 6 additions & 3 deletions vulkan/vulkan_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ static uint32_t FindGraphicsQueueIndex(
}

VulkanDevice::VulkanDevice(VulkanProcTable& p_vk,
VulkanHandle<VkPhysicalDevice> physical_device)
VulkanHandle<VkPhysicalDevice> physical_device,
bool enable_validation_layers)
: vk(p_vk),
physical_device_(std::move(physical_device)),
graphics_queue_index_(std::numeric_limits<uint32_t>::max()),
valid_(false) {
valid_(false),
enable_validation_layers_(enable_validation_layers) {
if (!physical_device_ || !vk.AreInstanceProcsSetup()) {
return;
}
Expand Down Expand Up @@ -69,7 +71,8 @@ VulkanDevice::VulkanDevice(VulkanProcTable& p_vk,
#endif
};

auto enabled_layers = DeviceLayersToEnable(vk, physical_device_);
auto enabled_layers =
DeviceLayersToEnable(vk, physical_device_, enable_validation_layers_);

const char* layers[enabled_layers.size()];

Expand Down
4 changes: 3 additions & 1 deletion vulkan/vulkan_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class VulkanSurface;
class VulkanDevice {
public:
VulkanDevice(VulkanProcTable& vk,
VulkanHandle<VkPhysicalDevice> physical_device);
VulkanHandle<VkPhysicalDevice> physical_device,
bool enable_validation_layers);

~VulkanDevice();

Expand Down Expand Up @@ -71,6 +72,7 @@ class VulkanDevice {
VulkanHandle<VkCommandPool> command_pool_;
uint32_t graphics_queue_index_;
bool valid_;
bool enable_validation_layers_;

std::vector<VkQueueFamilyProperties> GetQueueFamilyProperties() const;

Expand Down
27 changes: 11 additions & 16 deletions vulkan/vulkan_utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@

namespace vulkan {

bool IsDebuggingEnabled() {
#ifndef NDEBUG
return true;
#elif defined(VULKAN_VALIDATION_LAYERS_ENABLED)
return true;
#else
return false;
#endif
}

// Whether to show Vulkan validation layer info messages in addition
// to the error messages.
bool ValidationLayerInfoMessagesEnabled() {
Expand All @@ -35,8 +25,9 @@ bool ValidationErrorsFatal() {

static std::vector<std::string> InstanceOrDeviceLayersToEnable(
const VulkanProcTable& vk,
VkPhysicalDevice physical_device) {
if (!IsDebuggingEnabled()) {
VkPhysicalDevice physical_device,
bool enable_validation_layers) {
if (!enable_validation_layers) {
return {};
}

Expand Down Expand Up @@ -102,18 +93,22 @@ static std::vector<std::string> InstanceOrDeviceLayersToEnable(
return available_candidates;
}

std::vector<std::string> InstanceLayersToEnable(const VulkanProcTable& vk) {
return InstanceOrDeviceLayersToEnable(vk, VK_NULL_HANDLE);
std::vector<std::string> InstanceLayersToEnable(const VulkanProcTable& vk,
bool enable_validation_layers) {
return InstanceOrDeviceLayersToEnable(vk, VK_NULL_HANDLE,
enable_validation_layers);
}

std::vector<std::string> DeviceLayersToEnable(
const VulkanProcTable& vk,
const VulkanHandle<VkPhysicalDevice>& physical_device) {
const VulkanHandle<VkPhysicalDevice>& physical_device,
bool enable_validation_layers) {
if (!physical_device) {
return {};
}

return InstanceOrDeviceLayersToEnable(vk, physical_device);
return InstanceOrDeviceLayersToEnable(vk, physical_device,
enable_validation_layers);
}

} // namespace vulkan
7 changes: 4 additions & 3 deletions vulkan/vulkan_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@

namespace vulkan {

bool IsDebuggingEnabled();
bool ValidationLayerInfoMessagesEnabled();
bool ValidationErrorsFatal();

std::vector<std::string> InstanceLayersToEnable(const VulkanProcTable& vk);
std::vector<std::string> InstanceLayersToEnable(const VulkanProcTable& vk,
bool enable_validation_layers);

std::vector<std::string> DeviceLayersToEnable(
const VulkanProcTable& vk,
const VulkanHandle<VkPhysicalDevice>& physical_device);
const VulkanHandle<VkPhysicalDevice>& physical_device,
bool enable_validation_layers);

} // namespace vulkan

Expand Down

0 comments on commit 9f31d81

Please sign in to comment.