Skip to content
Merged
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
127 changes: 71 additions & 56 deletions tests/framework/icd/test_icd.cpp

Large diffs are not rendered by default.

39 changes: 38 additions & 1 deletion tests/framework/icd/test_icd.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <array>
#include <filesystem>
#include <ostream>
#include <unordered_map>

#include "util/dispatchable_handle.h"
#include "util/platform_wsi.h"
Expand Down Expand Up @@ -130,6 +131,9 @@ struct PhysicalDevice {

PhysicalDevice&& finish() { return std::move(*this); }

// Defines the order this physical device appears in vkEnumeratePhysicalDevices
uint32_t iteration_order = 0;

// Objects created from this physical device
std::vector<VkDevice> device_handles;
std::vector<DeviceCreateInfo> device_create_infos;
Expand All @@ -149,9 +153,14 @@ struct PhysicalDevice {
struct PhysicalDeviceGroup {
PhysicalDeviceGroup() {}
PhysicalDeviceGroup(PhysicalDevice const& physical_device) { physical_device_handles.push_back(&physical_device); }
PhysicalDeviceGroup(PhysicalDevice const* physical_device) { physical_device_handles.push_back(physical_device); }
PhysicalDeviceGroup(std::vector<PhysicalDevice*> const& physical_devices) {
physical_device_handles.insert(physical_device_handles.end(), physical_devices.begin(), physical_devices.end());
}
PhysicalDeviceGroup& use_physical_device(PhysicalDevice const* physical_device) {
physical_device_handles.push_back(physical_device);
return *this;
}
PhysicalDeviceGroup& use_physical_device(PhysicalDevice const& physical_device) {
physical_device_handles.push_back(&physical_device);
return *this;
Expand Down Expand Up @@ -197,7 +206,31 @@ struct TestICD {
BUILDER_VECTOR(Extension, instance_extensions, instance_extension)
std::vector<Extension> enabled_instance_extensions;

BUILDER_VECTOR_MOVE_ONLY(PhysicalDevice, physical_devices, physical_device);
std::unordered_map<VkPhysicalDevice, PhysicalDevice> physical_devices;
TestICD& add_physical_device(PhysicalDevice&& physical_device) {
physical_device.iteration_order = physical_devices.size();
physical_devices.emplace(physical_device.vk_physical_device.handle, std::move(physical_device));
return *this;
}

PhysicalDevice& add_and_get_physical_device(PhysicalDevice&& physical_device) {
VkPhysicalDevice pd = physical_device.vk_physical_device.handle;
physical_device.iteration_order = physical_devices.size();
physical_devices.emplace(physical_device.vk_physical_device.handle, std::move(physical_device));
return physical_devices.at(pd);
}

PhysicalDevice& add_physical_device_at_index(size_t index, PhysicalDevice&& physical_device) {
VkPhysicalDevice pd = physical_device.vk_physical_device.handle;
physical_device.iteration_order = index;
for (auto& [handle, phys_dev] : physical_devices) {
if (phys_dev.iteration_order >= index) {
phys_dev.iteration_order++;
}
}
physical_devices.emplace(physical_device.vk_physical_device.handle, std::move(physical_device));
return physical_devices.at(pd);
}

BUILDER_VECTOR(PhysicalDeviceGroup, physical_device_groups, physical_device_group);

Expand Down Expand Up @@ -237,6 +270,10 @@ struct TestICD {
return info;
}

// Speedup looking for physical devices by not having to iterate through the entire physical_device map to find a particular
// physical device
std::unordered_map<VkDevice, VkPhysicalDevice> device_to_physical_device_map;

#if defined(WIN32)
BUILDER_VALUE(LUID, adapterLUID)
#endif // defined(WIN32)
Expand Down
9 changes: 4 additions & 5 deletions tests/loader_alloc_callback_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,7 @@ TEST(Allocation, CreateInstanceDeviceIntentionalAllocFail) {
.set_library_arch(sizeof(void*) == 8 ? "64" : "32"))
.set_icd_api_version(VK_API_VERSION_1_1)
.add_instance_extension("VK_KHR_get_physical_device_properties2")
.add_physical_device("physical_device_0")
.physical_devices.at(0)
.add_and_get_physical_device("physical_device_0")
.add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, false})
.add_extensions({"VK_EXT_one", "VK_EXT_two", "VK_EXT_three", "VK_EXT_four", "VK_EXT_five"});
}
Expand Down Expand Up @@ -880,7 +879,7 @@ TEST(Allocation, EnumeratePhysicalDevicesIntentionalAllocFail) {
auto& driver = env.reset_icd();

for (uint32_t i = 0; i < physical_dev_count; i++) {
driver.physical_devices.emplace_back(std::string("physical_device_") + std::to_string(i))
driver.add_and_get_physical_device(std::string("physical_device_") + std::to_string(i))
.add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, false});
}
MemoryTracker tracker{{false, 0, true, fail_index}};
Expand All @@ -902,7 +901,7 @@ TEST(Allocation, EnumeratePhysicalDevicesIntentionalAllocFail) {
ASSERT_EQ(physical_dev_count, returned_physical_count);

for (uint32_t i = 0; i < 2; i++) {
driver.physical_devices.emplace_back(std::string("physical_device_") + std::to_string(physical_dev_count))
driver.add_and_get_physical_device(std::string("physical_device_") + std::to_string(physical_dev_count))
.add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, false});
physical_dev_count += 1;
}
Expand Down Expand Up @@ -976,7 +975,7 @@ TEST(Allocation, CreateInstanceDeviceWithDXGIDriverIntentionalAllocFail) {

for (uint32_t i = 0; i < 2; i++) {
auto& driver = env.get_test_icd(i);
driver.physical_devices.emplace_back(std::string("physical_device_") + std::to_string(i))
driver.add_and_get_physical_device(std::string("physical_device_") + std::to_string(i))
.add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, false});
}

Expand Down
29 changes: 15 additions & 14 deletions tests/loader_debug_ext_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class DebugReportTest : public ::testing::Test {
env = std::unique_ptr<FrameworkEnvironment>(new FrameworkEnvironment());
for (uint32_t icd = 0; icd < 3; ++icd) {
env->add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_0));
env->get_test_icd(icd).physical_devices.push_back({});
env->get_test_icd(icd).physical_devices.push_back({});
env->get_test_icd(icd).add_physical_device({});
env->get_test_icd(icd).add_physical_device({});
}
// Initialize the expected output
allow_any_message = false;
Expand Down Expand Up @@ -387,8 +387,8 @@ class DebugUtilTest : public ::testing::Test {
env = std::unique_ptr<FrameworkEnvironment>(new FrameworkEnvironment());
for (uint32_t icd = 0; icd < 3; ++icd) {
env->add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_0));
env->get_test_icd(icd).physical_devices.push_back({});
env->get_test_icd(icd).physical_devices.push_back({});
env->get_test_icd(icd).add_physical_device({});
env->get_test_icd(icd).add_physical_device({});
}
// Initialize the expected output
allow_any_message = false;
Expand Down Expand Up @@ -1041,9 +1041,8 @@ void CheckDeviceFunctions(FrameworkEnvironment& env, bool use_GIPA, bool enable_

TEST(GetProcAddr, DebugFuncsWithTerminator) {
FrameworkEnvironment env{};
auto& driver =
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).setup_WSI().add_physical_device("physical_device_0");
driver.physical_devices.at(0).add_extensions({"VK_KHR_swapchain"});
auto& driver = env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).setup_WSI();
auto& phys_dev = driver.add_and_get_physical_device("physical_device_0").add_extensions({"VK_KHR_swapchain"});
// Hardware doesn't support the debug extensions

