Vulkan: Make GatherSurfaceInfo use ResultOrError

Bug: dawn:269

Change-Id: I80ac5ce170b2e7630d8524cd34375bf0f1c67a60
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17961
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn_native/vulkan/NativeSwapChainImplVk.cpp b/src/dawn_native/vulkan/NativeSwapChainImplVk.cpp
index ada090f..11bf089 100644
--- a/src/dawn_native/vulkan/NativeSwapChainImplVk.cpp
+++ b/src/dawn_native/vulkan/NativeSwapChainImplVk.cpp
@@ -83,8 +83,8 @@
     }
 
     void NativeSwapChainImpl::UpdateSurfaceConfig() {
-        if (mDevice->ConsumedError(
-                GatherSurfaceInfo(*ToBackend(mDevice->GetAdapter()), mSurface, &mInfo))) {
+        if (mDevice->ConsumedError(GatherSurfaceInfo(*ToBackend(mDevice->GetAdapter()), mSurface),
+                                   &mInfo)) {
             ASSERT(false);
         }
 
diff --git a/src/dawn_native/vulkan/VulkanInfo.cpp b/src/dawn_native/vulkan/VulkanInfo.cpp
index 9bc68ee..61e1c19 100644
--- a/src/dawn_native/vulkan/VulkanInfo.cpp
+++ b/src/dawn_native/vulkan/VulkanInfo.cpp
@@ -324,21 +324,22 @@
         return info;
     }
 
-    MaybeError GatherSurfaceInfo(const Adapter& adapter,
-                                 VkSurfaceKHR surface,
-                                 VulkanSurfaceInfo* info) {
+    ResultOrError<VulkanSurfaceInfo> GatherSurfaceInfo(const Adapter& adapter,
+                                                       VkSurfaceKHR surface) {
+        VulkanSurfaceInfo info = {};
+
         VkPhysicalDevice physicalDevice = adapter.GetPhysicalDevice();
         const VulkanFunctions& vkFunctions = adapter.GetBackend()->GetFunctions();
 
         // Get the surface capabilities
         DAWN_TRY(CheckVkSuccess(vkFunctions.GetPhysicalDeviceSurfaceCapabilitiesKHR(
-                                    physicalDevice, surface, &info->capabilities),
+                                    physicalDevice, surface, &info.capabilities),
                                 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"));
 
         // Query which queue families support presenting this surface
         {
             size_t nQueueFamilies = adapter.GetDeviceInfo().queueFamilies.size();
-            info->supportedQueueFamilies.resize(nQueueFamilies, false);
+            info.supportedQueueFamilies.resize(nQueueFamilies, false);
 
             for (uint32_t i = 0; i < nQueueFamilies; ++i) {
                 VkBool32 supported = VK_FALSE;
@@ -346,7 +347,7 @@
                                             physicalDevice, i, surface, &supported),
                                         "vkGetPhysicalDeviceSurfaceSupportKHR"));
 
-                info->supportedQueueFamilies[i] = (supported == VK_TRUE);
+                info.supportedQueueFamilies[i] = (supported == VK_TRUE);
             }
         }
 
@@ -359,9 +360,9 @@
                 return DAWN_DEVICE_LOST_ERROR("vkGetPhysicalDeviceSurfaceFormatsKHR");
             }
 
-            info->formats.resize(count);
+            info.formats.resize(count);
             DAWN_TRY(CheckVkSuccess(vkFunctions.GetPhysicalDeviceSurfaceFormatsKHR(
-                                        physicalDevice, surface, &count, info->formats.data()),
+                                        physicalDevice, surface, &count, info.formats.data()),
                                     "vkGetPhysicalDeviceSurfaceFormatsKHR"));
         }
 
@@ -375,13 +376,13 @@
                 return DAWN_DEVICE_LOST_ERROR("vkGetPhysicalDeviceSurfacePresentModesKHR");
             }
 
-            info->presentModes.resize(count);
+            info.presentModes.resize(count);
             DAWN_TRY(CheckVkSuccess(vkFunctions.GetPhysicalDeviceSurfacePresentModesKHR(
-                                        physicalDevice, surface, &count, info->presentModes.data()),
+                                        physicalDevice, surface, &count, info.presentModes.data()),
                                     "vkGetPhysicalDeviceSurfacePresentModesKHR"));
         }
 
-        return {};
+        return info;
     }
 
 }}  // namespace dawn_native::vulkan
diff --git a/src/dawn_native/vulkan/VulkanInfo.h b/src/dawn_native/vulkan/VulkanInfo.h
index 13a0fdd..00254cf 100644
--- a/src/dawn_native/vulkan/VulkanInfo.h
+++ b/src/dawn_native/vulkan/VulkanInfo.h
@@ -122,9 +122,8 @@
     ResultOrError<VulkanGlobalInfo> GatherGlobalInfo(const Backend& backend);
     ResultOrError<std::vector<VkPhysicalDevice>> GetPhysicalDevices(const Backend& backend);
     ResultOrError<VulkanDeviceInfo> GatherDeviceInfo(const Adapter& adapter);
-    MaybeError GatherSurfaceInfo(const Adapter& adapter,
-                                 VkSurfaceKHR surface,
-                                 VulkanSurfaceInfo* info);
+    ResultOrError<VulkanSurfaceInfo> GatherSurfaceInfo(const Adapter& adapter,
+                                                       VkSurfaceKHR surface);
 }}  // namespace dawn_native::vulkan
 
 #endif  // DAWNNATIVE_VULKAN_VULKANINFO_H_