From 8ee88948e3aa511777cdeb29e76da43059ea8ee5 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Sun, 24 Jan 2021 09:06:09 -0600 Subject: [PATCH] vulkan: Move vk_device to its own file Things are going to start getting more complicated so let's avoid the single mega-file approach. Reviewed-by: Dave Airlie Reviewed-by: Lionel Landwerlin Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/amd/vulkan/radv_private.h | 2 +- src/broadcom/vulkan/v3dv_private.h | 2 +- src/freedreno/vulkan/tu_private.h | 2 +- src/gallium/frontends/lavapipe/lvp_private.h | 2 +- src/intel/vulkan/anv_private.h | 2 +- src/vulkan/Makefile.sources | 2 + src/vulkan/util/meson.build | 2 + src/vulkan/util/vk_deferred_operation.c | 1 + src/vulkan/util/vk_device.c | 61 ++++++++++++++++++++ src/vulkan/util/vk_device.h | 55 ++++++++++++++++++ src/vulkan/util/vk_object.c | 35 +---------- src/vulkan/util/vk_object.h | 20 ------- 12 files changed, 127 insertions(+), 59 deletions(-) create mode 100644 src/vulkan/util/vk_device.c create mode 100644 src/vulkan/util/vk_device.h diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index d1357a10dd7..a2ac8eb030c 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -55,7 +55,7 @@ #include "util/xmlconfig.h" #include "vk_alloc.h" #include "vk_debug_report.h" -#include "vk_object.h" +#include "vk_device.h" #include "vk_format.h" #include "radv_radeon_winsys.h" diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index 6d70bf0fd8c..8e51252b777 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -36,7 +36,7 @@ #include #include -#include "vk_object.h" +#include "vk_device.h" #include diff --git a/src/freedreno/vulkan/tu_private.h b/src/freedreno/vulkan/tu_private.h index de672fb53e6..347505fd3a6 100644 --- a/src/freedreno/vulkan/tu_private.h +++ b/src/freedreno/vulkan/tu_private.h @@ -52,8 +52,8 @@ #include "util/macros.h" #include "util/u_atomic.h" #include "vk_alloc.h" -#include "vk_object.h" #include "vk_debug_report.h" +#include "vk_device.h" #include "wsi_common.h" #include "ir3/ir3_compiler.h" diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h index ff83f93c283..6bf4887ce7c 100644 --- a/src/gallium/frontends/lavapipe/lvp_private.h +++ b/src/gallium/frontends/lavapipe/lvp_private.h @@ -52,7 +52,7 @@ typedef uint32_t xcb_window_t; #include "lvp_extensions.h" #include "lvp_entrypoints.h" -#include "vk_object.h" +#include "vk_device.h" #include "wsi_common.h" diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index f25ca1a6f05..2dd1c9a2ca2 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -62,7 +62,7 @@ #include "util/xmlconfig.h" #include "vk_alloc.h" #include "vk_debug_report.h" -#include "vk_object.h" +#include "vk_device.h" /* Pre-declarations needed for WSI entrypoints */ struct wl_surface; diff --git a/src/vulkan/Makefile.sources b/src/vulkan/Makefile.sources index e979d1a2450..e17a043ac01 100644 --- a/src/vulkan/Makefile.sources +++ b/src/vulkan/Makefile.sources @@ -29,6 +29,8 @@ VULKAN_UTIL_FILES := \ util/vk_debug_report.h \ util/vk_deferred_operation.c \ util/vk_deferred_operation.h \ + util/vk_device.c \ + util/vk_device.h \ util/vk_format.c \ util/vk_object.c \ util/vk_object.h \ diff --git a/src/vulkan/util/meson.build b/src/vulkan/util/meson.build index c719918d0dd..f0078c90258 100644 --- a/src/vulkan/util/meson.build +++ b/src/vulkan/util/meson.build @@ -26,6 +26,8 @@ files_vulkan_util = files( 'vk_debug_report.h', 'vk_deferred_operation.c', 'vk_deferred_operation.h', + 'vk_device.c', + 'vk_device.h', 'vk_format.c', 'vk_object.c', 'vk_object.h', diff --git a/src/vulkan/util/vk_deferred_operation.c b/src/vulkan/util/vk_deferred_operation.c index 765a8b3d4c2..fec6470de39 100644 --- a/src/vulkan/util/vk_deferred_operation.c +++ b/src/vulkan/util/vk_deferred_operation.c @@ -24,6 +24,7 @@ #include "vk_deferred_operation.h" #include "vk_alloc.h" +#include "vk_device.h" VkResult vk_create_deferred_operation(struct vk_device *device, diff --git a/src/vulkan/util/vk_device.c b/src/vulkan/util/vk_device.c new file mode 100644 index 00000000000..782f31b43d1 --- /dev/null +++ b/src/vulkan/util/vk_device.c @@ -0,0 +1,61 @@ +/* + * Copyright © 2020 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "vk_device.h" + +#include "util/hash_table.h" +#include "util/ralloc.h" + +void +vk_device_init(struct vk_device *device, + UNUSED const VkDeviceCreateInfo *pCreateInfo, + const VkAllocationCallbacks *instance_alloc, + const VkAllocationCallbacks *device_alloc) +{ + vk_object_base_init(device, &device->base, VK_OBJECT_TYPE_DEVICE); + if (device_alloc) + device->alloc = *device_alloc; + else + device->alloc = *instance_alloc; + + p_atomic_set(&device->private_data_next_index, 0); + +#ifdef ANDROID + mtx_init(&device->swapchain_private_mtx, mtx_plain); + device->swapchain_private = NULL; +#endif /* ANDROID */ +} + +void +vk_device_finish(UNUSED struct vk_device *device) +{ +#ifdef ANDROID + if (device->swapchain_private) { + hash_table_foreach(device->swapchain_private, entry) + util_sparse_array_finish(entry->data); + ralloc_free(device->swapchain_private); + } +#endif /* ANDROID */ + + vk_object_base_finish(&device->base); +} diff --git a/src/vulkan/util/vk_device.h b/src/vulkan/util/vk_device.h new file mode 100644 index 00000000000..3a1188fd4b7 --- /dev/null +++ b/src/vulkan/util/vk_device.h @@ -0,0 +1,55 @@ +/* + * Copyright © 2020 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#ifndef VK_DEVICE_H +#define VK_DEVICE_H + +#include "vk_object.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct vk_device { + struct vk_object_base base; + VkAllocationCallbacks alloc; + + /* For VK_EXT_private_data */ + uint32_t private_data_next_index; + +#ifdef ANDROID + mtx_t swapchain_private_mtx; + struct hash_table *swapchain_private; +#endif +}; + +void vk_device_init(struct vk_device *device, + const VkDeviceCreateInfo *pCreateInfo, + const VkAllocationCallbacks *instance_alloc, + const VkAllocationCallbacks *device_alloc); +void vk_device_finish(struct vk_device *device); + +#ifdef __cplusplus +} +#endif + +#endif /* VK_DEVICE_H */ diff --git a/src/vulkan/util/vk_object.c b/src/vulkan/util/vk_object.c index 7fed00e42c7..291ef1f33c4 100644 --- a/src/vulkan/util/vk_object.c +++ b/src/vulkan/util/vk_object.c @@ -24,6 +24,7 @@ #include "vk_object.h" #include "vk_alloc.h" +#include "vk_device.h" #include "util/hash_table.h" #include "util/ralloc.h" @@ -43,40 +44,6 @@ vk_object_base_finish(struct vk_object_base *base) util_sparse_array_finish(&base->private_data); } -void -vk_device_init(struct vk_device *device, - UNUSED const VkDeviceCreateInfo *pCreateInfo, - const VkAllocationCallbacks *instance_alloc, - const VkAllocationCallbacks *device_alloc) -{ - vk_object_base_init(device, &device->base, VK_OBJECT_TYPE_DEVICE); - if (device_alloc) - device->alloc = *device_alloc; - else - device->alloc = *instance_alloc; - - p_atomic_set(&device->private_data_next_index, 0); - -#ifdef ANDROID - mtx_init(&device->swapchain_private_mtx, mtx_plain); - device->swapchain_private = NULL; -#endif /* ANDROID */ -} - -void -vk_device_finish(UNUSED struct vk_device *device) -{ -#ifdef ANDROID - if (device->swapchain_private) { - hash_table_foreach(device->swapchain_private, entry) - util_sparse_array_finish(entry->data); - ralloc_free(device->swapchain_private); - } -#endif /* ANDROID */ - - vk_object_base_finish(&device->base); -} - void * vk_object_alloc(struct vk_device *device, const VkAllocationCallbacks *alloc, diff --git a/src/vulkan/util/vk_object.h b/src/vulkan/util/vk_object.h index b93018fa1c1..ee957b77aac 100644 --- a/src/vulkan/util/vk_object.h +++ b/src/vulkan/util/vk_object.h @@ -66,26 +66,6 @@ vk_object_base_from_u64_handle(uint64_t handle, VkObjectType obj_type) return base; } - -struct vk_device { - struct vk_object_base base; - VkAllocationCallbacks alloc; - - /* For VK_EXT_private_data */ - uint32_t private_data_next_index; - -#ifdef ANDROID - mtx_t swapchain_private_mtx; - struct hash_table *swapchain_private; -#endif -}; - -void vk_device_init(struct vk_device *device, - const VkDeviceCreateInfo *pCreateInfo, - const VkAllocationCallbacks *instance_alloc, - const VkAllocationCallbacks *device_alloc); -void vk_device_finish(struct vk_device *device); - #define VK_DEFINE_HANDLE_CASTS(__driver_type, __base, __VkType, __VK_TYPE) \ static inline struct __driver_type * \ __driver_type ## _from_handle(__VkType _handle) \