From ab4452b9af17ccc7efb7cfcd74989ffa469f593c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sat, 28 May 2022 08:56:54 +1000 Subject: [PATCH] nvk: add some initial wsi framework. Part-of: --- src/nouveau/vulkan/meson.build | 2 ++ src/nouveau/vulkan/nvk_instance.c | 17 +++++++++++++ src/nouveau/vulkan/nvk_physical_device.c | 12 ++++++++++ src/nouveau/vulkan/nvk_physical_device.h | 11 +++++++++ src/nouveau/vulkan/nvk_wsi.c | 41 ++++++++++++++++++++++++++++++++ src/nouveau/vulkan/nvk_wsi.h | 9 +++++++ 6 files changed, 92 insertions(+) create mode 100644 src/nouveau/vulkan/nvk_wsi.c create mode 100644 src/nouveau/vulkan/nvk_wsi.h diff --git a/src/nouveau/vulkan/meson.build b/src/nouveau/vulkan/meson.build index de93fa9..f35709f 100644 --- a/src/nouveau/vulkan/meson.build +++ b/src/nouveau/vulkan/meson.build @@ -16,6 +16,8 @@ nvk_files = files( 'nvk_private.h', 'nvk_sampler.c', 'nvk_sampler.h', + 'nvk_wsi.c', + 'nvk_wsi.h' ) nouveau_icd = custom_target( diff --git a/src/nouveau/vulkan/nvk_instance.c b/src/nouveau/vulkan/nvk_instance.c index 835bc76..da8cb09 100644 --- a/src/nouveau/vulkan/nvk_instance.c +++ b/src/nouveau/vulkan/nvk_instance.c @@ -10,6 +10,23 @@ nvk_EnumerateInstanceVersion(uint32_t *pApiVersion) } static const struct vk_instance_extension_table instance_extensions = { +#ifdef NVK_USE_WSI_PLATFORM + .KHR_get_surface_capabilities2 = true, + .KHR_surface = true, + .KHR_surface_protected_capabilities = true, +#endif +#ifdef VK_USE_PLATFORM_WAYLAND_KHR + .KHR_wayland_surface = true, +#endif +#ifdef VK_USE_PLATFORM_XCB_KHR + .KHR_xcb_surface = true, +#endif +#ifdef VK_USE_PLATFORM_XLIB_KHR + .KHR_xlib_surface = true, +#endif +#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT + .EXT_acquire_xlib_display = true, +#endif .KHR_get_physical_device_properties2 = true, .EXT_debug_report = true, .EXT_debug_utils = true, diff --git a/src/nouveau/vulkan/nvk_physical_device.c b/src/nouveau/vulkan/nvk_physical_device.c index e0835d5..b2252ea 100644 --- a/src/nouveau/vulkan/nvk_physical_device.c +++ b/src/nouveau/vulkan/nvk_physical_device.c @@ -2,6 +2,7 @@ #include "nvk_entrypoints.h" #include "nvk_instance.h" +#include "nvk_wsi.h" #include "vulkan/runtime/vk_device.h" #include "vulkan/wsi/wsi_common.h" @@ -119,6 +120,10 @@ nvk_get_device_extensions(const struct nvk_physical_device *device, struct vk_device_extension_table *ext) { *ext = (struct vk_device_extension_table) { +#ifdef NVK_USE_WSI_PLATFORM + .KHR_swapchain = true, + .KHR_swapchain_mutable_format = true, +#endif .KHR_variable_pointers = true, }; } @@ -180,6 +185,12 @@ nvk_physical_device_try_create(struct nvk_instance *instance, device->instance = instance; device->dev = ndev; + result = nvk_init_wsi(device); + if (result != VK_SUCCESS) { + vk_error(instance, result); + goto fail_alloc; + } + device->mem_heaps[0].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT; device->mem_types[0].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; device->mem_types[0].heapIndex = 0; @@ -221,6 +232,7 @@ fail_fd: void nvk_physical_device_destroy(struct nvk_physical_device *device) { + nvk_finish_wsi(device); nouveau_ws_device_destroy(device->dev); vk_physical_device_finish(&device->vk); vk_free(&device->instance->vk.alloc, device); diff --git a/src/nouveau/vulkan/nvk_physical_device.h b/src/nouveau/vulkan/nvk_physical_device.h index af51307..aa4535f 100644 --- a/src/nouveau/vulkan/nvk_physical_device.h +++ b/src/nouveau/vulkan/nvk_physical_device.h @@ -7,6 +7,8 @@ #include "vulkan/runtime/vk_physical_device.h" +#include "wsi_common.h" + struct nvk_instance; struct nvk_physical_device { @@ -17,6 +19,8 @@ struct nvk_physical_device { /* Link in nvk_instance::physical_devices */ struct list_head link; + struct wsi_device wsi_device; + // TODO: add mapable VRAM heap if possible VkMemoryHeap mem_heaps[2]; VkMemoryType mem_types[2]; @@ -31,4 +35,11 @@ VK_DEFINE_HANDLE_CASTS(nvk_physical_device, void nvk_physical_device_destroy(struct nvk_physical_device *); +#if defined(VK_USE_PLATFORM_WAYLAND_KHR) || \ + defined(VK_USE_PLATFORM_XCB_KHR) || \ + defined(VK_USE_PLATFORM_XLIB_KHR) || \ + defined(VK_USE_PLATFORM_DISPLAY_KHR) +#define NVK_USE_WSI_PLATFORM +#endif + #endif diff --git a/src/nouveau/vulkan/nvk_wsi.c b/src/nouveau/vulkan/nvk_wsi.c new file mode 100644 index 0000000..257ab5e --- /dev/null +++ b/src/nouveau/vulkan/nvk_wsi.c @@ -0,0 +1,41 @@ + +#include "nvk_wsi.h" +#include "nvk_instance.h" +#include "wsi_common.h" + +static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL +nvk_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName) +{ + VK_FROM_HANDLE(nvk_physical_device, pdevice, physicalDevice); + return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName); +} + +VkResult +nvk_init_wsi(struct nvk_physical_device *physical_device) +{ + struct wsi_device_options wsi_options = { + .sw_device = false + }; + VkResult result = + wsi_device_init(&physical_device->wsi_device, nvk_physical_device_to_handle(physical_device), + nvk_wsi_proc_addr, &physical_device->instance->vk.alloc, + -1, NULL, &wsi_options); + if (result != VK_SUCCESS) + return result; + + physical_device->vk.wsi_device = &physical_device->wsi_device; + return result; +} + +void +nvk_finish_wsi(struct nvk_physical_device *physical_device) +{ + physical_device->vk.wsi_device = NULL; + wsi_device_finish(&physical_device->wsi_device, &physical_device->instance->vk.alloc); +} + +VKAPI_ATTR VkResult VKAPI_CALL +nvk_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo) +{ + return VK_NOT_READY; +} diff --git a/src/nouveau/vulkan/nvk_wsi.h b/src/nouveau/vulkan/nvk_wsi.h new file mode 100644 index 0000000..a84a681 --- /dev/null +++ b/src/nouveau/vulkan/nvk_wsi.h @@ -0,0 +1,9 @@ +#ifndef NVK_WSI_H +#define NVK_WSI_H 1 + +#include "nvk_physical_device.h" + +VkResult nvk_init_wsi(struct nvk_physical_device *physical_device); +void nvk_finish_wsi(struct nvk_physical_device *physical_device); + +#endif -- 2.7.4