Mesa (main): dzn: refactor error-handling

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 19 16:29:46 UTC 2022


Module: Mesa
Branch: main
Commit: 9eace7f2e48bc254ff47a365605e6cbd3c8f604f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9eace7f2e48bc254ff47a365605e6cbd3c8f604f

Author: Boris Brezillon <boris.brezillon at collabora.com>
Date:   Fri Apr  8 13:32:12 2022 +0200

dzn: refactor error-handling

Here's a couple of cleanups to the error-handling code, now that we're
no longer using ComPtr<T>.

Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15816>

---

 src/microsoft/vulkan/dzn_device.c | 65 +++++++++++++++++++++++----------------
 1 file changed, 38 insertions(+), 27 deletions(-)

diff --git a/src/microsoft/vulkan/dzn_device.c b/src/microsoft/vulkan/dzn_device.c
index 81e4a3639c2..d3b12385df3 100644
--- a/src/microsoft/vulkan/dzn_device.c
+++ b/src/microsoft/vulkan/dzn_device.c
@@ -897,6 +897,20 @@ dzn_GetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice physicalDevice,
       };
 }
 
+static VkResult
+dzn_instance_add_physical_device(struct dzn_instance *instance,
+                                 IDXGIAdapter1 *adapter)
+{
+   DXGI_ADAPTER_DESC1 desc;
+   IDXGIAdapter1_GetDesc1(adapter, &desc);
+
+   if ((instance->debug_flags & DZN_DEBUG_WARP) &&
+       !(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE))
+      return VK_SUCCESS;
+
+    return dzn_physical_device_create(instance, adapter, &desc);
+}
+
 VKAPI_ATTR VkResult VKAPI_CALL
 dzn_EnumeratePhysicalDevices(VkInstance inst,
                              uint32_t *pPhysicalDeviceCount,
@@ -907,26 +921,21 @@ dzn_EnumeratePhysicalDevices(VkInstance inst,
    if (!instance->physical_devices_enumerated) {
       IDXGIFactory4 *factory = dxgi_get_factory(false);
       IDXGIAdapter1 *adapter = NULL;
+      VkResult result = VK_SUCCESS;
       for (UINT i = 0; SUCCEEDED(IDXGIFactory4_EnumAdapters1(factory, i, &adapter)); ++i) {
-         DXGI_ADAPTER_DESC1 desc;
-         IDXGIAdapter1_GetDesc1(adapter, &desc);
-         if (instance->debug_flags & DZN_DEBUG_WARP) {
-            if ((desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) == 0) {
-               IDXGIAdapter1_Release(adapter);
-               continue;
-            }
-         }
-
-         VkResult result =
-            dzn_physical_device_create(instance, adapter, &desc);
+         result =
+            dzn_instance_add_physical_device(instance, adapter);
 
          IDXGIAdapter1_Release(adapter);
-         if (result != VK_SUCCESS) {
-            IDXGIFactory4_Release(factory);
-            return result;
-         }
+
+         if (result != VK_SUCCESS)
+            break;
       }
+
       IDXGIFactory4_Release(factory);
+
+      if (result != VK_SUCCESS)
+         return result;
    }
 
    VK_OUTARRAY_MAKE_TYPED(VkPhysicalDevice, out, pPhysicalDevices,
@@ -1804,7 +1813,8 @@ dzn_device_create_root_sig(struct dzn_device *device,
 {
    struct dzn_instance *instance =
       container_of(device->vk.physical->instance, struct dzn_instance, vk);
-   ID3D10Blob *sig, *error;
+   ID3D12RootSignature *root_sig = NULL;
+   ID3DBlob *sig = NULL, *error = NULL;
 
    if (FAILED(instance->d3d12.serialize_root_sig(desc,
                                                  &sig, &error))) {
@@ -1817,21 +1827,22 @@ dzn_device_create_root_sig(struct dzn_device *device,
                  error_msg);
       }
 
-      ID3D10Blob_Release(error);
-      return NULL;
+      goto out;
    }
 
-   ID3D12RootSignature *root_sig;
-   if (FAILED(ID3D12Device1_CreateRootSignature(device->dev, 0,
-                                                ID3D10Blob_GetBufferPointer(sig),
-                                                ID3D10Blob_GetBufferSize(sig),
-                                                &IID_ID3D12RootSignature,
-                                                &root_sig))) {
+   ID3D12Device1_CreateRootSignature(device->dev, 0,
+                                     ID3D10Blob_GetBufferPointer(sig),
+                                     ID3D10Blob_GetBufferSize(sig),
+                                     &IID_ID3D12RootSignature,
+                                     &root_sig);
+
+out:
+   if (error)
+      ID3D10Blob_Release(error);
+
+   if (sig)
       ID3D10Blob_Release(sig);
-      return NULL;
-   }
 
-   ID3D10Blob_Release(sig);
    return root_sig;
 }
 



More information about the mesa-commit mailing list