Mesa (main): venus: minor cleanup to physical device init loop
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Aug 31 21:04:14 UTC 2021
Module: Mesa
Branch: main
Commit: e2020484eb99f3bf0cbc2f7263375a8215528a6e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e2020484eb99f3bf0cbc2f7263375a8215528a6e
Author: Chia-I Wu <olvaffe at gmail.com>
Date: Sat Aug 28 20:28:31 2021 -0700
venus: minor cleanup to physical device init loop
v2: let the for-loop increment (Yiwei)
Signed-off-by: Chia-I Wu <olvaffe at gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei at chromium.org> (v1)
Reviewed-by: Ryan Neph <ryanneph at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12637>
---
src/virtio/vulkan/vn_physical_device.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/virtio/vulkan/vn_physical_device.c b/src/virtio/vulkan/vn_physical_device.c
index 1e50e45a75c..491a02c0bf8 100644
--- a/src/virtio/vulkan/vn_physical_device.c
+++ b/src/virtio/vulkan/vn_physical_device.c
@@ -1224,27 +1224,28 @@ vn_instance_enumerate_physical_devices(struct vn_instance *instance)
if (result != VK_SUCCESS)
goto out;
- uint32_t i = 0;
- while (i < count) {
+ /* fully initialize physical devices and discard unsupported ones */
+ uint32_t supported_count = 0;
+ for (uint32_t i = 0; i < count; i++) {
struct vn_physical_device *physical_dev = &physical_devs[i];
result = vn_physical_device_init(physical_dev);
if (result != VK_SUCCESS) {
- vn_physical_device_base_fini(&physical_devs[i].base);
- memmove(&physical_devs[i], &physical_devs[i + 1],
- sizeof(*physical_devs) * (count - i - 1));
- count--;
+ vn_physical_device_base_fini(&physical_dev->base);
continue;
}
- i++;
+ if (supported_count < i)
+ physical_devs[supported_count] = *physical_dev;
+ supported_count++;
}
- if (count) {
- instance->physical_devices = physical_devs;
- instance->physical_device_count = count;
- result = VK_SUCCESS;
- }
+ count = supported_count;
+ if (!count)
+ goto out;
+
+ instance->physical_devices = physical_devs;
+ instance->physical_device_count = count;
out:
if (result != VK_SUCCESS && physical_devs) {
More information about the mesa-commit
mailing list