From 7d16621281688814146f0f5a116ebb462d00cc60 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 25 Jan 2021 10:35:32 +1000 Subject: [PATCH] radv: move to subclassed instance/physical_device structs This moves to using the common base structs for these two objects, this is prep work for the using the common dispatch layer code. Reviewed-by: Jason Ekstrand Reviewed-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/amd/vulkan/radv_debug.c | 14 ++--- src/amd/vulkan/radv_device.c | 89 ++++++++++++++----------------- src/amd/vulkan/radv_private.h | 13 ++--- src/amd/vulkan/radv_wsi.c | 6 +-- src/amd/vulkan/radv_wsi_display.c | 2 +- src/amd/vulkan/radv_wsi_wayland.c | 2 +- src/amd/vulkan/radv_wsi_x11.c | 4 +- 7 files changed, 58 insertions(+), 72 deletions(-) diff --git a/src/amd/vulkan/radv_debug.c b/src/amd/vulkan/radv_debug.c index 0d94ddd77e2..6975159640b 100644 --- a/src/amd/vulkan/radv_debug.c +++ b/src/amd/vulkan/radv_debug.c @@ -567,14 +567,14 @@ radv_dump_app_info(struct radv_device *device, FILE *f) { struct radv_instance *instance = device->instance; - fprintf(f, "Application name: %s\n", instance->applicationName); - fprintf(f, "Application version: %d\n", instance->applicationVersion); - fprintf(f, "Engine name: %s\n", instance->engineName); - fprintf(f, "Engine version: %d\n", instance->engineVersion); + fprintf(f, "Application name: %s\n", instance->vk.app_info.app_name); + fprintf(f, "Application version: %d\n", instance->vk.app_info.app_version); + fprintf(f, "Engine name: %s\n", instance->vk.app_info.engine_name); + fprintf(f, "Engine version: %d\n", instance->vk.app_info.engine_version); fprintf(f, "API version: %d.%d.%d\n", - VK_VERSION_MAJOR(instance->apiVersion), - VK_VERSION_MINOR(instance->apiVersion), - VK_VERSION_PATCH(instance->apiVersion)); + VK_VERSION_MAJOR(instance->vk.app_info.api_version), + VK_VERSION_MINOR(instance->vk.app_info.api_version), + VK_VERSION_PATCH(instance->vk.app_info.api_version)); radv_dump_enabled_options(device, f); } diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index b8436f54fd8..df38aeff197 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -340,14 +340,19 @@ radv_physical_device_try_create(struct radv_instance *instance, #endif struct radv_physical_device *device = - vk_zalloc2(&instance->alloc, NULL, sizeof(*device), 8, + vk_zalloc2(&instance->vk.alloc, NULL, sizeof(*device), 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (!device) { result = vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY); goto fail_fd; } - device->_loader_data.loaderMagic = ICD_LOADER_MAGIC; + result = vk_physical_device_init(&device->vk, &instance->vk, NULL, + NULL); + if (result != VK_SUCCESS) { + goto fail_alloc; + } + device->instance = instance; #ifdef _WIN32 @@ -364,7 +369,7 @@ radv_physical_device_try_create(struct radv_instance *instance, if (!device->ws) { result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED, "failed to initialize winsys"); - goto fail_alloc; + goto fail_base; } #ifndef _WIN32 @@ -481,8 +486,10 @@ fail_disk_cache: disk_cache_destroy(device->disk_cache); fail_wsi: device->ws->destroy(device->ws); +fail_base: + vk_physical_device_finish(&device->vk); fail_alloc: - vk_free(&instance->alloc, device); + vk_free(&instance->vk.alloc, device); fail_fd: if (fd != -1) close(fd); @@ -501,7 +508,8 @@ radv_physical_device_destroy(struct radv_physical_device *device) close(device->local_fd); if (device->master_fd != -1) close(device->master_fd); - vk_free(&device->instance->alloc, device); + vk_physical_device_finish(&device->vk); + vk_free(&device->instance->vk.alloc, device); } static void * @@ -679,10 +687,10 @@ static void radv_init_dri_options(struct radv_instance *instance) driParseConfigFiles(&instance->dri_options, &instance->available_dri_options, 0, "radv", NULL, - instance->applicationName, - instance->applicationVersion, - instance->engineName, - instance->engineVersion); + instance->vk.app_info.app_name, + instance->vk.app_info.app_version, + instance->vk.app_info.engine_name, + instance->vk.app_info.engine_version); } VkResult radv_CreateInstance( @@ -693,36 +701,22 @@ VkResult radv_CreateInstance( struct radv_instance *instance; VkResult result; - instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8, - VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + if (!pAllocator) + pAllocator = &default_alloc; + + instance = vk_zalloc(pAllocator, sizeof(*instance), 8, + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (!instance) return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY); - vk_object_base_init(NULL, &instance->base, VK_OBJECT_TYPE_INSTANCE); - - if (pAllocator) - instance->alloc = *pAllocator; - else - instance->alloc = default_alloc; - - if (pCreateInfo->pApplicationInfo) { - const VkApplicationInfo *app = pCreateInfo->pApplicationInfo; - - instance->applicationName = - vk_strdup(&instance->alloc, app->pApplicationName, - VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - instance->applicationVersion = app->applicationVersion; - - instance->engineName = - vk_strdup(&instance->alloc, app->pEngineName, - VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - instance->engineVersion = app->engineVersion; - instance->apiVersion = app->apiVersion; + result = vk_instance_init(&instance->vk, + NULL, NULL, + pCreateInfo, pAllocator); + if (result != VK_SUCCESS) { + vk_free(pAllocator, instance); + return vk_error(instance, result); } - if (instance->apiVersion == 0) - instance->apiVersion = VK_API_VERSION_1_0; - instance->debug_flags = parse_debug_string(getenv("RADV_DEBUG"), radv_debug_options); @@ -760,7 +754,7 @@ VkResult radv_CreateInstance( if (idx >= RADV_INSTANCE_EXTENSION_COUNT || !radv_instance_extensions_supported.extensions[idx]) { - vk_object_base_finish(&instance->base); + vk_instance_finish(&instance->vk); vk_free2(&default_alloc, pAllocator, instance); return vk_error(instance, VK_ERROR_EXTENSION_NOT_PRESENT); } @@ -772,7 +766,7 @@ VkResult radv_CreateInstance( /* Vulkan requires that entrypoints for extensions which have * not been enabled must not be advertised. */ - if (!radv_instance_entrypoint_is_enabled(i, instance->apiVersion, + if (!radv_instance_entrypoint_is_enabled(i, instance->vk.app_info.api_version, &instance->enabled_extensions)) { instance->dispatch.entrypoints[i] = NULL; } else { @@ -785,7 +779,7 @@ VkResult radv_CreateInstance( /* Vulkan requires that entrypoints for extensions which have * not been enabled must not be advertised. */ - if (!radv_physical_device_entrypoint_is_enabled(i, instance->apiVersion, + if (!radv_physical_device_entrypoint_is_enabled(i, instance->vk.app_info.api_version, &instance->enabled_extensions)) { instance->physical_device_dispatch.entrypoints[i] = NULL; } else { @@ -798,7 +792,7 @@ VkResult radv_CreateInstance( /* Vulkan requires that entrypoints for extensions which have * not been enabled must not be advertised. */ - if (!radv_device_entrypoint_is_enabled(i, instance->apiVersion, + if (!radv_device_entrypoint_is_enabled(i, instance->vk.app_info.api_version, &instance->enabled_extensions, NULL)) { instance->device_dispatch.entrypoints[i] = NULL; } else { @@ -812,7 +806,7 @@ VkResult radv_CreateInstance( result = vk_debug_report_instance_init(&instance->debug_report_callbacks); if (result != VK_SUCCESS) { - vk_object_base_finish(&instance->base); + vk_instance_finish(&instance->vk); vk_free2(&default_alloc, pAllocator, instance); return vk_error(instance, result); } @@ -843,9 +837,6 @@ void radv_DestroyInstance( radv_physical_device_destroy(pdevice); } - vk_free(&instance->alloc, instance->engineName); - vk_free(&instance->alloc, instance->applicationName); - VG(VALGRIND_DESTROY_MEMPOOL(instance)); glsl_type_singleton_decref(); @@ -855,8 +846,8 @@ void radv_DestroyInstance( vk_debug_report_instance_destroy(&instance->debug_report_callbacks); - vk_object_base_finish(&instance->base); - vk_free(&instance->alloc, instance); + vk_instance_finish(&instance->vk); + vk_free(&instance->vk.alloc, instance); } static VkResult @@ -2635,7 +2626,7 @@ radv_device_init_dispatch(struct radv_device *device) /* Vulkan requires that entrypoints for extensions which have not been * enabled must not be advertised. */ - if (!radv_device_entrypoint_is_enabled(i, instance->apiVersion, + if (!radv_device_entrypoint_is_enabled(i, instance->vk.app_info.api_version, &instance->enabled_extensions, &device->enabled_extensions)) { device->dispatch.entrypoints[i] = NULL; @@ -2790,14 +2781,14 @@ VkResult radv_CreateDevice( } } - device = vk_zalloc2(&physical_device->instance->alloc, pAllocator, + device = vk_zalloc2(&physical_device->instance->vk.alloc, pAllocator, sizeof(*device), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); if (!device) return vk_error(physical_device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); result = vk_device_init(&device->vk, NULL, NULL, pCreateInfo, - &physical_device->instance->alloc, pAllocator); + &physical_device->instance->vk.alloc, pAllocator); if (result != VK_SUCCESS) { vk_free(&device->vk.alloc, device); return result; @@ -8111,7 +8102,7 @@ radv_CreateDebugReportCallbackEXT(VkInstance _instance, { RADV_FROM_HANDLE(radv_instance, instance, _instance); return vk_create_debug_report_callback(&instance->debug_report_callbacks, - pCreateInfo, pAllocator, &instance->alloc, + pCreateInfo, pAllocator, &instance->vk.alloc, pCallback); } @@ -8122,7 +8113,7 @@ radv_DestroyDebugReportCallbackEXT(VkInstance _instance, { RADV_FROM_HANDLE(radv_instance, instance, _instance); vk_destroy_debug_report_callback(&instance->debug_report_callbacks, - _callback, pAllocator, &instance->alloc); + _callback, pAllocator, &instance->vk.alloc); } void diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 99840ef9701..c29780ad110 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -56,7 +56,9 @@ #include "vk_alloc.h" #include "vk_debug_report.h" #include "vk_device.h" +#include "vk_instance.h" #include "vk_format.h" +#include "vk_physical_device.h" #include "radv_radeon_winsys.h" #include "ac_binary.h" @@ -271,7 +273,7 @@ bool radv_device_entrypoint_is_enabled(int index, uint32_t core_version, void *radv_lookup_entrypoint(const char *name); struct radv_physical_device { - VK_LOADER_DATA _loader_data; + struct vk_physical_device vk; /* Link in radv_instance::physical_devices */ struct list_head link; @@ -326,17 +328,10 @@ struct radv_physical_device { }; struct radv_instance { - struct vk_object_base base; + struct vk_instance vk; VkAllocationCallbacks alloc; - uint32_t apiVersion; - - char * applicationName; - uint32_t applicationVersion; - char * engineName; - uint32_t engineVersion; - uint64_t debug_flags; uint64_t perftest_flags; diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c index 3154c9d9305..39714dea5ba 100644 --- a/src/amd/vulkan/radv_wsi.c +++ b/src/amd/vulkan/radv_wsi.c @@ -55,7 +55,7 @@ radv_init_wsi(struct radv_physical_device *physical_device) VkResult result = wsi_device_init(&physical_device->wsi_device, radv_physical_device_to_handle(physical_device), radv_wsi_proc_addr, - &physical_device->instance->alloc, + &physical_device->instance->vk.alloc, physical_device->master_fd, &physical_device->instance->dri_options, false); @@ -70,7 +70,7 @@ void radv_finish_wsi(struct radv_physical_device *physical_device) { wsi_device_finish(&physical_device->wsi_device, - &physical_device->instance->alloc); + &physical_device->instance->vk.alloc); } void radv_DestroySurfaceKHR( @@ -81,7 +81,7 @@ void radv_DestroySurfaceKHR( RADV_FROM_HANDLE(radv_instance, instance, _instance); ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface); - vk_free2(&instance->alloc, pAllocator, surface); + vk_free2(&instance->vk.alloc, pAllocator, surface); } VkResult radv_GetPhysicalDeviceSurfaceSupportKHR( diff --git a/src/amd/vulkan/radv_wsi_display.c b/src/amd/vulkan/radv_wsi_display.c index 868298df7be..64c7acd3734 100644 --- a/src/amd/vulkan/radv_wsi_display.c +++ b/src/amd/vulkan/radv_wsi_display.c @@ -204,7 +204,7 @@ radv_CreateDisplayPlaneSurfaceKHR( if (allocator) alloc = allocator; else - alloc = &instance->alloc; + alloc = &instance->vk.alloc; return wsi_create_display_surface(_instance, alloc, create_info, surface); diff --git a/src/amd/vulkan/radv_wsi_wayland.c b/src/amd/vulkan/radv_wsi_wayland.c index d9a4c72d67a..dba5a0610a0 100644 --- a/src/amd/vulkan/radv_wsi_wayland.c +++ b/src/amd/vulkan/radv_wsi_wayland.c @@ -49,7 +49,7 @@ VkResult radv_CreateWaylandSurfaceKHR( if (pAllocator) alloc = pAllocator; else - alloc = &instance->alloc; + alloc = &instance->vk.alloc; return wsi_create_wl_surface(alloc, pCreateInfo, pSurface); } diff --git a/src/amd/vulkan/radv_wsi_x11.c b/src/amd/vulkan/radv_wsi_x11.c index acad74d3cf2..8dee70555c1 100644 --- a/src/amd/vulkan/radv_wsi_x11.c +++ b/src/amd/vulkan/radv_wsi_x11.c @@ -75,7 +75,7 @@ VkResult radv_CreateXcbSurfaceKHR( if (pAllocator) alloc = pAllocator; else - alloc = &instance->alloc; + alloc = &instance->vk.alloc; return wsi_create_xcb_surface(alloc, pCreateInfo, pSurface); } @@ -94,7 +94,7 @@ VkResult radv_CreateXlibSurfaceKHR( if (pAllocator) alloc = pAllocator; else - alloc = &instance->alloc; + alloc = &instance->vk.alloc; return wsi_create_xlib_surface(alloc, pCreateInfo, pSurface); }