Skip to content

Commit

Permalink
Request DLSS extensions only when they are supported
Browse files Browse the repository at this point in the history
  • Loading branch information
kd-11 authored and sultim-t committed Apr 17, 2022
1 parent 135e517 commit 95788d7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Source/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,14 @@ void VulkanDevice::CreateInstance(const RgInstanceCreateInfo &info)
layerNames.push_back("VK_LAYER_LUNARG_monitor");
}

std::vector<VkExtensionProperties> supportedInstanceExtensions;
uint32_t supportedExtensionsCount;

if (vkEnumerateInstanceExtensionProperties(nullptr, &supportedExtensionsCount, nullptr) == VK_SUCCESS)
{
supportedInstanceExtensions.resize(supportedExtensionsCount);
vkEnumerateInstanceExtensionProperties(nullptr, &supportedExtensionsCount, supportedInstanceExtensions.data());
}

std::vector<const char *> extensions =
{
Expand Down Expand Up @@ -1441,6 +1449,18 @@ void VulkanDevice::CreateInstance(const RgInstanceCreateInfo &info)

for (const char *n : DLSS::GetDlssVulkanInstanceExtensions())
{
const bool isSupported = std::any_of(supportedInstanceExtensions.cbegin(), supportedInstanceExtensions.cend(),
[&](const VkExtensionProperties& ext)
{
return !std::strcmp(ext.extensionName, n);
}
);

if (!isSupported)
{
continue;
}

extensions.push_back(n);
}

Expand Down Expand Up @@ -1580,6 +1600,14 @@ void VulkanDevice::CreateDevice()
physicalDeviceFeatures2.pNext = &asFeatures;
physicalDeviceFeatures2.features = features;

std::vector<VkExtensionProperties> supportedDeviceExtensions;
uint32_t supportedExtensionsCount;

if (vkEnumerateDeviceExtensionProperties(physDevice->Get(), nullptr, &supportedExtensionsCount, nullptr) == VK_SUCCESS)
{
supportedDeviceExtensions.resize(supportedExtensionsCount);
vkEnumerateInstanceExtensionProperties(nullptr, &supportedExtensionsCount, supportedDeviceExtensions.data());
}

std::vector<const char *> deviceExtensions = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
Expand All @@ -1593,6 +1621,18 @@ void VulkanDevice::CreateDevice()

for (const char *n : DLSS::GetDlssVulkanDeviceExtensions())
{
const bool isSupported = std::any_of(supportedDeviceExtensions.cbegin(), supportedDeviceExtensions.cend(),
[&](const VkExtensionProperties& ext)
{
return !std::strcmp(ext.extensionName, n);
}
);

if (!isSupported)
{
continue;
}

deviceExtensions.push_back(n);
}

Expand Down

0 comments on commit 95788d7

Please sign in to comment.