Skip to content

Commit

Permalink
[vulkan] Check that additional extensions are supported before adding…
Browse files Browse the repository at this point in the history
… them (#2667)
  • Loading branch information
AmesingFlank authored Aug 12, 2021
1 parent 7175829 commit 2fe7f97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions taichi/backends/vulkan/vulkan_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,6 @@ void EmbeddedVulkanDevice::create_instance() {
}

auto extensions = get_required_extensions();
for (auto ext : params_.additional_instance_extensions) {
extensions.push_back(ext);
}

#ifdef TI_VULKAN_DEBUG
glfwInit();
Expand All @@ -302,6 +299,11 @@ void EmbeddedVulkanDevice::create_instance() {
extensions.push_back(ext.extensionName);
}
}
if (std::find(params_.additional_instance_extensions.begin(),
params_.additional_instance_extensions.end(),
name) != params_.additional_instance_extensions.end()) {
extensions.push_back(ext.extensionName);
}
}

create_info.enabledExtensionCount = (uint32_t)extensions.size();
Expand Down Expand Up @@ -401,10 +403,6 @@ void EmbeddedVulkanDevice::create_logical_device() {
// Detect extensions
std::vector<const char *> enabled_extensions;

for (auto ext : params_.additional_device_extensions) {
enabled_extensions.push_back(ext);
}

uint32_t extension_count = 0;
vkEnumerateDeviceExtensionProperties(physical_device_, nullptr,
&extension_count, nullptr);
Expand Down Expand Up @@ -458,6 +456,10 @@ void EmbeddedVulkanDevice::create_logical_device() {
capability_.has_float16 = true;
capability_.has_int8 = true;
enabled_extensions.push_back(ext.extensionName);
} else if (std::find(params_.additional_device_extensions.begin(),
params_.additional_device_extensions.end(),
name) != params_.additional_device_extensions.end()) {
enabled_extensions.push_back(ext.extensionName);
}
}

Expand Down
4 changes: 2 additions & 2 deletions taichi/backends/vulkan/vulkan_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class EmbeddedVulkanDevice {
struct Params {
std::optional<uint32_t> api_version;
bool is_for_ui{false};
std::vector<const char *> additional_instance_extensions;
std::vector<const char *> additional_device_extensions;
std::vector<std::string> additional_instance_extensions;
std::vector<std::string> additional_device_extensions;
// the VkSurfaceKHR needs to be created after creating the VkInstance, but
// before creating the VkPhysicalDevice thus, we allow the user to pass in a
// custom surface creator
Expand Down

0 comments on commit 2fe7f97

Please sign in to comment.