vulkan: use vk_features for vk_device::enabled_features
authorConstantine Shablya <constantine.shablya@collabora.com>
Wed, 15 Mar 2023 14:04:22 +0000 (16:04 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 16 Mar 2023 08:23:28 +0000 (08:23 +0000)
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21754>

src/vulkan/runtime/vk_device.c
src/vulkan/runtime/vk_device.h
src/vulkan/util/vk_physical_device_features.py

index 5546396..3a18374 100644 (file)
@@ -79,50 +79,9 @@ static void
 collect_enabled_features(struct vk_device *device,
                          const VkDeviceCreateInfo *pCreateInfo)
 {
-   if (pCreateInfo->pEnabledFeatures) {
-      if (pCreateInfo->pEnabledFeatures->robustBufferAccess)
-         device->enabled_features.robustBufferAccess = true;
-   }
-
-   vk_foreach_struct_const(ext, pCreateInfo->pNext) {
-      switch (ext->sType) {
-      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2: {
-         const VkPhysicalDeviceFeatures2 *features = (const void *)ext;
-         if (features->features.robustBufferAccess)
-            device->enabled_features.robustBufferAccess = true;
-         break;
-      }
-
-      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES: {
-         const VkPhysicalDeviceImageRobustnessFeatures *features = (void *)ext;
-         if (features->robustImageAccess)
-            device->enabled_features.robustImageAccess = true;
-         break;
-      }
-
-      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT: {
-         const VkPhysicalDeviceRobustness2FeaturesEXT *features = (void *)ext;
-         if (features->robustBufferAccess2)
-            device->enabled_features.robustBufferAccess2 = true;
-         if (features->robustImageAccess2)
-            device->enabled_features.robustImageAccess2 = true;
-         if (features->nullDescriptor)
-            device->enabled_features.nullDescriptor = true;
-         break;
-      }
-
-      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES: {
-         const VkPhysicalDeviceVulkan13Features *features = (void *)ext;
-         if (features->robustImageAccess)
-            device->enabled_features.robustImageAccess = true;
-         break;
-      }
-
-      default:
-         /* Don't warn */
-         break;
-      }
-   }
+   if (pCreateInfo->pEnabledFeatures)
+      vk_set_physical_device_features_1_0(&device->enabled_features, pCreateInfo->pEnabledFeatures);
+   vk_set_physical_device_features(&device->enabled_features, pCreateInfo->pNext);
 }
 
 VkResult
index c02cf5d..cefcc48 100644 (file)
@@ -27,6 +27,7 @@
 #include "vk_dispatch_table.h"
 #include "vk_extensions.h"
 #include "vk_object.h"
+#include "vk_physical_device_features.h"
 
 #include "util/list.h"
 #include "util/u_atomic.h"
@@ -105,13 +106,8 @@ struct vk_device {
    /** Table of enabled extensions */
    struct vk_device_extension_table enabled_extensions;
 
-   struct {
-      bool robustBufferAccess;
-      bool robustBufferAccess2;
-      bool robustImageAccess;
-      bool robustImageAccess2;
-      bool nullDescriptor;
-   } enabled_features;
+   /** Table of enabled features */
+   struct vk_features enabled_features;
 
    /** Device-level dispatch table */
    struct vk_device_dispatch_table dispatch_table;
index 094b2df..3335402 100644 (file)
@@ -229,6 +229,45 @@ vk_physical_device_check_device_features(struct vk_physical_device *physical_dev
 }
 
 void
+vk_set_physical_device_features_1_0(struct vk_features *all_features,
+                                    const VkPhysicalDeviceFeatures *pFeatures)
+{
+% for flag in pdev_features:
+   if (pFeatures->${flag})
+      all_features->${flag} = true;
+% endfor
+}
+
+void
+vk_set_physical_device_features(struct vk_features *all_features,
+                                const VkPhysicalDeviceFeatures2 *pFeatures)
+{
+   vk_foreach_struct_const(ext, pFeatures) {
+      switch (ext->sType) {
+      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2: {
+         const VkPhysicalDeviceFeatures2 *features = (const void *) ext;
+         vk_set_physical_device_features_1_0(all_features, &features->features);
+         break;
+      }
+
+% for f in feature_structs:
+      case ${f.s_type}: {
+         const ${f.c_type} *features = (const void *) ext;
+% for flag in f.features:
+         if (features->${flag})
+            all_features->${get_renamed_feature(f.c_type, flag)} = true;
+% endfor
+         break;
+      }
+
+% endfor
+      default:
+         break;
+      }
+   }
+}
+
+void
 vk_get_physical_device_features(VkPhysicalDeviceFeatures2 *pFeatures,
                                 const struct vk_features *all_features)
 {
@@ -271,6 +310,14 @@ struct vk_features {
 };
 
 void
+vk_set_physical_device_features_1_0(struct vk_features *all_features,
+                                    const VkPhysicalDeviceFeatures *pFeatures);
+
+void
+vk_set_physical_device_features(struct vk_features *all_features,
+                                const VkPhysicalDeviceFeatures2 *pFeatures);
+
+void
 vk_get_physical_device_features(VkPhysicalDeviceFeatures2 *pFeatures,
                                 const struct vk_features *all_features);