blob: 67a98cc8073f897585812910d4eac6ea40420351 [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
80 uint32_t count;
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060081 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -060082 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060083 std::vector<VkExtensionProperties> instance_extensions;
84 std::vector<VkExtensionProperties> device_extensions;
85
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -060086 std::vector<const char *> instance_extension_names;
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060087 std::vector<const char *> device_extension_names;
88
Ian Elliottc11750d2015-10-30 13:24:12 -060089 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
90 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Tony Barbourfc7a0a62016-04-05 11:42:41 -060091#ifdef _WIN32
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -060092 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Tony Barbourfc7a0a62016-04-05 11:42:41 -060093#endif
94#ifdef VK_USE_PLATFORM_XCB_KHR
95 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
96#endif
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060097
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -060098 VkBool32 extFound;
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060099
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600100 instance_extensions = vk_testing::GetGlobalExtensions();
101
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600102 for (uint32_t i = 0; i < instance_extension_names.size(); i++) {
103 extFound = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600104 for (uint32_t j = 0; j < instance_extensions.size(); j++) {
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600105 if (!strcmp(instance_extension_names[i], instance_extensions[j].extensionName)) {
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600106 extFound = 1;
107 }
108 }
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600109 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i]
Karl Schultz6addd812016-02-02 17:17:23 -0700110 << " which is necessary to pass this test";
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600111 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600112 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburnb317fad2015-04-04 14:52:07 -0600113 inst_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800114 inst_info.pApplicationInfo = &app_;
Jon Ashburnf19916e2016-01-11 13:12:43 -0700115 inst_info.enabledExtensionCount = instance_extension_names.size();
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600116 inst_info.ppEnabledExtensionNames = (instance_extension_names.size()) ? &instance_extension_names[0] : NULL;
Jon Ashburnf19916e2016-01-11 13:12:43 -0700117 inst_info.enabledLayerCount = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600118 inst_info.ppEnabledLayerNames = NULL;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800119 err = vkCreateInstance(&inst_info, NULL, &inst);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600120 ASSERT_EQ(VK_SUCCESS, err);
Jon Ashburn83a64252015-04-15 11:31:12 -0600121 err = vkEnumeratePhysicalDevices(inst, &count, NULL);
122 ASSERT_EQ(VK_SUCCESS, err);
123 ASSERT_LE(count, ARRAY_SIZE(gpus));
124 err = vkEnumeratePhysicalDevices(inst, &count, gpus);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600125 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour92400bb2015-03-02 16:38:52 -0700126 ASSERT_GT(count, default_dev_);
127
Chia-I Wu999f0482015-07-03 10:32:05 +0800128 vk_testing::PhysicalDevice phys_dev(gpus[0]);
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600129 device_extensions = phys_dev.extensions();
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600130
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600131 for (uint32_t i = 0; i < device_extension_names.size(); i++) {
132 extFound = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600133 for (uint32_t j = 0; j < device_extensions.size(); j++) {
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600134 if (!strcmp(device_extension_names[i], device_extensions[j].extensionName)) {
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600135 extFound = 1;
136 }
137 }
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600138 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i]
Karl Schultz6addd812016-02-02 17:17:23 -0700139 << " which is necessary to pass this test";
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600140 }
141
Tony Barbour92400bb2015-03-02 16:38:52 -0700142 devs_.reserve(count);
143 for (uint32_t i = 0; i < count; i++) {
144 devs_.push_back(new Device(gpus[i]));
145 if (i == default_dev_) {
Tony Barbour4c70d102016-08-08 16:06:56 -0600146 devs_[i]->init(device_extension_names);
Tony Barbour92400bb2015-03-02 16:38:52 -0700147 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
148 }
149 }
150}
151
Karl Schultz6addd812016-02-02 17:17:23 -0700152void Environment::TearDown() {
Tony Barbour92400bb2015-03-02 16:38:52 -0700153 // destroy devices first
Mark Lobodzinski0a4c1702016-09-07 16:33:17 -0600154 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
Tony Barbour92400bb2015-03-02 16:38:52 -0700155 delete *it;
156 devs_.clear();
157
Courtney Goeltzenleuchter607a0972015-07-06 15:45:16 -0600158 if (inst)
Chia-I Wuf7458c52015-10-26 21:10:41 +0800159 vkDestroyInstance(inst, NULL);
Tony Barbour92400bb2015-03-02 16:38:52 -0700160}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600161} // vk_testing namespace