mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Enable Vulkan validation layers for shell_test (flutter/engine#17684)
This commit is contained in:
parent
6e05478105
commit
56bdcec5ae
@ -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")
|
||||
@ -267,6 +268,11 @@ if (enable_unittests) {
|
||||
dest = "assets/shelltest_screenshot.png"
|
||||
},
|
||||
]
|
||||
|
||||
if (test_enable_vulkan) {
|
||||
libraries = vulkan_validation_libs
|
||||
resources += vulkan_icds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 {
|
||||
@ -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
|
||||
|
||||
@ -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",
|
||||
@ -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",
|
||||
@ -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",
|
||||
@ -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",
|
||||
|
||||
@ -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"
|
||||
}
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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()];
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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()];
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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() {
|
||||
@ -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 {};
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user