Commit bafd0c68 authored by Jason Ekstrand's avatar Jason Ekstrand Committed by Marge Bot
Browse files

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's avatarBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Reviewed-by: Lionel Landwerlin's avatarLionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <!8676>
parent 3a7514ea
......@@ -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;
......
......@@ -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);
......
......@@ -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,
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
}
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 (idx >= VK_DEVICE_EXTENSION_COUNT)
return VK_ERROR_EXTENSION_NOT_PRESENT;
if (!physical_device->supported_extensions.extensions[idx])
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;
}
device->enabled_extensions.extensions[idx] = true;
}
p_atomic_set(&device->private_data_next_index, 0);
......
......@@ -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);
......
......@@ -57,33 +57,29 @@ 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 (dispatch_table != NULL) {
instance->dispatch_table = *dispatch_table;
if (idx >= VK_INSTANCE_EXTENSION_COUNT)
return VK_ERROR_EXTENSION_NOT_PRESENT;
if (!supported_extensions->extensions[idx])
return VK_ERROR_EXTENSION_NOT_PRESENT;
/* Add common entrypoints without overwriting driver-provided ones. */
vk_instance_dispatch_table_from_entrypoints(
&instance->dispatch_table, &vk_common_instance_entrypoints, false);
instance->enabled_extensions.extensions[idx] = true;
}
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);
if (mtx_init(&instance->debug_report.callbacks_mutex, mtx_plain) != 0)
return VK_ERROR_INITIALIZATION_FAILED;
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment