Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 1 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | #include "vktestbinding.h" |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 3 | #include "test_environment.h" |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 4 | #include "vk_wsi_lunarg.h" |
| 5 | |
| 6 | #if defined(NDEBUG) && defined(__GNUC__) |
| 7 | #define U_ASSERT_ONLY __attribute__((unused)) |
| 8 | #else |
| 9 | #define U_ASSERT_ONLY |
| 10 | #endif |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 11 | |
| 12 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 13 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 14 | namespace vk_testing { |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 15 | |
| 16 | Environment::Environment() : |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 17 | default_dev_(0) |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 18 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 19 | app_.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
| 20 | app_.pAppName = "vk_testing"; |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 21 | app_.appVersion = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 22 | app_.pEngineName = "vk_testing"; |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 23 | app_.engineVersion = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 24 | app_.apiVersion = VK_API_VERSION; |
Courtney Goeltzenleuchter | aca235e | 2015-06-23 08:54:19 -0600 | [diff] [blame] | 25 | app_.pNext = NULL; |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | bool Environment::parse_args(int argc, char **argv) |
| 29 | { |
| 30 | int i; |
| 31 | |
| 32 | for (i = 1; i < argc; i++) { |
| 33 | #define ARG(name) (strcmp(argv[i], name) == 0) |
| 34 | #define ARG_P(name) (i < argc - 1 && ARG(name)) |
| 35 | if (ARG_P("--gpu")) { |
| 36 | default_dev_ = atoi(argv[++i]); |
| 37 | } else { |
| 38 | break; |
| 39 | } |
| 40 | #undef ARG |
| 41 | #undef ARG_P |
| 42 | } |
| 43 | |
| 44 | if (i < argc) { |
| 45 | std::cout << |
| 46 | "invalid argument: " << argv[i] << "\n\n" << |
| 47 | "Usage: " << argv[0] << " <options>\n\n" << |
| 48 | "Options:\n" |
| 49 | " --gpu <n> Use GPU<n> as the default GPU\n"; |
| 50 | |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | void Environment::SetUp() |
| 58 | { |
| 59 | |
| 60 | uint32_t count; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 61 | VkResult U_ASSERT_ONLY err; |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 62 | VkInstanceCreateInfo inst_info = {}; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 63 | std::vector<VkExtensionProperties> instance_extensions; |
| 64 | std::vector<VkExtensionProperties> device_extensions; |
| 65 | |
| 66 | std::vector<const char*> instance_extension_names; |
| 67 | std::vector<const char *> device_extension_names; |
| 68 | |
| 69 | instance_extension_names.push_back(VK_WSI_LUNARG_EXTENSION_NAME); |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 70 | |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 71 | bool32_t extFound; |
| 72 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame^] | 73 | instance_extensions = vk_testing::GetGlobalExtensions(); |
| 74 | |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 75 | for (uint32_t i = 0; i < instance_extension_names.size(); i++) { |
| 76 | extFound = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame^] | 77 | for (uint32_t j = 0; j < instance_extensions.size(); j++) { |
| 78 | if (!strcmp(instance_extension_names[i], instance_extensions[i].extName)) { |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 79 | extFound = 1; |
| 80 | } |
| 81 | } |
| 82 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] << " which is necessary to pass this test"; |
| 83 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 84 | inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 85 | inst_info.pNext = NULL; |
| 86 | inst_info.pAppInfo = &app_; |
| 87 | inst_info.pAllocCb = NULL; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame^] | 88 | inst_info.extensionCount = instance_extension_names.size(); |
| 89 | inst_info.ppEnabledExtensionNames = (instance_extension_names.size()) ? &instance_extension_names[0] : NULL; |
| 90 | inst_info.layerCount = 0; |
| 91 | inst_info.ppEnabledLayerNames = NULL; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 92 | err = vkCreateInstance(&inst_info, &inst); |
| 93 | ASSERT_EQ(VK_SUCCESS, err); |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 94 | err = vkEnumeratePhysicalDevices(inst, &count, NULL); |
| 95 | ASSERT_EQ(VK_SUCCESS, err); |
| 96 | ASSERT_LE(count, ARRAY_SIZE(gpus)); |
| 97 | err = vkEnumeratePhysicalDevices(inst, &count, gpus); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 98 | ASSERT_EQ(VK_SUCCESS, err); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 99 | ASSERT_GT(count, default_dev_); |
| 100 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame^] | 101 | vk_testing::PhysicalGpu phys_dev(gpus[0]); |
| 102 | device_extensions = phys_dev.extensions(); |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 103 | |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 104 | for (uint32_t i = 0; i < device_extension_names.size(); i++) { |
| 105 | extFound = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame^] | 106 | for (uint32_t j = 0; j < device_extensions.size(); j++) { |
| 107 | if (!strcmp(device_extension_names[i], device_extensions[i].extName)) { |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 108 | extFound = 1; |
| 109 | } |
| 110 | } |
| 111 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] << " which is necessary to pass this test"; |
| 112 | } |
| 113 | |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 114 | devs_.reserve(count); |
| 115 | for (uint32_t i = 0; i < count; i++) { |
| 116 | devs_.push_back(new Device(gpus[i])); |
| 117 | if (i == default_dev_) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame^] | 118 | devs_[i]->init(device_extension_names); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 119 | ASSERT_NE(true, devs_[i]->graphics_queues().empty()); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 124 | void Environment::TearDown() |
| 125 | { |
| 126 | // destroy devices first |
| 127 | for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++) |
| 128 | delete *it; |
| 129 | devs_.clear(); |
| 130 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 131 | vkDestroyInstance(inst); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 132 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 133 | } // vk_testing namespace |