Convert to new magma_sysmem functions

Bug: 120286
Change-Id: I4cbaeefafdd44734579d798526c97564708dbaac
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/mesa/+/792007
Reviewed-by: Craig Stout <cstout@google.com>
diff --git a/src/intel/vulkan/anv_magma_buffer_collection.c b/src/intel/vulkan/anv_magma_buffer_collection.c
index 1bb82f8..3a6abfd 100644
--- a/src/intel/vulkan/anv_magma_buffer_collection.c
+++ b/src/intel/vulkan/anv_magma_buffer_collection.c
@@ -59,8 +59,8 @@
       return ANV_MAGMA_DRET(VK_ERROR_DEVICE_LOST);
 
    magma_buffer_collection_t magma_buffer_collection;
-   status = magma_buffer_collection_import(sysmem_connection, pCreateInfo->collectionToken,
-                                           &magma_buffer_collection);
+   status = magma_sysmem_connection_import_buffer_collection(
+       sysmem_connection, pCreateInfo->collectionToken, &magma_buffer_collection);
    if (status != MAGMA_STATUS_OK)
       return ANV_MAGMA_DRET(VK_ERROR_INVALID_EXTERNAL_HANDLE);
 
@@ -91,10 +91,10 @@
       return;
 
    if (buffer_collection->constraints) {
-     magma_buffer_constraints_release(sysmem_connection, buffer_collection->constraints);
+      magma_buffer_constraints_release2(buffer_collection->constraints);
    }
 
-   magma_buffer_collection_release(sysmem_connection, buffer_collection->buffer_collection);
+   magma_buffer_collection_release2(buffer_collection->buffer_collection);
    vk_free2(&device->vk.alloc, pAllocator, buffer_collection);
 }
 
@@ -267,14 +267,15 @@
        .max_buffer_count = pConstraints->bufferCollectionConstraints.maxBufferCount};
 
    magma_sysmem_buffer_constraints_t constraints;
-   status = magma_buffer_constraints_create(sysmem_connection, &format_constraints, &constraints);
+   status = magma_sysmem_connection_create_buffer_constraints(sysmem_connection,
+                                                              &format_constraints, &constraints);
    if (status != MAGMA_STATUS_OK)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
-   status = magma_buffer_collection_set_constraints(
-       sysmem_connection, buffer_collection->buffer_collection, constraints);
+   status =
+       magma_buffer_collection_set_constraints2(buffer_collection->buffer_collection, constraints);
 
-   magma_buffer_constraints_release(sysmem_connection, constraints);
+   magma_buffer_constraints_release2(constraints);
 
    if (status != MAGMA_STATUS_OK)
       return VK_ERROR_FORMAT_NOT_SUPPORTED;
@@ -328,23 +329,23 @@
    if (status != MAGMA_STATUS_OK)
       return ANV_MAGMA_DRET(VK_ERROR_DEVICE_LOST);
 
-   magma_buffer_format_description_t description;
-   status = magma_sysmem_get_description_from_collection(
-       sysmem_connection, buffer_collection->buffer_collection, &description);
+   magma_collection_info_t collection_info;
+   status = magma_buffer_collection_get_collection_info(buffer_collection->buffer_collection,
+                                                        &collection_info);
    if (status != MAGMA_STATUS_OK)
       return ANV_MAGMA_DRET(VK_ERROR_OUT_OF_HOST_MEMORY);
 
    uint32_t count;
-   status = magma_get_buffer_count(description, &count);
+   status = magma_collection_info_get_buffer_count(collection_info, &count);
    if (status != MAGMA_STATUS_OK) {
-      magma_buffer_format_description_release(description);
+      magma_collection_info_release(collection_info);
       return ANV_MAGMA_DRET(VK_ERROR_OUT_OF_HOST_MEMORY);
    }
 
    uint32_t sysmem_format;
-   status = magma_get_buffer_format(description, &sysmem_format);
+   status = magma_collection_info_get_format(collection_info, &sysmem_format);
    if (status != MAGMA_STATUS_OK) {
-      magma_buffer_format_description_release(description);
+      magma_collection_info_release(collection_info);
       return ANV_MAGMA_DRET(VK_ERROR_OUT_OF_HOST_MEMORY);
    }
 
@@ -352,14 +353,15 @@
 
    magma_bool_t has_format_modifier;
    uint64_t format_modifier = 0;
-   status = magma_get_buffer_format_modifier(description, &has_format_modifier, &format_modifier);
+   status = magma_collection_info_get_format_modifier(collection_info, &has_format_modifier,
+                                                      &format_modifier);
    if (status != MAGMA_STATUS_OK) {
-      magma_buffer_format_description_release(description);
+      magma_collection_info_release(collection_info);
       return ANV_MAGMA_DRET(VK_ERROR_OUT_OF_HOST_MEMORY);
    }
 
    uint32_t color_space = MAGMA_COLORSPACE_INVALID;
