Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016 Valve Corporation |
| 4 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 17 | * |
| 18 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 19 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 20 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 21 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 22 | * Author: Mike Stroyan <mike@LunarG.com> |
| 23 | * Author: Tobin Ehlis <tobine@google.com> |
| 24 | * Author: Tony Barbour <tony@LunarG.com> |
| 25 | */ |
| 26 | |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 27 | #include "test_common.h" |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 28 | #include "test_environment.h" |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 29 | |
| 30 | #if defined(NDEBUG) && defined(__GNUC__) |
| 31 | #define U_ASSERT_ONLY __attribute__((unused)) |
| 32 | #else |
| 33 | #define U_ASSERT_ONLY |
| 34 | #endif |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 35 | |
| 36 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 37 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 38 | namespace vk_testing { |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 39 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 40 | Environment::Environment() : default_dev_(0) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 41 | app_.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 42 | app_.pApplicationName = "vk_testing"; |
| 43 | app_.applicationVersion = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 44 | app_.pEngineName = "vk_testing"; |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 45 | app_.engineVersion = 1; |
Jon Ashburn | c5012ff | 2016-03-22 13:57:46 -0600 | [diff] [blame] | 46 | app_.apiVersion = VK_API_VERSION_1_0; |
Courtney Goeltzenleuchter | aca235e | 2015-06-23 08:54:19 -0600 | [diff] [blame] | 47 | app_.pNext = NULL; |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 50 | bool Environment::parse_args(int argc, char **argv) { |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 51 | int i; |
| 52 | |
| 53 | for (i = 1; i < argc; i++) { |
| 54 | #define ARG(name) (strcmp(argv[i], name) == 0) |
| 55 | #define ARG_P(name) (i < argc - 1 && ARG(name)) |
| 56 | if (ARG_P("--gpu")) { |
| 57 | default_dev_ = atoi(argv[++i]); |
| 58 | } else { |
| 59 | break; |
| 60 | } |
| 61 | #undef ARG |
| 62 | #undef ARG_P |
| 63 | } |
| 64 | |
| 65 | if (i < argc) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 66 | std::cout << "invalid argument: " << argv[i] << "\n\n" |
| 67 | << "Usage: " << argv[0] << " <options>\n\n" |
| 68 | << "Options:\n" |
| 69 | " --gpu <n> Use GPU<n> as the default GPU\n"; |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 70 | |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | return true; |
| 75 | } |
| 76 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 77 | void Environment::SetUp() { |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 78 | uint32_t count; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 79 | VkResult U_ASSERT_ONLY err; |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 80 | VkInstanceCreateInfo inst_info = {}; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 81 | std::vector<VkExtensionProperties> instance_extensions; |
| 82 | std::vector<VkExtensionProperties> device_extensions; |
| 83 | |
Courtney Goeltzenleuchter | 5bac609 | 2015-07-07 11:47:33 -0600 | [diff] [blame] | 84 | std::vector<const char *> instance_extension_names; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 85 | std::vector<const char *> device_extension_names; |
| 86 | |
Ian Elliott | c11750d | 2015-10-30 13:24:12 -0600 | [diff] [blame] | 87 | instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 88 | device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Tony Barbour | fc7a0a6 | 2016-04-05 11:42:41 -0600 | [diff] [blame] | 89 | #ifdef _WIN32 |
Mark Lobodzinski | 0a4c170 | 2016-09-07 16:33:17 -0600 | [diff] [blame] | 90 | instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
Tony Barbour | fc7a0a6 | 2016-04-05 11:42:41 -0600 | [diff] [blame] | 91 | #endif |
| 92 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 93 | instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
| 94 | #endif |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 95 | |
Courtney Goeltzenleuchter | cd2a099 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 96 | VkBool32 extFound; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 97 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 98 | instance_extensions = vk_testing::GetGlobalExtensions(); |
| 99 | |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 100 | for (uint32_t i = 0; i < instance_extension_names.size(); i++) { |
| 101 | extFound = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 102 | for (uint32_t j = 0; j < instance_extensions.size(); j++) { |
Mark Lobodzinski | 0a4c170 | 2016-09-07 16:33:17 -0600 | [diff] [blame] | 103 | if (!strcmp(instance_extension_names[i], instance_extensions[j].extensionName)) { |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 104 | extFound = 1; |
| 105 | } |
| 106 | } |
Mark Lobodzinski | 0a4c170 | 2016-09-07 16:33:17 -0600 | [diff] [blame] | 107 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 108 | << " which is necessary to pass this test"; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 109 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 110 | inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 111 | inst_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 112 | inst_info.pApplicationInfo = &app_; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 113 | inst_info.enabledExtensionCount = instance_extension_names.size(); |
Mark Lobodzinski | 0a4c170 | 2016-09-07 16:33:17 -0600 | [diff] [blame] | 114 | inst_info.ppEnabledExtensionNames = (instance_extension_names.size()) ? &instance_extension_names[0] : NULL; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 115 | inst_info.enabledLayerCount = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 116 | inst_info.ppEnabledLayerNames = NULL; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 117 | err = vkCreateInstance(&inst_info, NULL, &inst); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 118 | ASSERT_EQ(VK_SUCCESS, err); |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 119 | err = vkEnumeratePhysicalDevices(inst, &count, NULL); |
| 120 | ASSERT_EQ(VK_SUCCESS, err); |
| 121 | ASSERT_LE(count, ARRAY_SIZE(gpus)); |
| 122 | err = vkEnumeratePhysicalDevices(inst, &count, gpus); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 123 | ASSERT_EQ(VK_SUCCESS, err); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 124 | ASSERT_GT(count, default_dev_); |
| 125 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 126 | vk_testing::PhysicalDevice phys_dev(gpus[0]); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 127 | device_extensions = phys_dev.extensions(); |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 128 | |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 129 | for (uint32_t i = 0; i < device_extension_names.size(); i++) { |
| 130 | extFound = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 131 | for (uint32_t j = 0; j < device_extensions.size(); j++) { |
Mark Lobodzinski | 0a4c170 | 2016-09-07 16:33:17 -0600 | [diff] [blame] | 132 | if (!strcmp(device_extension_names[i], device_extensions[j].extensionName)) { |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 133 | extFound = 1; |
| 134 | } |
| 135 | } |
Mark Lobodzinski | 0a4c170 | 2016-09-07 16:33:17 -0600 | [diff] [blame] | 136 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 137 | << " which is necessary to pass this test"; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 138 | } |
| 139 | |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 140 | devs_.reserve(count); |
| 141 | for (uint32_t i = 0; i < count; i++) { |
| 142 | devs_.push_back(new Device(gpus[i])); |
| 143 | if (i == default_dev_) { |
Tony Barbour | 4c70d10 | 2016-08-08 16:06:56 -0600 | [diff] [blame] | 144 | devs_[i]->init(device_extension_names); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 145 | ASSERT_NE(true, devs_[i]->graphics_queues().empty()); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 150 | void Environment::TearDown() { |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 151 | // destroy devices first |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 152 | for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++) delete *it; |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 153 | devs_.clear(); |
| 154 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 155 | if (inst) vkDestroyInstance(inst, NULL); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 156 | } |
Dave Houlton | 6c72f35 | 2018-02-06 17:49:16 -0700 | [diff] [blame] | 157 | } // namespace vk_testing |