Skip to content

Commit

Permalink
[vulkan] improved version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Jan 23, 2025
1 parent 27a078f commit fdbcb76
Showing 1 changed file with 66 additions and 37 deletions.
103 changes: 66 additions & 37 deletions runtime/RHI/Vulkan/Vulkan_Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,31 @@ namespace spartan
uint32_t sdk_version = VK_HEADER_VERSION_COMPLETE;
app_info.apiVersion = min(sdk_version, driver_version);

// the minimum required version is 1.4
if (app_info.apiVersion < VK_API_VERSION_1_4)
{
SP_ERROR_WINDOW("Your machine doesn't support Vulkan 1.4");
}

// in case the SDK is not supported by the driver, prompt the user to update
if (sdk_version > driver_version)
{
// detect and log version
string driver_version_str = to_string(VK_API_VERSION_MAJOR(driver_version)) + "." + to_string(VK_API_VERSION_MINOR(driver_version)) + "." + to_string(VK_API_VERSION_PATCH(driver_version));
string sdk_version_str = to_string(VK_API_VERSION_MAJOR(sdk_version)) + "." + to_string(VK_API_VERSION_MINOR(sdk_version)) + "." + to_string(VK_API_VERSION_PATCH(sdk_version));
SP_LOG_WARNING("Using Vulkan %s, update drivers or wait for GPU vendor to support Vulkan %s, engine may still work", driver_version_str.c_str(), sdk_version_str.c_str());
}

// save the api version we ended up using
version::used = app_info.apiVersion;
RHI_Context::api_version_str = version::to_string();

// some checks
{
// if the driver hasn't been updated to the latest SDK, log a warning
if (sdk_version > driver_version)
{
string version_driver = to_string(VK_API_VERSION_MAJOR(driver_version)) + "." + to_string(VK_API_VERSION_MINOR(driver_version)) + "." + to_string(VK_API_VERSION_PATCH(driver_version));
string version_sdk = to_string(VK_API_VERSION_MAJOR(sdk_version)) + "." + to_string(VK_API_VERSION_MINOR(sdk_version)) + "." + to_string(VK_API_VERSION_PATCH(sdk_version));
SP_LOG_WARNING("Using Vulkan %s, update drivers or wait for GPU vendor to support Vulkan %s, engine may still work", version_driver.c_str(), version_sdk.c_str());

}

// ensure that the machine supports Vulkan 1.4 (as we are using extensions from it)
uint32_t driver_major = VK_API_VERSION_MAJOR(driver_version);
uint32_t driver_minor = VK_API_VERSION_MINOR(driver_version);
uint32_t min_major = VK_API_VERSION_MAJOR(VK_API_VERSION_1_4);
uint32_t min_minor = VK_API_VERSION_MINOR(VK_API_VERSION_1_4);
if (driver_major < min_major || (driver_major == min_major && driver_minor < min_minor))
{
SP_ERROR_WINDOW("Your machine doesn't support Vulkan 1.4");
}
}
}

return app_info;
Expand Down Expand Up @@ -1051,38 +1058,56 @@ namespace spartan
{
VkPhysicalDeviceFeatures2 features = {};
VkPhysicalDeviceRobustness2FeaturesEXT features_robustness = {};
VkPhysicalDeviceVulkan14Features features_1_4 = {};
VkPhysicalDeviceVulkan13Features features_1_3 = {};
VkPhysicalDeviceVulkan12Features features_1_2 = {};
VkPhysicalDeviceFragmentShadingRateFeaturesKHR features_vrs = {};

void detect(bool* is_shading_rate_supported)
{
// features that will be enabled
features_vrs.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR;
features_vrs.pNext = nullptr;

features_robustness.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
features_vrs.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR;
features_robustness.pNext = &features_vrs;
features_1_3.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
features_1_3.pNext = &features_robustness;
features_1_2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
features_1_2.pNext = &features_1_3;
features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
features.pNext = &features_1_2;

// features which are supported

features_1_2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
features_1_2.pNext = &features_robustness;

features_1_3.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
features_1_3.pNext = &features_1_2;

features_1_4.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES;
features_1_4.pNext = &features_1_3;

features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
features.pNext = &features_1_4;

// detect which features are supported
VkPhysicalDeviceFragmentShadingRateFeaturesKHR support_vrs = {};
support_vrs.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR;
VkPhysicalDeviceRobustness2FeaturesEXT support_robustness = {};
support_robustness.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
support_robustness.pNext = &support_vrs;
VkPhysicalDeviceVulkan13Features support_1_3 = {};
support_1_3.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
support_1_3.pNext = &support_robustness;
VkPhysicalDeviceVulkan12Features support_1_2 = {};
support_1_2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
support_1_2.pNext = &support_1_3;
VkPhysicalDeviceFeatures2 support = {};
support.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
support.pNext = &support_1_2;
support_vrs.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR;

VkPhysicalDeviceRobustness2FeaturesEXT support_robustness = {};
support_robustness.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
support_robustness.pNext = &support_vrs;

VkPhysicalDeviceVulkan12Features support_1_2 = {};
support_1_2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
support_1_2.pNext = &support_robustness;

VkPhysicalDeviceVulkan13Features support_1_3 = {};
support_1_3.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
support_1_3.pNext = &support_1_2;

VkPhysicalDeviceVulkan14Features support_1_4 = {};
support_1_4.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES;
support_1_4.pNext = &support_1_3;

VkPhysicalDeviceFeatures2 support = {};
support.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
support.pNext = &support_1_4;

vkGetPhysicalDeviceFeatures2(RHI_Context::device_physical, &support);

// check if certain features are supported and enable them
Expand Down Expand Up @@ -1165,6 +1190,10 @@ namespace spartan

SP_ASSERT(support_robustness.nullDescriptor == VK_TRUE);
features_robustness.nullDescriptor = VK_TRUE;

// AMD doesn't support Vulkan 1.4 yet, so we'll wait on it.
//SP_ASSERT(support_1_4.pushDescriptor == VK_TRUE);
//features_1_4.pushDescriptor = VK_TRUE;
}

// fidelity fx
Expand Down

0 comments on commit fdbcb76

Please sign in to comment.