// Use getDeviceProcAddr & vary enabling the debug extensions
Expand All @@ -1056,7 +1055,7 @@ TEST(GetProcAddr, DebugFuncsWithTerminator) {

// Now set the hardware to support the extensions and run the situations again
driver.add_instance_extensions({"VK_EXT_debug_utils", "VK_EXT_debug_report"});
driver.physical_devices.at(0).add_extensions({"VK_EXT_debug_marker"});
phys_dev.add_extensions({"VK_EXT_debug_marker"});

// Use getDeviceProcAddr & vary enabling the debug extensions
ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false, true));
Expand All @@ -1069,9 +1068,10 @@ TEST(GetProcAddr, DebugFuncsWithTerminator) {

TEST(GetProcAddr, DebugFuncsWithTrampoline) {
FrameworkEnvironment env{};
auto& driver =
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).setup_WSI().add_physical_device("physical_device_0");
driver.physical_devices.at(0).add_extensions({"VK_KHR_swapchain"});
auto& driver = env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA))
.setup_WSI()
.add_and_get_physical_device("physical_device_0")
.add_extensions({"VK_KHR_swapchain"});
// Hardware doesn't support the debug extensions

// Use getDeviceProcAddr & vary enabling the debug extensions
Expand Down Expand Up @@ -1103,9 +1103,10 @@ TEST(GetProcAddr, DebugFuncsWithTrampoline) {

TEST(GetProcAddr, DebugFuncsWithDebugExtsForceAdded) {
FrameworkEnvironment env{};
auto& driver =
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).setup_WSI().add_physical_device("physical_device_0");
driver.physical_devices.at(0).add_extensions({"VK_KHR_swapchain"});
auto& driver = env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA))
.setup_WSI()
.add_and_get_physical_device("physical_device_0")
.add_extensions({"VK_KHR_swapchain"});
// Hardware doesn't support the debug extensions

// Use getDeviceProcAddr & vary enabling the debug extensions
Expand Down
4 changes: 2 additions & 2 deletions tests/loader_envvar_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ TEST(EnvVarICDOverrideSetup, XDGContainsJsonFile) {
TEST(EnvVarICDOverrideSetup, TestOnlyAddDriverEnvVar) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::add_env_var));
env.get_test_icd(0).physical_devices.emplace_back("pd0");
env.get_test_icd(0).add_and_get_physical_device("pd0");

InstWrapper inst{env.vulkan_functions};
FillDebugUtilsCreateDetails(inst.create_info, env.debug_log);
Expand All @@ -272,7 +272,7 @@ TEST(EnvVarICDOverrideSetup, TestOnlyAddDriverEnvVar) {
TEST(EnvVarICDOverrideSetup, TestOnlyAddDriverEnvVarRunningWithElevatedPrivileges) {
FrameworkEnvironment env{FrameworkSettings{}.set_run_as_if_with_elevated_privleges(true)};
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::add_env_var));
env.get_test_icd(0).physical_devices.emplace_back("pd0");
env.get_test_icd(0).add_and_get_physical_device("pd0");

InstWrapper inst{env.vulkan_functions};
FillDebugUtilsCreateDetails(inst.create_info, env.debug_log);
Expand Down
25 changes: 13 additions & 12 deletions tests/loader_get_proc_addr_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ TEST(GetProcAddr, Verify10FunctionsLoadWithMultipleDrivers) {
// and return VK_SUCCESS to maintain previous behavior.
TEST(GetDeviceProcAddr, SwapchainFuncsWithTerminator) {
FrameworkEnvironment env{};
auto& driver =
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).setup_WSI().add_physical_device("physical_device_0");
auto& test_physical_device = env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA))
.setup_WSI()
.add_and_get_physical_device("physical_device_0");

