vulkan: Rework vk_device_init and friends

Now that all drivers are converted over, we can make a few changes.
First off, vk_device_init no longer takes two separate allocators
because we can assume that the parent instance is non-null and it can
pull the instance allocator from that.  Second, dispatch tables and the
instance extension table are no longer optional.  We leave the device
extension table optional for now because we don't do any verification at
vk_init_physical_device time and some drivers find it more convenient to
set the extensions later in their own physical_device_init for various
reasons.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8676>
This commit is contained in:
Jason Ekstrand 2021-01-29 12:30:34 -06:00 committed by Marge Bot
parent 3a7514ea09
commit bafd0c680d
9 changed files with 50 additions and 67 deletions

View file

@ -2701,8 +2701,8 @@ VkResult radv_CreateDevice(
&radv_device_entrypoints, true);
}
result = vk_device_init(&device->vk, &physical_device->vk, &dispatch_table, pCreateInfo,
&physical_device->instance->vk.alloc, pAllocator);
result = vk_device_init(&device->vk, &physical_device->vk,
&dispatch_table, pCreateInfo, pAllocator);
if (result != VK_SUCCESS) {
vk_free(&device->vk.alloc, device);
return result;

View file

@ -1394,8 +1394,7 @@ v3dv_CreateDevice(VkPhysicalDevice physicalDevice,
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
&v3dv_device_entrypoints, true);
result = vk_device_init(&device->vk, &physical_device->vk,
&dispatch_table, pCreateInfo,
&physical_device->vk.instance->alloc, pAllocator);
&dispatch_table, pCreateInfo, pAllocator);
if (result != VK_SUCCESS) {
vk_free(&device->vk.alloc, device);
return vk_error(instance, result);

View file

@ -1018,9 +1018,7 @@ tu_CreateDevice(VkPhysicalDevice physicalDevice,
&dispatch_table, &tu_device_entrypoints, true);
result = vk_device_init(&device->vk, &physical_device->vk,
&dispatch_table, pCreateInfo,
&physical_device->instance->vk.alloc,
pAllocator);
&dispatch_table, pCreateInfo, pAllocator);
if (result != VK_SUCCESS) {
vk_free(&device->vk.alloc, device);
return vk_startup_errorf(physical_device->instance, result,

View file

@ -810,7 +810,6 @@ VkResult lvp_CreateDevice(
VkResult result = vk_device_init(&device->vk,
&physical_device->vk,
&dispatch_table, pCreateInfo,
&physical_device->vk.instance->alloc,
pAllocator);
if (result != VK_SUCCESS) {
vk_free(&device->vk.alloc, device);

View file

@ -2660,8 +2660,7 @@ VkResult anv_CreateDevice(
&anv_device_entrypoints, false);
result = vk_device_init(&device->vk, &physical_device->vk,
&dispatch_table, pCreateInfo,
&physical_device->instance->vk.alloc, pAllocator);
&dispatch_table, pCreateInfo, pAllocator);
if (result != VK_SUCCESS) {
vk_error(result);
goto fail_alloc;

View file

@ -34,43 +34,38 @@ vk_device_init(struct vk_device *device,
struct vk_physical_device *physical_device,
const struct vk_device_dispatch_table *dispatch_table,
const VkDeviceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *instance_alloc,
const VkAllocationCallbacks *device_alloc)
const VkAllocationCallbacks *alloc)
{
memset(device, 0, sizeof(*device));
vk_object_base_init(device, &device->base, VK_OBJECT_TYPE_DEVICE);
if (device_alloc)
device->alloc = *device_alloc;
if (alloc != NULL)
device->alloc = *alloc;
else
device->alloc = *instance_alloc;
device->alloc = physical_device->instance->alloc;
device->physical = physical_device;
if (dispatch_table != NULL) {
device->dispatch_table = *dispatch_table;
device->dispatch_table = *dispatch_table;
/* Add common entrypoints without overwriting driver-provided ones. */
vk_device_dispatch_table_from_entrypoints(
&device->dispatch_table, &vk_common_device_entrypoints, false);
}
/* Add common entrypoints without overwriting driver-provided ones. */
vk_device_dispatch_table_from_entrypoints(
&device->dispatch_table, &vk_common_device_entrypoints, false);
if (physical_device != NULL) {
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
int idx;
for (idx = 0; idx < VK_DEVICE_EXTENSION_COUNT; idx++) {
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
vk_device_extensions[idx].extensionName) == 0)
break;
}
if (idx >= VK_DEVICE_EXTENSION_COUNT)
return VK_ERROR_EXTENSION_NOT_PRESENT;
if (!physical_device->supported_extensions.extensions[idx])
return VK_ERROR_EXTENSION_NOT_PRESENT;
device->enabled_extensions.extensions[idx] = true;
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
int idx;
for (idx = 0; idx < VK_DEVICE_EXTENSION_COUNT; idx++) {
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
vk_device_extensions[idx].extensionName) == 0)
break;
}
if (idx >= VK_DEVICE_EXTENSION_COUNT)
return VK_ERROR_EXTENSION_NOT_PRESENT;
if (!physical_device->supported_extensions.extensions[idx])
return VK_ERROR_EXTENSION_NOT_PRESENT;
device->enabled_extensions.extensions[idx] = true;
}
p_atomic_set(&device->private_data_next_index, 0);