-   magma_get_buffer_color_space(description, &color_space);
+   magma_collection_info_get_color_space(collection_info, &color_space);
    // Colorspace may be invalid for non-images, so ignore error.
 
    pProperties->sysmemColorSpaceIndex.colorSpace = color_space;
@@ -407,11 +409,10 @@
 
    if (buffer_collection->constraints) {
       magma_bool_t format_valid[kMaxFormatIndices];
-      status = magma_get_description_format_index(sysmem_connection, description,
-                                                  buffer_collection->constraints, format_valid,
-                                                  kMaxFormatIndices);
+      status = magma_collection_info_get_format_index(
+          collection_info, buffer_collection->constraints, format_valid, kMaxFormatIndices);
       if (status != MAGMA_STATUS_OK) {
-         magma_buffer_format_description_release(description);
+         magma_collection_info_release(collection_info);
          return ANV_MAGMA_DRET(VK_ERROR_OUT_OF_HOST_MEMORY);
       }
 
@@ -442,7 +443,7 @@
       }
    }
 
-   magma_buffer_format_description_release(description);
+   magma_collection_info_release(collection_info);
 
    pProperties->bufferCount = count;
 
@@ -505,17 +506,7 @@
           .ram_domain_supported = true,
           .cpu_domain_supported = true,
           .min_size_bytes = 0,
-      };
-
-      status =
-          magma_buffer_constraints_create(sysmem_connection, &format_constraints, &constraints);
-      if (status != MAGMA_STATUS_OK)
-         return ANV_MAGMA_DRET(VK_ERROR_OUT_OF_HOST_MEMORY);
-   }
-
-   // Add additional constraints.
-   {
-      magma_buffer_format_additional_constraints_t additional = {
+          .options = MAGMA_BUFFER_FORMAT_CONSTRAINT_OPTIONS_EXTRA_COUNTS,
           .min_buffer_count_for_camping =
               pImageConstraintsInfo->bufferCollectionConstraints.minBufferCountForCamping,
           .min_buffer_count_for_shared_slack =
@@ -524,11 +515,10 @@
               pImageConstraintsInfo->bufferCollectionConstraints.minBufferCountForDedicatedSlack,
           .max_buffer_count = pImageConstraintsInfo->bufferCollectionConstraints.maxBufferCount};
 
-      status = magma_buffer_constraints_add_additional(sysmem_connection, constraints, &additional);
-      if (status != MAGMA_STATUS_OK) {
-         magma_buffer_constraints_release(sysmem_connection, constraints);
+      status = magma_sysmem_connection_create_buffer_constraints(sysmem_connection,
+                                                                 &format_constraints, &constraints);
+      if (status != MAGMA_STATUS_OK)
          return ANV_MAGMA_DRET(VK_ERROR_OUT_OF_HOST_MEMORY);
-      }
    }
 
    uint32_t format_index = 0;
@@ -638,36 +628,35 @@
 
          collection->format_index_input_index_map[format_index] = i;
 
-         status = magma_buffer_constraints_set_format(sysmem_connection, constraints, format_index,
-                                                      &image_constraints[slot]);
+         status = magma_buffer_constraints_set_format2(constraints, format_index,
+                                                       &image_constraints[slot]);
          if (status != MAGMA_STATUS_OK) {
-            magma_buffer_constraints_release(sysmem_connection, constraints);
+            magma_buffer_constraints_release2(constraints);
             return ANV_MAGMA_DRET(VK_ERROR_FORMAT_NOT_SUPPORTED);
          }
 
          if (colorSpaceCount) {
-            magma_buffer_constraints_set_colorspaces(sysmem_connection, constraints, format_index,
-                                                     colorSpaceCount, color_spaces);
+            magma_buffer_constraints_set_colorspaces2(constraints, format_index, colorSpaceCount,
+                                                      color_spaces);
          }
 
          format_index += 1;
          if (format_index >= kMaxFormatIndices) {
             assert(!(format_index >= kMaxFormatIndices));
-            magma_buffer_constraints_release(sysmem_connection, constraints);
+            magma_buffer_constraints_release2(constraints);
             return ANV_MAGMA_DRET(VK_ERROR_OUT_OF_HOST_MEMORY);
          }
       }
    }
 
    if (format_index == 0) {
-      magma_buffer_constraints_release(sysmem_connection, constraints);
+      magma_buffer_constraints_release2(constraints);
       return ANV_MAGMA_DRET(VK_ERROR_FORMAT_NOT_SUPPORTED);
    }
 
-   status = magma_buffer_collection_set_constraints(sysmem_connection,
-                                                    collection->buffer_collection, constraints);
+   status = magma_buffer_collection_set_constraints2(collection->buffer_collection, constraints);
    if (status != MAGMA_STATUS_OK) {
-      magma_buffer_constraints_release(sysmem_connection, constraints);
+      magma_buffer_constraints_release2(constraints);
       return ANV_MAGMA_DRET(VK_ERROR_FORMAT_NOT_SUPPORTED);
    }
 
@@ -676,29 +665,29 @@
    return VK_SUCCESS;
 }
 
