panvk: Move the VkInstance logic to panvk_instance.{c,h}

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Reviewed-by: Rebecca Mckeever <rebecca.mckeever@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28170>
This commit is contained in:
Boris Brezillon 2023-12-20 13:04:26 +01:00 committed by Marge Bot
parent 5b0ff2643f
commit afdca26091
11 changed files with 275 additions and 233 deletions

View file

@ -44,6 +44,7 @@ libpanvk_files = files(
'panvk_event.c',
'panvk_formats.c',
'panvk_image.c',
'panvk_instance.c',
'panvk_mempool.c',
'panvk_pipeline.c',
'panvk_private.h',

View file

@ -28,6 +28,7 @@
#include "panvk_device_memory.h"
#include "panvk_image.h"
#include "panvk_instance.h"
#include "panvk_private.h"
#include "panvk_queue.h"
@ -94,46 +95,8 @@ panvk_get_device_uuid(void *uuid)
memset(uuid, 0, VK_UUID_SIZE);
}
static const struct debug_control panvk_debug_options[] = {
{"startup", PANVK_DEBUG_STARTUP},
{"nir", PANVK_DEBUG_NIR},
{"trace", PANVK_DEBUG_TRACE},
{"sync", PANVK_DEBUG_SYNC},
{"afbc", PANVK_DEBUG_AFBC},
{"linear", PANVK_DEBUG_LINEAR},
{"dump", PANVK_DEBUG_DUMP},
{"no_known_warn", PANVK_DEBUG_NO_KNOWN_WARN},
{NULL, 0}};
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
#define PANVK_USE_WSI_PLATFORM
#endif
#define PANVK_API_VERSION VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION)
VKAPI_ATTR VkResult VKAPI_CALL
panvk_EnumerateInstanceVersion(uint32_t *pApiVersion)
{
*pApiVersion = PANVK_API_VERSION;
return VK_SUCCESS;
}
static const struct vk_instance_extension_table panvk_instance_extensions = {
.KHR_get_physical_device_properties2 = true,
.EXT_debug_report = true,
.EXT_debug_utils = true,
#ifdef PANVK_USE_WSI_PLATFORM
.KHR_surface = true,
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
.KHR_wayland_surface = true,
#endif
#ifndef VK_USE_PLATFORM_WIN32_KHR
.EXT_headless_surface = true,
#endif
};
static void
panvk_get_device_extensions(const struct panvk_physical_device *device,
struct vk_device_extension_table *ext)
@ -278,11 +241,7 @@ panvk_get_features(const struct panvk_physical_device *device,
};
}
VkResult panvk_physical_device_try_create(struct vk_instance *vk_instance,
struct _drmDevice *drm_device,
struct vk_physical_device **out);
static void
void
panvk_physical_device_finish(struct panvk_physical_device *device)
{
panvk_wsi_finish(device);
@ -294,98 +253,7 @@ panvk_physical_device_finish(struct panvk_physical_device *device)
vk_physical_device_finish(&device->vk);
}
static void
panvk_destroy_physical_device(struct vk_physical_device *device)
{
panvk_physical_device_finish((struct panvk_physical_device *)device);
vk_free(&device->instance->alloc, device);
}
static void *
panvk_kmod_zalloc(const struct pan_kmod_allocator *allocator, size_t size,
bool transient)
{
const VkAllocationCallbacks *vkalloc = allocator->priv;
return vk_zalloc(vkalloc, size, 8,
transient ? VK_SYSTEM_ALLOCATION_SCOPE_COMMAND
: VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
}
static void
panvk_kmod_free(const struct pan_kmod_allocator *allocator, void *data)
{
const VkAllocationCallbacks *vkalloc = allocator->priv;
return vk_free(vkalloc, data);
}
VKAPI_ATTR VkResult VKAPI_CALL
panvk_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkInstance *pInstance)
{
struct panvk_instance *instance;
VkResult result;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
pAllocator = pAllocator ?: vk_default_allocator();
instance = vk_zalloc(pAllocator, sizeof(*instance), 8,
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (!instance)
return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
struct vk_instance_dispatch_table dispatch_table;
vk_instance_dispatch_table_from_entrypoints(
&dispatch_table, &panvk_instance_entrypoints, true);
vk_instance_dispatch_table_from_entrypoints(
&dispatch_table, &wsi_instance_entrypoints, false);
result = vk_instance_init(&instance->vk, &panvk_instance_extensions,
&dispatch_table, pCreateInfo, pAllocator);
if (result != VK_SUCCESS) {
vk_free(pAllocator, instance);
return vk_error(NULL, result);
}
instance->kmod.allocator = (struct pan_kmod_allocator){
.zalloc = panvk_kmod_zalloc,
.free = panvk_kmod_free,
.priv = &instance->vk.alloc,
};
instance->vk.physical_devices.try_create_for_drm =
panvk_physical_device_try_create;
instance->vk.physical_devices.destroy = panvk_destroy_physical_device;
instance->debug_flags =
parse_debug_string(getenv("PANVK_DEBUG"), panvk_debug_options);
if (instance->debug_flags & PANVK_DEBUG_STARTUP)
vk_logi(VK_LOG_NO_OBJS(instance), "Created an instance");
VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
*pInstance = panvk_instance_to_handle(instance);
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL
panvk_DestroyInstance(VkInstance _instance,
const VkAllocationCallbacks *pAllocator)
{
VK_FROM_HANDLE(panvk_instance, instance, _instance);
if (!instance)
return;
vk_instance_finish(&instance->vk);
vk_free(&instance->vk.alloc, instance);
}
static VkResult
VkResult
panvk_physical_device_init(struct panvk_physical_device *device,
struct panvk_instance *instance,
drmDevicePtr drm_device)
@ -521,34 +389,6 @@ fail:
return result;
}
VkResult
panvk_physical_device_try_create(struct vk_instance *vk_instance,
struct _drmDevice *drm_device,
struct vk_physical_device **out)
{
struct panvk_instance *instance =
container_of(vk_instance, struct panvk_instance, vk);
if (!(drm_device->available_nodes & (1 << DRM_NODE_RENDER)) ||
drm_device->bustype != DRM_BUS_PLATFORM)
return VK_ERROR_INCOMPATIBLE_DRIVER;
struct panvk_physical_device *device =
vk_zalloc(&instance->vk.alloc, sizeof(*device), 8,
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (!device)
return vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
VkResult result = panvk_physical_device_init(device, instance, drm_device);
if (result != VK_SUCCESS) {
vk_free(&instance->vk.alloc, device);
return result;
}
*out = &device->vk;
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL
panvk_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
VkPhysicalDeviceProperties2 *pProperties)
@ -1063,44 +903,6 @@ panvk_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator)
panvk_arch_dispatch(arch, destroy_device, device, pAllocator);
}
VKAPI_ATTR VkResult VKAPI_CALL
panvk_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount,
VkLayerProperties *pProperties)
{
*pPropertyCount = 0;
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL
panvk_EnumerateInstanceExtensionProperties(const char *pLayerName,
uint32_t *pPropertyCount,
VkExtensionProperties *pProperties)
{
if (pLayerName)
return vk_error(NULL, VK_ERROR_LAYER_NOT_PRESENT);
return vk_enumerate_instance_extension_properties(
&panvk_instance_extensions, pPropertyCount, pProperties);
}
PFN_vkVoidFunction
panvk_GetInstanceProcAddr(VkInstance _instance, const char *pName)
{
VK_FROM_HANDLE(panvk_instance, instance, _instance);
return vk_instance_get_proc_addr(&instance->vk, &panvk_instance_entrypoints,
pName);
}
/* The loader wants us to expose a second GetInstanceProcAddr function
* to work around certain LD_PRELOAD issues seen in apps.
*/
PUBLIC
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(VkInstance instance, const char *pName)
{
return panvk_GetInstanceProcAddr(instance, pName);
}
VKAPI_ATTR void VKAPI_CALL
panvk_GetPhysicalDeviceExternalSemaphoreProperties(
VkPhysicalDevice physicalDevice,

View file

@ -30,6 +30,7 @@
#include "panvk_device_memory.h"
#include "panvk_image.h"
#include "panvk_instance.h"
#include "panvk_private.h"
#include "drm-uapi/drm_fourcc.h"

View file

@ -0,0 +1,212 @@
/*
* Copyright © 2021 Collabora Ltd.
*
* Derived from tu_device.c which is:
* Copyright © 2016 Red Hat.
* Copyright © 2016 Bas Nieuwenhuizen
* Copyright © 2015 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/
#include "vk_alloc.h"
#include "vk_log.h"
#include "panvk_entrypoints.h"
#include "panvk_instance.h"
#include "panvk_private.h"
static const struct debug_control panvk_debug_options[] = {
{"startup", PANVK_DEBUG_STARTUP},
{"nir", PANVK_DEBUG_NIR},
{"trace", PANVK_DEBUG_TRACE},
{"sync", PANVK_DEBUG_SYNC},
{"afbc", PANVK_DEBUG_AFBC},
{"linear", PANVK_DEBUG_LINEAR},
{"dump", PANVK_DEBUG_DUMP},
{"no_known_warn", PANVK_DEBUG_NO_KNOWN_WARN},
{NULL, 0}};
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
#define PANVK_USE_WSI_PLATFORM
#endif
VKAPI_ATTR VkResult VKAPI_CALL
panvk_EnumerateInstanceVersion(uint32_t *pApiVersion)
{
*pApiVersion = VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION);
return VK_SUCCESS;
}
static const struct vk_instance_extension_table panvk_instance_extensions = {
.KHR_get_physical_device_properties2 = true,
.EXT_debug_report = true,
.EXT_debug_utils = true,
#ifdef PANVK_USE_WSI_PLATFORM
.KHR_surface = true,
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
.KHR_wayland_surface = true,
#endif
#ifndef VK_USE_PLATFORM_WIN32_KHR
.EXT_headless_surface = true,
#endif
};
static VkResult
panvk_physical_device_try_create(struct vk_instance *vk_instance,
struct _drmDevice *drm_device,
struct vk_physical_device **out)
{
struct panvk_instance *instance =
container_of(vk_instance, struct panvk_instance, vk);
if (!(drm_device->available_nodes & (1 << DRM_NODE_RENDER)) ||
drm_device->bustype != DRM_BUS_PLATFORM)
return VK_ERROR_INCOMPATIBLE_DRIVER;
struct panvk_physical_device *device =
vk_zalloc(&instance->vk.alloc, sizeof(*device), 8,
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (!device)
return vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
VkResult result = panvk_physical_device_init(device, instance, drm_device);
if (result != VK_SUCCESS) {
vk_free(&instance->vk.alloc, device);
return result;
}
*out = &device->vk;
return VK_SUCCESS;
}
static void
panvk_destroy_physical_device(struct vk_physical_device *device)
{
panvk_physical_device_finish((struct panvk_physical_device *)device);
vk_free(&device->instance->alloc, device);
}
static void *
panvk_kmod_zalloc(const struct pan_kmod_allocator *allocator, size_t size,
bool transient)
{
const VkAllocationCallbacks *vkalloc = allocator->priv;
return vk_zalloc(vkalloc, size, 8,
transient ? VK_SYSTEM_ALLOCATION_SCOPE_COMMAND
: VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
}
static void
panvk_kmod_free(const struct pan_kmod_allocator *allocator, void *data)
{
const VkAllocationCallbacks *vkalloc = allocator->priv;
return vk_free(vkalloc, data);
}
VKAPI_ATTR VkResult VKAPI_CALL
panvk_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkInstance *pInstance)
{
struct panvk_instance *instance;
VkResult result;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
pAllocator = pAllocator ?: vk_default_allocator();
instance = vk_zalloc(pAllocator, sizeof(*instance), 8,
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (!instance)
return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
struct vk_instance_dispatch_table dispatch_table;
vk_instance_dispatch_table_from_entrypoints(
&dispatch_table, &panvk_instance_entrypoints, true);
vk_instance_dispatch_table_from_entrypoints(
&dispatch_table, &wsi_instance_entrypoints, false);
result = vk_instance_init(&instance->vk, &panvk_instance_extensions,
&dispatch_table, pCreateInfo, pAllocator);
if (result != VK_SUCCESS) {
vk_free(pAllocator, instance);
return vk_error(NULL, result);
}
instance->kmod.allocator = (struct pan_kmod_allocator){
.zalloc = panvk_kmod_zalloc,
.free = panvk_kmod_free,
.priv = &instance->vk.alloc,
};
instance->vk.physical_devices.try_create_for_drm =
panvk_physical_device_try_create;
instance->vk.physical_devices.destroy = panvk_destroy_physical_device;
instance->debug_flags =
parse_debug_string(getenv("PANVK_DEBUG"), panvk_debug_options);
if (instance->debug_flags & PANVK_DEBUG_STARTUP)
vk_logi(VK_LOG_NO_OBJS(instance), "Created an instance");
VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
*pInstance = panvk_instance_to_handle(instance);
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL
panvk_DestroyInstance(VkInstance _instance,
const VkAllocationCallbacks *pAllocator)
{
VK_FROM_HANDLE(panvk_instance, instance, _instance);
if (!instance)
return;
vk_instance_finish(&instance->vk);
vk_free(&instance->vk.alloc, instance);
}
VKAPI_ATTR VkResult VKAPI_CALL
panvk_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount,
VkLayerProperties *pProperties)
{
*pPropertyCount = 0;
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL
panvk_EnumerateInstanceExtensionProperties(const char *pLayerName,
uint32_t *pPropertyCount,
VkExtensionProperties *pProperties)
{
if (pLayerName)
return vk_error(NULL, VK_ERROR_LAYER_NOT_PRESENT);
return vk_enumerate_instance_extension_properties(
&panvk_instance_extensions, pPropertyCount, pProperties);
}
PFN_vkVoidFunction
panvk_GetInstanceProcAddr(VkInstance _instance, const char *pName)
{
VK_FROM_HANDLE(panvk_instance, instance, _instance);
return vk_instance_get_proc_addr(&instance->vk, &panvk_instance_entrypoints,
pName);
}
/* The loader wants us to expose a second GetInstanceProcAddr function
* to work around certain LD_PRELOAD issues seen in apps.
*/
PUBLIC
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(VkInstance instance, const char *pName)
{
return panvk_GetInstanceProcAddr(instance, pName);
}

View file

@ -0,0 +1,47 @@
/*
* Copyright © 2021 Collabora Ltd.
* SPDX-License-Identifier: MIT
*/
#ifndef PANVK_INSTANCE_H
#define PANVK_INSTANCE_H
#include <stdint.h>
#include "vk_instance.h"
#include "lib/kmod/pan_kmod.h"
enum panvk_debug_flags {
PANVK_DEBUG_STARTUP = 1 << 0,
PANVK_DEBUG_NIR = 1 << 1,
PANVK_DEBUG_TRACE = 1 << 2,
PANVK_DEBUG_SYNC = 1 << 3,
PANVK_DEBUG_AFBC = 1 << 4,
PANVK_DEBUG_LINEAR = 1 << 5,
PANVK_DEBUG_DUMP = 1 << 6,
PANVK_DEBUG_NO_KNOWN_WARN = 1 << 7,
};
struct panvk_instance {
struct vk_instance vk;
uint32_t api_version;
enum panvk_debug_flags debug_flags;
struct {
struct pan_kmod_allocator allocator;
} kmod;
};
VK_DEFINE_HANDLE_CASTS(panvk_instance, vk.base, VkInstance,
VK_OBJECT_TYPE_INSTANCE)
static inline struct panvk_instance *
to_panvk_instance(struct vk_instance *instance)
{
return container_of(instance, struct panvk_instance, vk);
}
#endif

View file

@ -69,6 +69,7 @@
#include "pan_texture.h"
#include "panvk_descriptor_set.h"
#include "panvk_descriptor_set_layout.h"
#include "panvk_instance.h"
#include "panvk_macros.h"
#include "panvk_mempool.h"
#include "panvk_pipeline.h"
@ -219,44 +220,19 @@ to_panvk_physical_device(struct vk_physical_device *phys_dev)
return container_of(phys_dev, struct panvk_physical_device, vk);
}
enum panvk_debug_flags {
PANVK_DEBUG_STARTUP = 1 << 0,
PANVK_DEBUG_NIR = 1 << 1,
PANVK_DEBUG_TRACE = 1 << 2,
PANVK_DEBUG_SYNC = 1 << 3,
PANVK_DEBUG_AFBC = 1 << 4,
PANVK_DEBUG_LINEAR = 1 << 5,
PANVK_DEBUG_DUMP = 1 << 6,
PANVK_DEBUG_NO_KNOWN_WARN = 1 << 7,
};
struct panvk_instance {
struct vk_instance vk;
uint32_t api_version;
enum panvk_debug_flags debug_flags;
struct {
struct pan_kmod_allocator allocator;
} kmod;
};
static inline struct panvk_instance *
to_panvk_instance(struct vk_instance *instance)
{
return container_of(instance, struct panvk_instance, vk);
}
VkResult panvk_wsi_init(struct panvk_physical_device *physical_device);
void panvk_wsi_finish(struct panvk_physical_device *physical_device);
bool panvk_instance_extension_supported(const char *name);
uint32_t panvk_physical_device_api_version(struct panvk_physical_device *dev);
bool
panvk_physical_device_extension_supported(struct panvk_physical_device *dev,
const char *name);
void panvk_physical_device_finish(struct panvk_physical_device *device);
VkResult panvk_physical_device_init(struct panvk_physical_device *device,
struct panvk_instance *instance,
drmDevicePtr drm_device);
#define PANVK_MAX_QUEUE_FAMILIES 1
struct panvk_device {
@ -470,8 +446,6 @@ void panvk_cmd_preload_fb_after_batch_split(struct panvk_cmd_buffer *cmdbuf);
VK_DEFINE_HANDLE_CASTS(panvk_cmd_buffer, vk.base, VkCommandBuffer,
VK_OBJECT_TYPE_COMMAND_BUFFER)
VK_DEFINE_HANDLE_CASTS(panvk_device, vk.base, VkDevice, VK_OBJECT_TYPE_DEVICE)
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)

View file

@ -33,6 +33,7 @@
#include "panvk_event.h"
#include "panvk_image.h"
#include "panvk_image_view.h"
#include "panvk_instance.h"
#include "panvk_pipeline.h"
#include "panvk_pipeline_layout.h"
#include "panvk_private.h"

View file

@ -12,6 +12,7 @@
#include "vk_cmd_enqueue_entrypoints.h"
#include "vk_common_entrypoints.h"
#include "panvk_instance.h"
#include "panvk_macros.h"
#include "panvk_private.h"
#include "panvk_queue.h"

View file

@ -16,6 +16,7 @@
#include "panvk_event.h"
#include "panvk_image.h"
#include "panvk_image_view.h"
#include "panvk_instance.h"
#include "panvk_private.h"
#include "panvk_queue.h"

View file

@ -29,6 +29,7 @@
#include "genxml/gen_macros.h"
#include "panvk_instance.h"
#include "panvk_pipeline_layout.h"
#include "panvk_private.h"
#include "panvk_shader.h"

View file

@ -25,6 +25,7 @@
* DEALINGS IN THE SOFTWARE.
*/
#include "panvk_instance.h"
#include "panvk_private.h"
#include "vk_util.h"