Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions loader/generated/vk_loader_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,7 @@ VKAPI_ATTR void VKAPI_CALL loader_init_instance_extension_dispatch_table(VkLayer
// device function. This is used in the terminators themselves.
void init_extension_device_proc_terminator_dispatch(struct loader_device *dev) {
struct loader_device_terminator_dispatch* dispatch = &dev->loader_dispatch.extension_terminator_dispatch;
PFN_vkGetDeviceProcAddr gpda = (PFN_vkGetDeviceProcAddr)dev->phys_dev_term->this_icd_term->dispatch.GetDeviceProcAddr;
PFN_vkGetDeviceProcAddr gpda = (PFN_vkGetDeviceProcAddr)dev->icd_term->dispatch.GetDeviceProcAddr;

// ---- VK_KHR_swapchain extension commands
if (dev->driver_extensions.khr_swapchain_enabled)
Expand Down Expand Up @@ -1871,7 +1871,7 @@ VKAPI_ATTR void* VKAPI_CALL loader_lookup_device_dispatch_table(const VkLayerDis
name += 2;
*found_name = true;
struct loader_device* dev = (struct loader_device *)table;
const struct loader_instance* inst = dev->phys_dev_term->this_icd_term->this_instance;
const struct loader_instance* inst = dev->icd_term->this_instance;
uint32_t api_version = VK_MAKE_API_VERSION(0, inst->app_api_version.major, inst->app_api_version.minor, inst->app_api_version.patch);
const uint32_t name_hash = loader_hash_string(name);

Expand Down
2 changes: 1 addition & 1 deletion loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -5657,7 +5657,7 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice(VkPhysicalDevice physical
abort();
}

dev->phys_dev_term = phys_dev_term;
dev->icd_term = icd_term;

icd_exts.list = NULL;

Expand Down
3 changes: 2 additions & 1 deletion loader/loader_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ struct loader_device {
struct loader_dev_dispatch_table loader_dispatch;
VkDevice chain_device; // device object from the dispatch chain
VkDevice icd_device; // device object from the icd
struct loader_physical_device_term* phys_dev_term;
// Driver that owns this device. Not the physical device, which is freed if it drops out of a later enumeration.
struct loader_icd_term* icd_term;

VkAllocationCallbacks alloc_callbacks;

Expand Down
2 changes: 1 addition & 1 deletion loader/wsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice devic
const VkLayerDispatchTable* disp = loader_validate_and_get_device_dispatch(device, __FUNCTION__);
if (NULL == disp->CreateSwapchainKHR) {
struct loader_device* dev = *((struct loader_device**)device);
loader_log(NULL != dev ? dev->phys_dev_term->this_icd_term->this_instance : NULL,
loader_log(NULL != dev ? dev->icd_term->this_instance : NULL,
VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
"vkCreateSwapchainKHR: Driver's function pointer was NULL, returning VK_SUCCESS. Was the VK_KHR_swapchain "
"extension enabled?");
Expand Down
4 changes: 2 additions & 2 deletions scripts/generators/loader_extension_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def InitDeviceFunctionTerminatorDispatchTable(self, out):
out.append('// device function. This is used in the terminators themselves.\n')
out.append('void init_extension_device_proc_terminator_dispatch(struct loader_device *dev) {\n')
out.append(' struct loader_device_terminator_dispatch* dispatch = &dev->loader_dispatch.extension_terminator_dispatch;\n')
out.append(' PFN_vkGetDeviceProcAddr gpda = (PFN_vkGetDeviceProcAddr)dev->phys_dev_term->this_icd_term->dispatch.GetDeviceProcAddr;\n')
out.append(' PFN_vkGetDeviceProcAddr gpda = (PFN_vkGetDeviceProcAddr)dev->icd_term->dispatch.GetDeviceProcAddr;\n')
current_block = ''
for command in [x for x in self.vk.commands.values() if x.extensions or x.version]:
if command.name in DEVICE_CMDS_NEED_TERM:
Expand Down Expand Up @@ -637,7 +637,7 @@ def OutputLoaderLookupFunc(self, out):
out.append(' name += 2;\n')
out.append(' *found_name = true;\n')
out.append(' struct loader_device* dev = (struct loader_device *)table;\n')
out.append(' const struct loader_instance* inst = dev->phys_dev_term->this_icd_term->this_instance;\n')
out.append(' const struct loader_instance* inst = dev->icd_term->this_instance;\n')
out.append(' uint32_t api_version = VK_MAKE_API_VERSION(0, inst->app_api_version.major, inst->app_api_version.minor, inst->app_api_version.patch);\n')
out.append(' const uint32_t name_hash = loader_hash_string(name);\n')
out.append('\n')
Expand Down
32 changes: 32 additions & 0 deletions tests/loader_regression_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5803,3 +5803,35 @@ TEST(DriverUnloadingFromZeroPhysDevs, DriverWithLiveDeviceNotUnloaded) {
inst->vkGetDeviceQueue(dev_1, 0, 0, &queue_1);
handle_assert_has_value(queue_1);
}

// A VkDevice must stay usable after its physical device drops out of a later vkEnumeratePhysicalDevices call.
TEST(DriverUnloadingFromZeroPhysDevs, GetDeviceProcAddrAfterPhysicalDeviceRemoved) {
FrameworkEnvironment env{};
add_driver_for_unloading_testing(env);
add_driver_for_unloading_testing(env);

InstWrapper inst{env.vulkan_functions};
inst.CheckCreate();
auto phys_devs = inst.GetPhysDevs(2);

DeviceWrapper dev_0{inst};
dev_0.create_info.add_device_queue(DeviceQueueCreateInfo{}.add_priority(0.0f));
dev_0.CheckCreate(phys_devs[0]);
DeviceWrapper dev_1{inst};
dev_1.create_info.add_device_queue(DeviceQueueCreateInfo{}.add_priority(0.0f));
dev_1.CheckCreate(phys_devs[1]);
PFN_vkVoidFunction create_command_pool_0 = inst->vkGetDeviceProcAddr(dev_0, "vkCreateCommandPool");
ASSERT_NE(nullptr, create_command_pool_0);
PFN_vkVoidFunction create_command_pool_1 = inst->vkGetDeviceProcAddr(dev_1, "vkCreateCommandPool");
ASSERT_NE(nullptr, create_command_pool_1);

// The physical device of one of the devices is no longer enumerated
env.get_test_icd(1).set_enum_physical_devices_return_code(VK_ERROR_INITIALIZATION_FAILED);
uint32_t phys_dev_count = 2;
std::array<VkPhysicalDevice, 2> phys_devs_after{};
ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &phys_dev_count, phys_devs_after.data()));
ASSERT_EQ(phys_dev_count, 1U);

ASSERT_EQ(create_command_pool_0, inst->vkGetDeviceProcAddr(dev_0, "vkCreateCommandPool"));
ASSERT_EQ(create_command_pool_1, inst->vkGetDeviceProcAddr(dev_1, "vkCreateCommandPool"));
}
Loading