InstWrapper inst(env.vulkan_functions);
inst.create_info.add_extension("VK_EXT_debug_utils");
Expand Down Expand Up @@ -250,7 +251,7 @@ TEST(GetDeviceProcAddr, SwapchainFuncsWithTerminator) {
log.logger.clear();
ASSERT_FALSE(dev_funcs.vkDestroySwapchainKHR);
}
driver.physical_devices.at(0).add_extensions({"VK_KHR_swapchain", "VK_KHR_display_swapchain", "VK_EXT_debug_marker"});
test_physical_device.add_extensions({"VK_KHR_swapchain", "VK_KHR_display_swapchain", "VK_EXT_debug_marker"});
{
DeviceWrapper dev{inst};
dev.create_info.add_extensions({"VK_KHR_swapchain", "VK_KHR_display_swapchain", "VK_EXT_debug_marker"});
Expand Down Expand Up @@ -328,15 +329,15 @@ TEST(GetProcAddr, PreserveLayerGettingVkCreateDeviceWithNullInstance) {

TEST(GetDeviceProcAddr, AppQueries11FunctionsWhileOnlyEnabling10) {
FrameworkEnvironment env{};
auto& driver =
auto& test_physical_device =
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_1))
.set_icd_api_version(VK_API_VERSION_1_1)
.add_physical_device(
.add_and_get_physical_device(
PhysicalDevice{}.set_api_version(VK_API_VERSION_1_1).add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME).finish());

std::vector<const char*> functions = {"vkGetDeviceQueue2", "vkCmdDispatchBase", "vkCreateDescriptorUpdateTemplate"};
for (const auto& f : functions) {
driver.physical_devices.back().add_device_function(VulkanFunction{f, [] {}});
test_physical_device.add_device_function(VulkanFunction{f, [] {}});
}
{ // doesn't enable the feature or extension
InstWrapper inst{env.vulkan_functions};
Expand Down Expand Up @@ -382,15 +383,15 @@ TEST(GetDeviceProcAddr, AppQueries11FunctionsWhileOnlyEnabling10) {

TEST(GetDeviceProcAddr, AppQueries12FunctionsWhileOnlyEnabling11) {
FrameworkEnvironment env{};
auto& driver =
auto& test_physical_device =
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_2))
.set_icd_api_version(VK_API_VERSION_1_2)
.add_physical_device(
.add_and_get_physical_device(
PhysicalDevice{}.set_api_version(VK_API_VERSION_1_2).add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME).finish());
std::vector<const char*> functions = {"vkCmdDrawIndirectCount", "vkCmdNextSubpass2", "vkGetBufferDeviceAddress",
"vkGetDeviceMemoryOpaqueCaptureAddress"};
for (const auto& f : functions) {
driver.physical_devices.back().add_device_function(VulkanFunction{f, [] {}});
test_physical_device.add_device_function(VulkanFunction{f, [] {}});
}
{ // doesn't enable the feature or extension
InstWrapper inst{env.vulkan_functions};
Expand Down Expand Up @@ -439,16 +440,16 @@ TEST(GetDeviceProcAddr, AppQueries12FunctionsWhileOnlyEnabling11) {

TEST(GetDeviceProcAddr, AppQueries13FunctionsWhileOnlyEnabling12) {
FrameworkEnvironment env{};
auto& driver =
auto& test_physical_device =
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_3))
.set_icd_api_version(VK_API_VERSION_1_3)
.add_physical_device(
.add_and_get_physical_device(
PhysicalDevice{}.set_api_version(VK_API_VERSION_1_3).add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME).finish());
std::vector<const char*> functions = {"vkCreatePrivateDataSlot", "vkGetDeviceBufferMemoryRequirements", "vkCmdWaitEvents2",
"vkGetDeviceImageSparseMemoryRequirements"};

for (const auto& f : functions) {
driver.physical_devices.back().add_device_function(VulkanFunction{f, [] {}});
test_physical_device.add_device_function(VulkanFunction{f, [] {}});
}
{ // doesn't enable the feature or extension
InstWrapper inst{env.vulkan_functions};
Expand Down
Loading
Loading