Skip to content

Commit 4b9fa87

Browse files
Check handles in PhysicalDeviceFunctionErrorPath
Add an internal function to the test_icd which validates that the passed in physical device is one from the driver.
1 parent fcbdd87 commit 4b9fa87

3 files changed

Lines changed: 27 additions & 20 deletions

File tree

tests/framework/icd/test_icd.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,11 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkGetCalibratedTimestampsEXT(VkDevice device
16241624
return VK_SUCCESS;
16251625
}
16261626

1627+
VKAPI_ATTR VkResult VKAPI_CALL test_icd_internal_function(VkPhysicalDevice physicalDevice, uint32_t a, uint32_t b, float c) {
1628+
check_valid_physical_device(physicalDevice);
1629+
return VK_SUCCESS;
1630+
}
1631+
16271632
#if defined(WIN32)
16281633
VKAPI_ATTR VkResult VKAPI_CALL test_vk_icdEnumerateAdapterPhysicalDevices(VkInstance instance, LUID adapterLUID,
16291634
uint32_t* pPhysicalDeviceCount,
@@ -1955,7 +1960,9 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_physical_device_func(VkInstance ins
19551960
if (string_eq(pName, "vkGetPhysicalDeviceToolPropertiesEXT"))
19561961
return to_vkVoidFunction(test_vkGetPhysicalDeviceToolPropertiesEXT);
19571962
}
1958-
1963+
if (icd.supports_internal_function && string_eq(pName, TEST_ICD_INTERNAL_FUNCTION_NAME_STRING)) {
1964+
return to_vkVoidFunction(test_icd_internal_function);
1965+
}
19591966
for (auto const& [phys_dev_handle, phys_dev] : icd.created_physical_device_details) {
19601967
if (phys_dev.instance_created_from != instance) {
19611968
continue;

tests/framework/icd/test_icd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ inline std::ostream& operator<<(std::ostream& os, const InterfaceVersionCheck& r
8383

8484
using VulkanUUID = std::array<uint8_t, VK_UUID_SIZE>;
8585

86+
using PFN_test_icd_internal_function = VKAPI_ATTR VkResult (VKAPI_CALL *)(VkPhysicalDevice physicalDevice, uint32_t a, uint32_t b, float c);
87+
#define TEST_ICD_INTERNAL_FUNCTION_NAME_STRING "TEST_ICD_INTERNAL_FUNCTION_NAME"
8688
// clang-format on
8789

8890
// Move only type because it holds a DispatchableHandle<VkPhysicalDevice>
@@ -288,6 +290,9 @@ struct TestICD {
288290
// known_device_functions member)
289291
BUILDER_VECTOR(VulkanFunction, custom_instance_functions, custom_instance_function)
290292

293+
// When true, this ICD returns function pointers when TEST_ICD_INTERNAL_FUNCTION_NAME is queried.
294+
BUILDER_VALUE(bool, supports_internal_function)
295+
291296
// Must explicitely state support for the tooling info extension, that way we can control if vkGetInstanceProcAddr returns a
292297
// function pointer for vkGetPhysicalDeviceToolPropertiesEXT or vkGetPhysicalDeviceToolProperties (core version)
293298
BUILDER_VALUE(bool, supports_tooling_info_ext);

tests/loader_unknown_ext_tests.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -390,39 +390,34 @@ TEST(UnknownFunction, PhysicalDeviceFunctionMultipleDriverSupport) {
390390
}
391391
}
392392

393-
// Add unknown functions to driver 0, and try to use them on driver 1.
393+
// Add unknown functions to driver 0, and try to use them on driver 1. Needs TestICD to implement the unknown function so that it
394+
// can validate the passed in VkPhysicalDevice
394395
TEST(UnknownFunctionDeathTests, PhysicalDeviceFunctionErrorPath) {
395396
FrameworkEnvironment env{};
396397
auto& driver_0 = env.add_icd(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA);
397-
auto& driver_1 = env.add_icd(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA);
398-
std::vector<std::string> function_names;
399-
add_function_names(function_names, 1);
398+
auto& driver_1 = env.add_icd(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA).set_supports_internal_function(true);
400399

401400
// used to identify the GPUs
402-
auto& test_physical_driver_0 = driver_0.add_and_get_physical_device("physical_device_0");
403-
test_physical_driver_0.properties.deviceType = VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU;
404-
auto& test_physical_driver_1 = driver_1.add_and_get_physical_device("physical_device_1");
405-
test_physical_driver_1.properties.deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
406-
function_names.push_back(std::string("vkNotIntRealFuncTEST_0"));
407-
408-
custom_physical_device_functions funcs{};
409-
test_physical_driver_0.custom_physical_device_functions.push_back(
410-
VulkanFunction{function_names.back(), to_vkVoidFunction(funcs.func_zero)});
401+
driver_0.add_and_get_physical_device("physical_device_0").properties.deviceType = VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU;
402+
driver_1.add_and_get_physical_device("physical_device_1").properties.deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
411403

412404
InstWrapper inst{env.vulkan_functions};
413405
inst.CheckCreate();
414406

415407
auto phys_devs = inst.GetPhysDevs(2);
416-
VkPhysicalDevice phys_dev_to_use = phys_devs[1];
417408
VkPhysicalDeviceProperties props{};
409+
env.vulkan_functions.vkGetPhysicalDeviceProperties(phys_devs[0], &props);
410+
ASSERT_EQ(props.deviceType, VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU);
411+
418412
env.vulkan_functions.vkGetPhysicalDeviceProperties(phys_devs[1], &props);
419-
if (props.deviceType != VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) phys_dev_to_use = phys_devs[0];
420-
// use the wrong GPU to query the functions, should get 5 errors
413+
ASSERT_EQ(props.deviceType, VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU);
421414

422-
decltype(custom_physical_device_functions::func_zero)* returned_func_i =
423-
env.vulkan_functions.load(inst.inst, function_names.at(0).c_str());
415+
// GPU that supports the unknown function is enumerated first (gpus are enumerated in reverse order)
416+
PFN_test_icd_internal_function returned_func_i = env.vulkan_functions.load(inst.inst, TEST_ICD_INTERNAL_FUNCTION_NAME_STRING);
424417
ASSERT_NE(returned_func_i, nullptr);
425-
ASSERT_DEATH(returned_func_i(phys_dev_to_use, 0), "Function vkNotIntRealFuncTEST_0 not supported for this physical device");
418+
ASSERT_EQ(returned_func_i(phys_devs[0], 0, 1, 2.2f), VK_SUCCESS);
419+
ASSERT_DEATH(returned_func_i(phys_devs[1], 0, 1, 2.2f),
420+
"Function " TEST_ICD_INTERNAL_FUNCTION_NAME_STRING " not supported for this physical device");
426421
}
427422

428423
TEST(UnknownFunction, PhysicalDeviceFunctionWithImplicitLayerImplementation) {

0 commit comments

Comments
 (0)