vulkan/properties: Handle unsized arrays properly
authorKonstantin Seurer <konstantin.seurer@gmail.com>
Tue, 5 Sep 2023 13:28:29 +0000 (15:28 +0200)
committerMarge Bot <emma+marge@anholt.net>
Mon, 11 Sep 2023 22:01:44 +0000 (22:01 +0000)
Sadly we cannot autogenerate handling for them, so fall back to hand
written handling instead.

Fixes: eaee792 ("vulkan: Add a generated vk_properties struct")
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25055>

src/vulkan/util/vk_physical_device_properties_gen.py

index dfe7f62..df9fb11 100644 (file)
@@ -58,6 +58,10 @@ RENAMED_PROPERTIES = {
     ("SubgroupProperties", "quadOperationsInAllStages"): "subgroupQuadOperationsInAllStages",
 }
 
+SPECIALIZED_PROPERTY_STRUCTS = [
+    "HostImageCopyPropertiesEXT",
+]
+
 @dataclass
 class Property:
     decl: str
@@ -89,10 +93,10 @@ class PropertyStruct:
     properties: typing.List[Property]
 
 def copy_property(dst, src, decl, length="1"):
+    assert "*" not in decl
+
     if "[" in decl:
         return "memcpy(%s, %s, sizeof(%s));" % (dst, src, dst)
-    elif "*" in decl:
-        return "if (%s) memcpy(%s, %s, sizeof(%s[0] * %s));" % (dst, dst, src, dst, length)
     else:
         return "%s = %s;" % (dst, src)
 
@@ -140,6 +144,7 @@ vk_common_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
    vk_foreach_struct(ext, pProperties) {
       switch (ext->sType) {
 % for property_struct in property_structs:
+% if property_struct.name not in SPECIALIZED_PROPERTY_STRUCTS:
       case ${property_struct.s_type}: {
          ${property_struct.c_type} *properties = (void *)ext;
 % for prop in property_struct.properties:
@@ -147,7 +152,39 @@ vk_common_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
 % endfor
          break;
       }
+% endif
 % endfor
+
+      /* Specialized propery handling defined in vk_physical_device_properties_gen.py */
+
+      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_PROPERTIES_EXT: {
+         VkPhysicalDeviceHostImageCopyPropertiesEXT *properties = (void *)ext;
+
+         if (properties->pCopySrcLayouts) {
+            uint32_t written_layout_count = MIN2(properties->copySrcLayoutCount,
+                                                 pdevice->properties.copySrcLayoutCount);
+            memcpy(properties->pCopySrcLayouts, pdevice->properties.pCopySrcLayouts,
+                   sizeof(VkImageLayout) * written_layout_count);
+            properties->copySrcLayoutCount = written_layout_count;
+         } else {
+            properties->copySrcLayoutCount = pdevice->properties.copySrcLayoutCount;
+         }
+
+         if (properties->pCopyDstLayouts) {
+            uint32_t written_layout_count = MIN2(properties->copyDstLayoutCount,
+                                                 pdevice->properties.copyDstLayoutCount);
+            memcpy(properties->pCopyDstLayouts, pdevice->properties.pCopyDstLayouts,
+                   sizeof(VkImageLayout) * written_layout_count);
+            properties->copyDstLayoutCount = written_layout_count;
+         } else {
+            properties->copyDstLayoutCount = pdevice->properties.copyDstLayoutCount;
+         }
+
+         memcpy(properties->optimalTilingLayoutUUID, pdevice->properties.optimalTilingLayoutUUID, VK_UUID_SIZE);
+         properties->identicalMemoryTypeRequirements = pdevice->properties.identicalMemoryTypeRequirements;
+         break;
+      }
+
       default:
          break;
       }
@@ -274,7 +311,8 @@ def main():
         "pdev_properties": pdev_properties,
         "property_structs": property_structs,
         "all_properties": all_properties,
-        "copy_property": copy_property
+        "copy_property": copy_property,
+        "SPECIALIZED_PROPERTY_STRUCTS": SPECIALIZED_PROPERTY_STRUCTS,
     }
 
     try: