Skip to content

Commit

Permalink
Vulkan: Enable Fuchsia memory extensions on initialization. (flutter#…
Browse files Browse the repository at this point in the history
…4301)

Refactor querying of supported Vulkan extensions.
  • Loading branch information
mikejurka authored Oct 31, 2017
1 parent afd4229 commit b8fc6b7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 42 deletions.
55 changes: 53 additions & 2 deletions vulkan/vulkan_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ VulkanApplication::VulkanApplication(
uint32_t api_version)
: vk(p_vk), api_version_(api_version), valid_(false) {
// Check if we want to enable debugging.

std::vector<VkExtensionProperties> supported_extensions =
GetSupportedInstanceExtensions(vk);
bool enable_instance_debugging =
IsDebuggingEnabled() && VulkanDebugReport::DebugExtensionSupported(vk);
IsDebuggingEnabled() &&
ExtensionSupported(supported_extensions,
VulkanDebugReport::DebugExtensionName());

// Configure extensions.

if (enable_instance_debugging) {
enabled_extensions.emplace_back(VulkanDebugReport::DebugExtensionName());
}
#if OS_FUCHSIA
if (ExtensionSupported(supported_extensions,
VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME)) {
enabled_extensions.emplace_back(
VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME);
}
#endif

const char* extensions[enabled_extensions.size()];

Expand Down Expand Up @@ -166,4 +176,45 @@ VulkanApplication::AcquireFirstCompatibleLogicalDevice() const {
return nullptr;
}

std::vector<VkExtensionProperties>
VulkanApplication::GetSupportedInstanceExtensions(
const VulkanProcTable& vk) const {
if (!vk.EnumerateInstanceExtensionProperties) {
return std::vector<VkExtensionProperties>();
}

uint32_t count = 0;
if (VK_CALL_LOG_ERROR(vk.EnumerateInstanceExtensionProperties(
nullptr, &count, nullptr)) != VK_SUCCESS) {
return std::vector<VkExtensionProperties>();
}

if (count == 0) {
return std::vector<VkExtensionProperties>();
}

std::vector<VkExtensionProperties> properties;
properties.resize(count);
if (VK_CALL_LOG_ERROR(vk.EnumerateInstanceExtensionProperties(
nullptr, &count, properties.data())) != VK_SUCCESS) {
return std::vector<VkExtensionProperties>();
}

return properties;
}

bool VulkanApplication::ExtensionSupported(
const std::vector<VkExtensionProperties>& supported_instance_extensions,
std::string extension_name) {
uint32_t count = supported_instance_extensions.size();
for (size_t i = 0; i < count; i++) {
if (strncmp(supported_instance_extensions[i].extensionName,
extension_name.c_str(), extension_name.size()) == 0) {
return true;
}
}

return false;
}

} // namespace vulkan
5 changes: 5 additions & 0 deletions vulkan/vulkan_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class VulkanApplication {
bool valid_;

std::vector<VkPhysicalDevice> GetPhysicalDevices() const;
std::vector<VkExtensionProperties> GetSupportedInstanceExtensions(
const VulkanProcTable& vk) const;
bool ExtensionSupported(
const std::vector<VkExtensionProperties>& supported_extensions,
std::string extension_name);

FXL_DISALLOW_COPY_AND_ASSIGN(VulkanApplication);
};
Expand Down
38 changes: 0 additions & 38 deletions vulkan/vulkan_debug_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,6 @@ std::string VulkanDebugReport::DebugExtensionName() {
return VK_EXT_DEBUG_REPORT_EXTENSION_NAME;
}

bool VulkanDebugReport::DebugExtensionSupported(const VulkanProcTable& vk) {
if (!IsDebuggingEnabled()) {
return false;
}

if (!vk.EnumerateInstanceExtensionProperties) {
return false;
}

uint32_t count = 0;
if (VK_CALL_LOG_ERROR(vk.EnumerateInstanceExtensionProperties(
nullptr, &count, nullptr)) != VK_SUCCESS) {
return false;
}

if (count == 0) {
return false;
}

std::vector<VkExtensionProperties> properties;
properties.resize(count);
if (VK_CALL_LOG_ERROR(vk.EnumerateInstanceExtensionProperties(
nullptr, &count, properties.data())) != VK_SUCCESS) {
return false;
}

auto debug_extension_name = DebugExtensionName();

for (size_t i = 0; i < count; i++) {
if (strncmp(properties[i].extensionName, debug_extension_name.c_str(),
debug_extension_name.size()) == 0) {
return true;
}
}

return false;
}

static const char* VkDebugReportFlagsEXTToString(VkDebugReportFlagsEXT flags) {
if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
return "Information";
Expand Down
2 changes: 0 additions & 2 deletions vulkan/vulkan_debug_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace vulkan {

class VulkanDebugReport {
public:
static bool DebugExtensionSupported(const VulkanProcTable& vk);

static std::string DebugExtensionName();

VulkanDebugReport(const VulkanProcTable& vk,
Expand Down
2 changes: 2 additions & 0 deletions vulkan/vulkan_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ VulkanDevice::VulkanDevice(VulkanProcTable& p_vk,
const char* extensions[] = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
#if OS_FUCHSIA
VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME,
VK_KHR_EXTERNAL_MEMORY_FUCHSIA_EXTENSION_NAME,
VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME,
VK_KHR_EXTERNAL_SEMAPHORE_FUCHSIA_EXTENSION_NAME,
#endif
Expand Down

0 comments on commit b8fc6b7

Please sign in to comment.