View file

@ -57,8 +57,7 @@ vk_device_init(struct vk_device *device,
struct vk_physical_device *physical_device,
const struct vk_device_dispatch_table *dispatch_table,
const VkDeviceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *instance_alloc,
const VkAllocationCallbacks *device_alloc);
const VkAllocationCallbacks *alloc);
void
vk_device_finish(struct vk_device *device);

View file

@ -57,32 +57,28 @@ vk_instance_init(struct vk_instance *instance,
if (instance->app_info.api_version == 0)
instance->app_info.api_version = VK_API_VERSION_1_0;
if (supported_extensions != NULL) {
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
int idx;
for (idx = 0; idx < VK_INSTANCE_EXTENSION_COUNT; idx++) {
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
vk_instance_extensions[idx].extensionName) == 0)
break;
}
if (idx >= VK_INSTANCE_EXTENSION_COUNT)
return VK_ERROR_EXTENSION_NOT_PRESENT;
if (!supported_extensions->extensions[idx])
return VK_ERROR_EXTENSION_NOT_PRESENT;
instance->enabled_extensions.extensions[idx] = true;
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
int idx;
for (idx = 0; idx < VK_INSTANCE_EXTENSION_COUNT; idx++) {
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
vk_instance_extensions[idx].extensionName) == 0)
break;
}
if (idx >= VK_INSTANCE_EXTENSION_COUNT)
return VK_ERROR_EXTENSION_NOT_PRESENT;
if (!supported_extensions->extensions[idx])
return VK_ERROR_EXTENSION_NOT_PRESENT;
instance->enabled_extensions.extensions[idx] = true;
}
if (dispatch_table != NULL) {
instance->dispatch_table = *dispatch_table;
instance->dispatch_table = *dispatch_table;
/* Add common entrypoints without overwriting driver-provided ones. */
vk_instance_dispatch_table_from_entrypoints(
&instance->dispatch_table, &vk_common_instance_entrypoints, false);
}
/* Add common entrypoints without overwriting driver-provided ones. */
vk_instance_dispatch_table_from_entrypoints(
&instance->dispatch_table, &vk_common_instance_entrypoints, false);
if (mtx_init(&instance->debug_report.callbacks_mutex, mtx_plain) != 0)
return VK_ERROR_INITIALIZATION_FAILED;

View file

@ -39,13 +39,11 @@ vk_physical_device_init(struct vk_physical_device *pdevice,
if (supported_extensions != NULL)
pdevice->supported_extensions = *supported_extensions;
if (dispatch_table != NULL) {
pdevice->dispatch_table = *dispatch_table;
pdevice->dispatch_table = *dispatch_table;
/* Add common entrypoints without overwriting driver-provided ones. */
vk_physical_device_dispatch_table_from_entrypoints(
&pdevice->dispatch_table, &vk_common_physical_device_entrypoints, false);
}
/* Add common entrypoints without overwriting driver-provided ones. */
vk_physical_device_dispatch_table_from_entrypoints(
&pdevice->dispatch_table, &vk_common_physical_device_entrypoints, false);
return VK_SUCCESS;
}