Vkgetphysicaldevicefeatures2 Work 【Tested】
// 1. Define the structs you care about VkPhysicalDeviceFeatures2 features2 = .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 ; VkPhysicalDeviceVulkan13Features vulkan13Features = .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES ; VkPhysicalDeviceRayTracingPipelineFeaturesKHR rtFeatures = .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR ;
Developers should be cautious when the Vulkan API version is 1.1 or higher but the underlying GPU driver is older. In some cases, calling vkGetPhysicalDeviceFeatures2 on such a system can cause a crash , requiring a fallback or check for driver compatibility.
vkGetPhysicalDeviceFeatures2 is a masterpiece of API design regarding extensibility. It solved the "static struct" problem inherent in C APIs. While it introduces verbosity due to the manual management of the pNext chain, the flexibility it provides is essential for a low-level, cross-vendor API like Vulkan. vkgetphysicaldevicefeatures2
Modern engines should ignore the V1.0 command entirely and use vkGetPhysicalDeviceFeatures2 .
: Querying features is only half the battle. When calling vkCreateDevice , you must pass these same structures in the pNext chain of VkDeviceCreateInfo to actually enable them for your logical device. Modern engines should ignore the V1
// 1. Define the specific extension structs VkPhysicalDeviceRayTracingPipelineFeaturesKHR rtFeatures{}; rtFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR; VkPhysicalDevice16BitStorageFeatures storage16Features{}; storage16Features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES; storage16Features.pNext = &rtFeatures; // Link them! // 2. Define the base struct VkPhysicalDeviceFeatures2 totalFeatures{}; totalFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; totalFeatures.pNext = &storage16Features; // Start the chain // 3. Query the hardware vkGetPhysicalDeviceFeatures2(physicalDevice, &totalFeatures); // 4. Check the results if (rtFeatures.rayTracingPipeline) // Hardware supports Ray Tracing! Use code with caution. Critical Best Practices
It is critical to note that you usually need to enable an instance extension (or rely on a specific Vulkan version) before you can query the corresponding feature structs. your setup would look like this:
: Always ensure every struct in your chain has the correct sType initialized. Forgetting this is a leading cause of driver crashes and "garbage" data returns. Conclusion
If you want to see if a GPU supports Ray Tracing and 16-bit float math, your setup would look like this: