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 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and/or associated documentation files (the "Materials"), to |
| 8 | * deal in the Materials without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Materials, and to permit persons to whom the Materials are |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice(s) and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Materials. |
| 15 | * |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 16 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 | * |
| 20 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 21 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 22 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 23 | * USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 | * |
| 25 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 26 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 27 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 28 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 29 | * Author: Mike Stroyan <mike@LunarG.com> |
| 30 | * Author: Tobin Ehlis <tobine@google.com> |
| 31 | * Author: Tony Barbour <tony@LunarG.com> |
| 32 | */ |
| 33 | |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 34 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 35 | #include "vktestbinding.h" |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 36 | #include "test_environment.h" |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 37 | |
| 38 | #if defined(NDEBUG) && defined(__GNUC__) |
| 39 | #define U_ASSERT_ONLY __attribute__((unused)) |
| 40 | #else |
| 41 | #define U_ASSERT_ONLY |
| 42 | #endif |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 43 | |
| 44 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 45 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 46 | namespace vk_testing { |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 47 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 48 | Environment::Environment() : default_dev_(0) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 49 | app_.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 50 | app_.pApplicationName = "vk_testing"; |
| 51 | app_.applicationVersion = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 52 | app_.pEngineName = "vk_testing"; |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 53 | app_.engineVersion = 1; |
Jon Ashburn | c5012ff | 2016-03-22 13:57:46 -0600 | [diff] [blame] | 54 | app_.apiVersion = VK_API_VERSION_1_0; |
Courtney Goeltzenleuchter | aca235e | 2015-06-23 08:54:19 -0600 | [diff] [blame] | 55 | app_.pNext = NULL; |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 58 | bool Environment::parse_args(int argc, char **argv) { |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 59 | int i; |
| 60 | |
| 61 | for (i = 1; i < argc; i++) { |
| 62 | #define ARG(name) (strcmp(argv[i], name) == 0) |
| 63 | #define ARG_P(name) (i < argc - 1 && ARG(name)) |
| 64 | if (ARG_P("--gpu")) { |
| 65 | default_dev_ = atoi(argv[++i]); |
| 66 | } else { |
| 67 | break; |
| 68 | } |
| 69 | #undef ARG |
| 70 | #undef ARG_P |
| 71 | } |
| 72 | |
| 73 | if (i < argc) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 74 | std::cout << "invalid argument: " << argv[i] << "\n\n" |
| 75 | << "Usage: " << argv[0] << " <options>\n\n" |
| 76 | << "Options:\n" |
| 77 | " --gpu <n> Use GPU<n> as the default GPU\n"; |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 78 | |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | return true; |
| 83 | } |
| 84 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 85 | void Environment::SetUp() { |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 86 | |
| 87 | uint32_t count; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 88 | VkResult U_ASSERT_ONLY err; |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 89 | VkInstanceCreateInfo inst_info = {}; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 90 | std::vector<VkExtensionProperties> instance_extensions; |
| 91 | std::vector<VkExtensionProperties> device_extensions; |
| 92 | |
Courtney Goeltzenleuchter | 5bac609 | 2015-07-07 11:47:33 -0600 | [diff] [blame] | 93 | std::vector<const char *> instance_extension_names; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 94 | std::vector<const char *> device_extension_names; |
Courtney Goeltzenleuchter | 5bac609 | 2015-07-07 11:47:33 -0600 | [diff] [blame] | 95 | std::vector<const char *> device_layer_names; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 96 | |
Ian Elliott | c11750d | 2015-10-30 13:24:12 -0600 | [diff] [blame] | 97 | instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 98 | device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Tony Barbour | fc7a0a6 | 2016-04-05 11:42:41 -0600 | [diff] [blame^] | 99 | #ifdef _WIN32 |
| 100 | instance_extension_names.push_back( |
| 101 | VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
| 102 | #endif |
| 103 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 104 | instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
| 105 | #endif |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 106 | |
Courtney Goeltzenleuchter | cd2a099 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 107 | VkBool32 extFound; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 108 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 109 | instance_extensions = vk_testing::GetGlobalExtensions(); |
| 110 | |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 111 | for (uint32_t i = 0; i < instance_extension_names.size(); i++) { |
| 112 | extFound = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 113 | for (uint32_t j = 0; j < instance_extensions.size(); j++) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 114 | if (!strcmp(instance_extension_names[i], |
| 115 | instance_extensions[j].extensionName)) { |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 116 | extFound = 1; |
| 117 | } |
| 118 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 119 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " |
| 120 | << instance_extension_names[i] |
| 121 | << " which is necessary to pass this test"; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 122 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 123 | inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 124 | inst_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 125 | inst_info.pApplicationInfo = &app_; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 126 | inst_info.enabledExtensionCount = instance_extension_names.size(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 127 | inst_info.ppEnabledExtensionNames = |
| 128 | (instance_extension_names.size()) ? &instance_extension_names[0] : NULL; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 129 | inst_info.enabledLayerCount = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 130 | inst_info.ppEnabledLayerNames = NULL; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 131 | err = vkCreateInstance(&inst_info, NULL, &inst); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 132 | ASSERT_EQ(VK_SUCCESS, err); |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 133 | err = vkEnumeratePhysicalDevices(inst, &count, NULL); |
| 134 | ASSERT_EQ(VK_SUCCESS, err); |
| 135 | ASSERT_LE(count, ARRAY_SIZE(gpus)); |
| 136 | err = vkEnumeratePhysicalDevices(inst, &count, gpus); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 137 | ASSERT_EQ(VK_SUCCESS, err); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 138 | ASSERT_GT(count, default_dev_); |
| 139 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 140 | vk_testing::PhysicalDevice phys_dev(gpus[0]); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 141 | device_extensions = phys_dev.extensions(); |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 142 | |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 143 | for (uint32_t i = 0; i < device_extension_names.size(); i++) { |
| 144 | extFound = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 145 | for (uint32_t j = 0; j < device_extensions.size(); j++) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 146 | if (!strcmp(device_extension_names[i], |
| 147 | device_extensions[j].extensionName)) { |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 148 | extFound = 1; |
| 149 | } |
| 150 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 151 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " |
| 152 | << device_extension_names[i] |
| 153 | << " which is necessary to pass this test"; |
Courtney Goeltzenleuchter | 553b9cb | 2015-06-24 15:03:26 -0600 | [diff] [blame] | 154 | } |
| 155 | |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 156 | devs_.reserve(count); |
| 157 | for (uint32_t i = 0; i < count; i++) { |
| 158 | devs_.push_back(new Device(gpus[i])); |
| 159 | if (i == default_dev_) { |
Courtney Goeltzenleuchter | 5bac609 | 2015-07-07 11:47:33 -0600 | [diff] [blame] | 160 | devs_[i]->init(device_layer_names, device_extension_names); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 161 | ASSERT_NE(true, devs_[i]->graphics_queues().empty()); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 166 | void Environment::TearDown() { |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 167 | // destroy devices first |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 168 | for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); |
| 169 | it++) |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 170 | delete *it; |
| 171 | devs_.clear(); |
| 172 | |
Courtney Goeltzenleuchter | 607a097 | 2015-07-06 15:45:16 -0600 | [diff] [blame] | 173 | if (inst) |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 174 | vkDestroyInstance(inst, NULL); |
Tony Barbour | 92400bb | 2015-03-02 16:38:52 -0700 | [diff] [blame] | 175 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 176 | } // vk_testing namespace |