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); |
| 70 | device_extension_names.push_back(VK_WSI_LUNARG_EXTENSION_NAME); |
| 71 | |
| 72 | uint32_t extCount = 0; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame^] | 73 | err = vkGetGlobalExtensionCount(&extCount); |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 74 | assert(!err); |
| 75 | |
| 76 | VkExtensionProperties extProp; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 77 | bool32_t extFound; |
| 78 | |
| 79 | for (uint32_t i = 0; i < instance_extension_names.size(); i++) { |
| 80 | extFound = 0; |
| 81 | for (uint32_t j = 0; j < extCount; j++) { |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame^] | 82 | err = vkGetGlobalExtensionProperties(j, &extProp); |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 83 | assert(!err); |
| 84 | if (!strcmp(instance_extension_names[i], extProp.name)) { |
| 85 | instance_extensions.push_back(extProp); |
| 86 | extFound = 1; |
| 87 | } |
| 88 | } |
| 89 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] << " which is necessary to pass this test"; |
| 90 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 91 | inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 92 | inst_info.pNext = NULL; |
| 93 | inst_info.pAppInfo = &app_; |
| 94 | inst_info.pAllocCb = NULL; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 95 | inst_info.extensionCount = instance_extensions.size(); |
| 96 | inst_info.pEnabledExtensions = (instance_extensions.size()) ? &instance_extensions[0] : NULL; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 97 | err = vkCreateInstance(&inst_info, &inst); |
| 98 | ASSERT_EQ(VK_SUCCESS, err); |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 99 | err = vkEnumeratePhysicalDevices(inst, &count, NULL); |
| 100 | ASSERT_EQ(VK_SUCCESS, err); |
| 101 | ASSERT_LE(count, ARRAY_SIZE(gpus)); |
| 102 | err = vkEnumeratePhysicalDevices(inst, &count, gpus); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 103 | ASSERT_EQ(VK_SUCCESS, err); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 104 | ASSERT_GT(count, default_dev_); |
| 105 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame^] | 106 | err = vkGetPhysicalDeviceExtensionCount(gpus[0], &extCount); |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 107 | assert(!err); |
| 108 | |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 109 | for (uint32_t i = 0; i < device_extension_names.size(); i++) { |
| 110 | extFound = 0; |
| 111 | for (uint32_t j = 0; j < extCount; j++) { |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame^] | 112 | err = vkGetPhysicalDeviceExtensionProperties(gpus[0], j, &extProp); |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 113 | assert(!err); |
| 114 | if (!strcmp(device_extension_names[i], extProp.name)) { |
| 115 | device_extensions.push_back(extProp); |
| 116 | extFound = 1; |
| 117 | } |
| 118 | } |
| 119 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] << " which is necessary to pass this test"; |
| 120 | } |
| 121 | |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 122 | devs_.reserve(count); |
| 123 | for (uint32_t i = 0; i < count; i++) { |
| 124 | devs_.push_back(new Device(gpus[i])); |
| 125 | if (i == default_dev_) { |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 126 | devs_[i]->init(device_extensions); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 127 | ASSERT_NE(true, devs_[i]->graphics_queues().empty()); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 132 | void Environment::TearDown() |
| 133 | { |
| 134 | // destroy devices first |
| 135 | for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++) |
| 136 | delete *it; |
| 137 | devs_.clear(); |
| 138 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 139 | vkDestroyInstance(inst); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 140 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 141 | } // vk_testing namespace |