blob: e8dc95c6572c73edc5faafceab46c77a9ef72036 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
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 Ashburn3ebf1252016-04-19 11:30:31 -06006 * 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 Schultz6addd812016-02-02 17:17:23 -07009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * 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 Schultz6addd812016-02-02 17:17:23 -070017 *
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 Barbour92400bb2015-03-02 16:38:52 -070027#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vktestbinding.h"
Tony Barbour92400bb2015-03-02 16:38:52 -070029#include "test_environment.h"
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060030
31#if defined(NDEBUG) && defined(__GNUC__)
32#define U_ASSERT_ONLY __attribute__((unused))
33#else
34#define U_ASSERT_ONLY
35#endif
Tony Barbour92400bb2015-03-02 16:38:52 -070036
37#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
38
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060039namespace vk_testing {
Tony Barbour92400bb2015-03-02 16:38:52 -070040
Karl Schultz6addd812016-02-02 17:17:23 -070041Environment::Environment() : default_dev_(0) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060042 app_.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080043 app_.pApplicationName = "vk_testing";
44 app_.applicationVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060045 app_.pEngineName = "vk_testing";
Tony Barbour92400bb2015-03-02 16:38:52 -070046 app_.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -060047 app_.apiVersion = VK_API_VERSION_1_0;
Courtney Goeltzenleuchteraca235e2015-06-23 08:54:19 -060048 app_.pNext = NULL;
Tony Barbour92400bb2015-03-02 16:38:52 -070049}
50
Karl Schultz6addd812016-02-02 17:17:23 -070051bool Environment::parse_args(int argc, char **argv) {
Tony Barbour92400bb2015-03-02 16:38:52 -070052 int i;
53
54 for (i = 1; i < argc; i++) {
55#define ARG(name) (strcmp(argv[i], name) == 0)
56#define ARG_P(name) (i < argc - 1 && ARG(name))
57 if (ARG_P("--gpu")) {
58 default_dev_ = atoi(argv[++i]);
59 } else {
60 break;
61 }
62#undef ARG
63#undef ARG_P
64 }
65
66 if (i < argc) {
Karl Schultz6addd812016-02-02 17:17:23 -070067 std::cout << "invalid argument: " << argv[i] << "\n\n"
68 << "Usage: " << argv[0] << " <options>\n\n"
69 << "Options:\n"
70 " --gpu <n> Use GPU<n> as the default GPU\n";
Tony Barbour92400bb2015-03-02 16:38:52 -070071
72 return false;
73 }
74
75 return true;
76}
77
Karl Schultz6addd812016-02-02 17:17:23 -070078void Environment::SetUp() {
Tony Barbour92400bb2015-03-02 16:38:52 -070079 uint32_t count;
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060080 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -060081 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060082 std::vector<VkExtensionProperties> instance_extensions;
83 std::vector<VkExtensionProperties> device_extensions;
84
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -060085 std::vector<const char *> instance_extension_names;
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060086 std::vector<const char *> device_extension_names;
87
Ian Elliottc11750d2015-10-30 13:24:12 -060088 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
89 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Tony Barbourfc7a0a62016-04-05 11:42:41 -060090#ifdef _WIN32
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -060091 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Tony Barbourfc7a0a62016-04-05 11:42:41 -060092#endif
93#ifdef VK_USE_PLATFORM_XCB_KHR
94 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
95#endif
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060096
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -060097 VkBool32 extFound;
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060098
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060099 instance_extensions = vk_testing::GetGlobalExtensions();
100
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600101 for (uint32_t i = 0; i < instance_extension_names.size(); i++) {
102 extFound = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600103 for (uint32_t j = 0; j < instance_extensions.size(); j++) {
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600104 if (!strcmp(instance_extension_names[i], instance_extensions[j].extensionName)) {
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600105 extFound = 1;
106 }
107 }
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600108 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i]
Karl Schultz6addd812016-02-02 17:17:23 -0700109 << " which is necessary to pass this test";
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600110 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600111 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburnb317fad2015-04-04 14:52:07 -0600112 inst_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800113 inst_info.pApplicationInfo = &app_;
Jon Ashburnf19916e2016-01-11 13:12:43 -0700114 inst_info.enabledExtensionCount = instance_extension_names.size();
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600115 inst_info.ppEnabledExtensionNames = (instance_extension_names.size()) ? &instance_extension_names[0] : NULL;
Jon Ashburnf19916e2016-01-11 13:12:43 -0700116 inst_info.enabledLayerCount = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600117 inst_info.ppEnabledLayerNames = NULL;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800118 err = vkCreateInstance(&inst_info, NULL, &inst);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600119 ASSERT_EQ(VK_SUCCESS, err);
Jon Ashburn83a64252015-04-15 11:31:12 -0600120 err = vkEnumeratePhysicalDevices(inst, &count, NULL);
121 ASSERT_EQ(VK_SUCCESS, err);
122 ASSERT_LE(count, ARRAY_SIZE(gpus));
123 err = vkEnumeratePhysicalDevices(inst, &count, gpus);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600124 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour92400bb2015-03-02 16:38:52 -0700125 ASSERT_GT(count, default_dev_);
126
Chia-I Wu999f0482015-07-03 10:32:05 +0800127 vk_testing::PhysicalDevice phys_dev(gpus[0]);
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600128 device_extensions = phys_dev.extensions();
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600129
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600130 for (uint32_t i = 0; i < device_extension_names.size(); i++) {
131 extFound = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600132 for (uint32_t j = 0; j < device_extensions.size(); j++) {
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600133 if (!strcmp(device_extension_names[i], device_extensions[j].extensionName)) {
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600134 extFound = 1;
135 }
136 }
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600137 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i]
Karl Schultz6addd812016-02-02 17:17:23 -0700138 << " which is necessary to pass this test";
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600139 }
140
Tony Barbour92400bb2015-03-02 16:38:52 -0700141 devs_.reserve(count);
142 for (uint32_t i = 0; i < count; i++) {
143 devs_.push_back(new Device(gpus[i]));
144 if (i == default_dev_) {
Tony Barbour4c70d102016-08-08 16:06:56 -0600145 devs_[i]->init(device_extension_names);
Tony Barbour92400bb2015-03-02 16:38:52 -0700146 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
147 }
148 }
149}
150
Karl Schultz6addd812016-02-02 17:17:23 -0700151void Environment::TearDown() {
Tony Barbour92400bb2015-03-02 16:38:52 -0700152 // destroy devices first
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700153 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++) delete *it;
Tony Barbour92400bb2015-03-02 16:38:52 -0700154 devs_.clear();
155
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700156 if (inst) vkDestroyInstance(inst, NULL);
Tony Barbour92400bb2015-03-02 16:38:52 -0700157}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700158} // vk_testing namespace