From 01a6f128c13aed290dcaecad2aa343214242f016 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Tue, 19 Dec 2023 19:02:26 +0100 Subject: [PATCH] panvk: Move VkQueue logic to panvk_[vX_]queue.{c,h} Signed-off-by: Boris Brezillon Acked-by: Erik Faye-Lund Reviewed-by: Mary Guillemard Reviewed-by: Rebecca Mckeever Part-of: --- src/panfrost/vulkan/meson.build | 2 +- src/panfrost/vulkan/panvk_device.c | 82 +++---------------- src/panfrost/vulkan/panvk_pipeline_layout.h | 2 +- src/panfrost/vulkan/panvk_private.h | 7 +- src/panfrost/vulkan/panvk_queue.h | 43 ++++++++++ .../{panvk_vX_device.c => panvk_vX_queue.c} | 61 +++++++++----- 6 files changed, 99 insertions(+), 98 deletions(-) create mode 100644 src/panfrost/vulkan/panvk_queue.h rename src/panfrost/vulkan/{panvk_vX_device.c => panvk_vX_queue.c} (88%) diff --git a/src/panfrost/vulkan/meson.build b/src/panfrost/vulkan/meson.build index 5844183f194..73d749be64a 100644 --- a/src/panfrost/vulkan/meson.build +++ b/src/panfrost/vulkan/meson.build @@ -65,7 +65,6 @@ foreach arch : ['6', '7'] 'panvk_vX_cmd_buffer.c', 'panvk_vX_descriptor_set.c', 'panvk_vX_descriptor_set_layout.c', - 'panvk_vX_device.c', 'panvk_vX_image_view.c', 'panvk_vX_meta.c', 'panvk_vX_meta_blit.c', @@ -74,6 +73,7 @@ foreach arch : ['6', '7'] 'panvk_vX_nir_lower_descriptors.c', 'panvk_vX_pipeline.c', 'panvk_vX_pipeline_layout.c', + 'panvk_vX_queue.c', 'panvk_vX_sampler.c', 'panvk_vX_shader.c', ], diff --git a/src/panfrost/vulkan/panvk_device.c b/src/panfrost/vulkan/panvk_device.c index 65fa365b08a..b7c2e65b8bb 100644 --- a/src/panfrost/vulkan/panvk_device.c +++ b/src/panfrost/vulkan/panvk_device.c @@ -29,6 +29,7 @@ #include "panvk_device_memory.h" #include "panvk_image.h" #include "panvk_private.h" +#include "panvk_queue.h" #include "decode.h" @@ -923,50 +924,6 @@ panvk_GetPhysicalDeviceMemoryProperties2( }; } -static VkResult -panvk_queue_init(struct panvk_device *device, struct panvk_queue *queue, - int idx, const VkDeviceQueueCreateInfo *create_info) -{ - struct panvk_physical_device *phys_dev = - to_panvk_physical_device(device->vk.physical); - - VkResult result = vk_queue_init(&queue->vk, &device->vk, create_info, idx); - if (result != VK_SUCCESS) - return result; - - struct drm_syncobj_create create = { - .flags = DRM_SYNCOBJ_CREATE_SIGNALED, - }; - - int ret = drmIoctl(device->vk.drm_fd, DRM_IOCTL_SYNCOBJ_CREATE, &create); - if (ret) { - vk_queue_finish(&queue->vk); - return VK_ERROR_OUT_OF_HOST_MEMORY; - } - - unsigned arch = pan_arch(phys_dev->kmod.props.gpu_prod_id); - - switch (arch) { - case 6: - queue->vk.driver_submit = panvk_v6_queue_submit; - break; - case 7: - queue->vk.driver_submit = panvk_v7_queue_submit; - break; - default: - unreachable("Unsupported architecture"); - } - - queue->sync = create.handle; - return VK_SUCCESS; -} - -static void -panvk_queue_finish(struct panvk_queue *queue) -{ - vk_queue_finish(&queue->vk); -} - struct panvk_priv_bo * panvk_priv_bo_create(struct panvk_device *dev, size_t size, uint32_t flags, const struct VkAllocationCallbacks *alloc, @@ -1071,6 +1028,13 @@ panvk_priv_bo_destroy(struct panvk_priv_bo *priv_bo, /* Always reserve the lower 32MB. */ #define PANVK_VA_RESERVE_BOTTOM 0x2000000ull +VkResult panvk_v6_queue_init(struct panvk_device *device, + struct panvk_queue *queue, int idx, + const VkDeviceQueueCreateInfo *create_info); +VkResult panvk_v7_queue_init(struct panvk_device *device, + struct panvk_queue *queue, int idx, + const VkDeviceQueueCreateInfo *create_info); + VKAPI_ATTR VkResult VKAPI_CALL panvk_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, @@ -1091,15 +1055,19 @@ panvk_CreateDevice(VkPhysicalDevice physicalDevice, const struct vk_command_buffer_ops *cmd_buffer_ops; struct vk_device_dispatch_table dispatch_table; unsigned arch = pan_arch(physical_device->kmod.props.gpu_prod_id); + VkResult (*qinit)(struct panvk_device *, struct panvk_queue *, int, + const VkDeviceQueueCreateInfo *); switch (arch) { case 6: dev_entrypoints = &panvk_v6_device_entrypoints; cmd_buffer_ops = &panvk_v6_cmd_buffer_ops; + qinit = panvk_v6_queue_init; break; case 7: dev_entrypoints = &panvk_v7_device_entrypoints; cmd_buffer_ops = &panvk_v7_cmd_buffer_ops; + qinit = panvk_v7_queue_init; break; default: unreachable("Unsupported architecture"); @@ -1197,8 +1165,7 @@ panvk_CreateDevice(VkPhysicalDevice physicalDevice, device->queue_count[qfi] = queue_create->queueCount; for (unsigned q = 0; q < queue_create->queueCount; q++) { - result = - panvk_queue_init(device, &device->queues[qfi][q], q, queue_create); + result = qinit(device, &device->queues[qfi][q], q, queue_create); if (result != VK_SUCCESS) goto fail; } @@ -1264,29 +1231,6 @@ panvk_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount, return VK_SUCCESS; } -VKAPI_ATTR VkResult VKAPI_CALL -panvk_QueueWaitIdle(VkQueue _queue) -{ - VK_FROM_HANDLE(panvk_queue, queue, _queue); - struct panvk_device *dev = to_panvk_device(queue->vk.base.device); - - if (vk_device_is_lost(&dev->vk)) - return VK_ERROR_DEVICE_LOST; - - struct drm_syncobj_wait wait = { - .handles = (uint64_t)(uintptr_t)(&queue->sync), - .count_handles = 1, - .timeout_nsec = INT64_MAX, - .flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL, - }; - int ret; - - ret = drmIoctl(queue->vk.base.device->drm_fd, DRM_IOCTL_SYNCOBJ_WAIT, &wait); - assert(!ret); - - return VK_SUCCESS; -} - VKAPI_ATTR VkResult VKAPI_CALL panvk_EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pPropertyCount, diff --git a/src/panfrost/vulkan/panvk_pipeline_layout.h b/src/panfrost/vulkan/panvk_pipeline_layout.h index ed26d31827c..70e811e6352 100644 --- a/src/panfrost/vulkan/panvk_pipeline_layout.h +++ b/src/panfrost/vulkan/panvk_pipeline_layout.h @@ -8,7 +8,7 @@ #include -#include "vulkan/runtime/vk_pipeline_layout.h" +#include "vk_pipeline_layout.h" #include "panvk_descriptor_set_layout.h" #include "panvk_macros.h" diff --git a/src/panfrost/vulkan/panvk_private.h b/src/panfrost/vulkan/panvk_private.h index ea7cc497744..15a2c740f51 100644 --- a/src/panfrost/vulkan/panvk_private.h +++ b/src/panfrost/vulkan/panvk_private.h @@ -107,6 +107,7 @@ typedef uint32_t xcb_window_t; struct panvk_device; struct panvk_pipeline_layout; +struct panvk_queue; /* Used for internal object allocation. */ struct panvk_priv_bo { @@ -258,11 +259,6 @@ panvk_physical_device_extension_supported(struct panvk_physical_device *dev, #define PANVK_MAX_QUEUE_FAMILIES 1 -struct panvk_queue { - struct vk_queue vk; - uint32_t sync; -}; - struct panvk_device { struct vk_device vk; @@ -467,7 +463,6 @@ VK_DEFINE_HANDLE_CASTS(panvk_instance, vk.base, VkInstance, VK_OBJECT_TYPE_INSTANCE) VK_DEFINE_HANDLE_CASTS(panvk_physical_device, vk.base, VkPhysicalDevice, VK_OBJECT_TYPE_PHYSICAL_DEVICE) -VK_DEFINE_HANDLE_CASTS(panvk_queue, vk.base, VkQueue, VK_OBJECT_TYPE_QUEUE) #ifdef PAN_ARCH #include "panvk_vX_cmd_buffer.h" diff --git a/src/panfrost/vulkan/panvk_queue.h b/src/panfrost/vulkan/panvk_queue.h new file mode 100644 index 00000000000..4e5f4850b5c --- /dev/null +++ b/src/panfrost/vulkan/panvk_queue.h @@ -0,0 +1,43 @@ +/* + * Copyright © 2021 Collabora Ltd. + * SPDX-License-Identifier: MIT + */ + +#ifndef PANVK_QUEUE_H +#define PANVK_QUEUE_H + +#include + +#include "vk_queue.h" + +#include "panvk_private.h" + +struct panvk_queue { + struct vk_queue vk; + uint32_t sync; +}; + +VK_DEFINE_HANDLE_CASTS(panvk_queue, vk.base, VkQueue, VK_OBJECT_TYPE_QUEUE) + +static inline struct panvk_device * +panvk_queue_get_device(const struct panvk_queue *queue) +{ + return container_of(queue->vk.base.device, struct panvk_device, vk); +} + +static inline void +panvk_queue_finish(struct panvk_queue *queue) +{ + struct panvk_device *dev = panvk_queue_get_device(queue); + + vk_queue_finish(&queue->vk); + drmSyncobjDestroy(dev->vk.drm_fd, queue->sync); +} + +#ifdef PAN_ARCH +VkResult panvk_per_arch(queue_init)(struct panvk_device *device, + struct panvk_queue *queue, int idx, + const VkDeviceQueueCreateInfo *create_info); +#endif + +#endif diff --git a/src/panfrost/vulkan/panvk_vX_device.c b/src/panfrost/vulkan/panvk_vX_queue.c similarity index 88% rename from src/panfrost/vulkan/panvk_vX_device.c rename to src/panfrost/vulkan/panvk_vX_queue.c index 095a0ddc6e3..f75f11fda42 100644 --- a/src/panfrost/vulkan/panvk_vX_device.c +++ b/src/panfrost/vulkan/panvk_vX_queue.c @@ -6,24 +6,7 @@ * Copyright © 2016 Bas Nieuwenhuizen * Copyright © 2015 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. + * SPDX-License-Identifier: MIT */ #include "genxml/gen_macros.h" @@ -34,6 +17,7 @@ #include "panvk_image.h" #include "panvk_image_view.h" #include "panvk_private.h" +#include "panvk_queue.h" #include "vk_drm_syncobj.h" #include "vk_framebuffer.h" @@ -206,9 +190,8 @@ panvk_signal_event_syncobjs(struct panvk_queue *queue, } } -VkResult -panvk_per_arch(queue_submit)(struct vk_queue *vk_queue, - struct vk_queue_submit *submit) +static VkResult +panvk_queue_submit(struct vk_queue *vk_queue, struct vk_queue_submit *submit) { struct panvk_queue *queue = container_of(vk_queue, struct panvk_queue, vk); struct panvk_device *dev = to_panvk_device(queue->vk.base.device); @@ -301,3 +284,39 @@ panvk_per_arch(queue_submit)(struct vk_queue *vk_queue, return VK_SUCCESS; } + +VkResult +panvk_per_arch(queue_init)(struct panvk_device *device, + struct panvk_queue *queue, int idx, + const VkDeviceQueueCreateInfo *create_info) +{ + VkResult result = vk_queue_init(&queue->vk, &device->vk, create_info, idx); + if (result != VK_SUCCESS) + return result; + + int ret = drmSyncobjCreate(device->vk.drm_fd, DRM_SYNCOBJ_CREATE_SIGNALED, + &queue->sync); + if (ret) { + vk_queue_finish(&queue->vk); + return VK_ERROR_OUT_OF_HOST_MEMORY; + } + + queue->vk.driver_submit = panvk_queue_submit; + return VK_SUCCESS; +} + +VKAPI_ATTR VkResult VKAPI_CALL +panvk_per_arch(QueueWaitIdle)(VkQueue _queue) +{ + VK_FROM_HANDLE(panvk_queue, queue, _queue); + struct panvk_device *dev = panvk_queue_get_device(queue); + + if (vk_device_is_lost(&dev->vk)) + return VK_ERROR_DEVICE_LOST; + + int ret = drmSyncobjWait(queue->vk.base.device->drm_fd, &queue->sync, 1, + INT64_MAX, DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL, NULL); + assert(!ret); + + return VK_SUCCESS; +}