-// Takes ownership of the buffer format description.
-static VkResult
-anv_image_params_from_description(magma_buffer_format_description_t description, uint32_t width,
-                                  uint32_t height,
-                                  VkImageDrmFormatModifierExplicitCreateInfoEXT* modifier_info_out,
-                                  VkSubresourceLayout* subresource_layout_out)
+// Takes ownership of the buffer format collection_info.
+static VkResult anv_image_params_from_collection_info(
+    magma_collection_info_t collection_info, uint32_t width, uint32_t height,
+    VkImageDrmFormatModifierExplicitCreateInfoEXT* modifier_info_out,
+    VkSubresourceLayout* subresource_layout_out)
 {
    magma_bool_t has_format_modifier;
    uint64_t format_modifier;
    magma_status_t status = MAGMA_STATUS_OK;
    magma_image_plane_t magma_planes[MAGMA_MAX_IMAGE_PLANES];
 
-   status = magma_get_buffer_format_plane_info_with_size(description, width, height, magma_planes);
+   status =
+       magma_collection_info_get_plane_info_with_size(collection_info, width, height, magma_planes);
    if (status == MAGMA_STATUS_OK) {
-      status =
-          magma_get_buffer_format_modifier(description, &has_format_modifier, &format_modifier);
+      status = magma_collection_info_get_format_modifier(collection_info, &has_format_modifier,
+                                                         &format_modifier);
    }
    uint32_t magma_format;
    if (status == MAGMA_STATUS_OK) {
-      status = magma_get_buffer_format(description, &magma_format);
+      status = magma_collection_info_get_format(collection_info, &magma_format);
    }
 
-   magma_buffer_format_description_release(description);
+   magma_collection_info_release(collection_info);
 
    if (status != MAGMA_STATUS_OK)
       return ANV_MAGMA_DRET(VK_ERROR_FORMAT_NOT_SUPPORTED);
@@ -779,16 +768,16 @@
       get_anv_connection(device->vk.magma_connection), &sysmem_connection);
    if (status != MAGMA_STATUS_OK)
       return ANV_MAGMA_DRET(VK_ERROR_DEVICE_LOST);
-   magma_buffer_format_description_t description;
-   status = magma_sysmem_get_description_from_collection(
-       sysmem_connection, buffer_collection->buffer_collection, &description);
+   magma_collection_info_t collection_info;
+   status = magma_buffer_collection_get_collection_info(buffer_collection->buffer_collection,
+                                                        &collection_info);
    if (status != MAGMA_STATUS_OK)
       return ANV_MAGMA_DRET(VK_ERROR_DEVICE_LOST);
    uint32_t width = extent ? extent->width : 0u;
    uint32_t height = extent ? extent->height : 0;
 
-   return anv_image_params_from_description(description, width, height, modifier_info_out,
-                                            subresource_layout_out);
+   return anv_image_params_from_collection_info(collection_info, width, height, modifier_info_out,
+                                                subresource_layout_out);
 }
 
 VkResult anv_memory_params_from_buffer_collection(VkDevice vk_device,
@@ -803,16 +792,16 @@
       get_anv_connection(device->vk.magma_connection), &sysmem_connection);
    if (status != MAGMA_STATUS_OK)
       return ANV_MAGMA_DRET(VK_ERROR_DEVICE_LOST);
-   magma_buffer_format_description_t description;
-   status = magma_sysmem_get_description_from_collection(
-       sysmem_connection, buffer_collection->buffer_collection, &description);
+   magma_collection_info_t collection_info;
+   status = magma_buffer_collection_get_collection_info(buffer_collection->buffer_collection,
+                                                        &collection_info);
    if (status != MAGMA_STATUS_OK)
       return ANV_MAGMA_DRET(VK_ERROR_DEVICE_LOST);
    uint32_t coherency_domain;
    if (status == MAGMA_STATUS_OK) {
-      status = magma_get_buffer_coherency_domain(description, &coherency_domain);
+      status = magma_collection_info_get_coherency_domain(collection_info, &coherency_domain);
    }
-   magma_buffer_format_description_release(description);
+   magma_collection_info_release(collection_info);
 
    if (status != MAGMA_STATUS_OK)
       return ANV_MAGMA_DRET(VK_ERROR_FORMAT_NOT_SUPPORTED);
@@ -831,9 +820,8 @@
       get_anv_connection(device->vk.magma_connection), &sysmem_connection);
    if (status != MAGMA_STATUS_OK)
       return ANV_MAGMA_DRET(VK_ERROR_DEVICE_LOST);
-   if (magma_sysmem_get_buffer_handle_from_collection(sysmem_connection,
-                                                      buffer_collection->buffer_collection, index,
-                                                      handle_out, offset_out) != MAGMA_STATUS_OK) {
+   if (magma_buffer_collection_get_buffer_handle(buffer_collection->buffer_collection, index,
+                                                 handle_out, offset_out) != MAGMA_STATUS_OK) {
       return ANV_MAGMA_DRET(VK_ERROR_DEVICE_LOST);
    }
    return VK_SUCCESS;