Skip to content

Commit

Permalink
configure validation layers on the vulkanapplication
Browse files Browse the repository at this point in the history
  • Loading branch information
George Wright committed Apr 16, 2020
1 parent 754e7eb commit 92307ea
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 36 deletions.
7 changes: 3 additions & 4 deletions shell/common/shell_test_platform_view_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ ShellTestPlatformViewVulkan::ShellTestPlatformViewVulkan(
create_vsync_waiter_(std::move(create_vsync_waiter)),
vsync_clock_(vsync_clock),
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()),
shell_test_external_view_embedder_(shell_test_external_view_embedder) {
vulkan::SetValidationLayersEnabled(true);
}
shell_test_external_view_embedder_(shell_test_external_view_embedder) { }

ShellTestPlatformViewVulkan::~ShellTestPlatformViewVulkan() = default;

Expand Down Expand Up @@ -68,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
11 changes: 6 additions & 5 deletions vulkan/vulkan_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ 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_ || IsDebuggingEnabled()) &&
ExtensionSupported(supported_extensions,
VulkanDebugReport::DebugExtensionName());

Expand Down Expand Up @@ -54,7 +55,7 @@ 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 +173,7 @@ 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
2 changes: 1 addition & 1 deletion vulkan/vulkan_debug_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ VulkanDebugReport::VulkanDebugReport(
const VulkanProcTable& p_vk,
const VulkanHandle<VkInstance>& application)
: vk(p_vk), application_(application), valid_(false) {
if (!IsDebuggingEnabled() || !vk.CreateDebugReportCallbackEXT ||
if (!vk.CreateDebugReportCallbackEXT ||
!vk.DestroyDebugReportCallbackEXT) {
return;
}
Expand Down
8 changes: 5 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,7 @@ 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
26 changes: 9 additions & 17 deletions vulkan/vulkan_utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,14 @@

namespace vulkan {

static bool sValidationLayersEnabled = false;

bool IsDebuggingEnabled() {
#ifndef NDEBUG
return true;
#else
return ValidationLayersEnabled();
return false;
#endif
}

void SetValidationLayersEnabled(bool enabled) {
sValidationLayersEnabled = enabled;
}

bool ValidationLayersEnabled() {
return sValidationLayersEnabled;
}

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

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

Expand Down Expand Up @@ -110,18 +101,19 @@ 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: 3 additions & 4 deletions vulkan/vulkan_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
namespace vulkan {

bool IsDebuggingEnabled();
void SetValidationLayersEnabled(bool enabled);
bool ValidationLayersEnabled();
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 92307ea

Please sign in to comment.