2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
27 #include "test_common.h"
28 #include "vktestbinding.h"
29 #include "test_environment.h"
31 #if defined(NDEBUG) && defined(__GNUC__)
32 #define U_ASSERT_ONLY __attribute__((unused))
37 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
39 namespace vk_testing {
41 Environment::Environment() : default_dev_(0) {
42 app_.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
43 app_.pApplicationName = "vk_testing";
44 app_.applicationVersion = 1;
45 app_.pEngineName = "vk_testing";
46 app_.engineVersion = 1;
47 app_.apiVersion = VK_API_VERSION_1_0;
51 bool Environment::parse_args(int argc, char **argv) {
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))
58 default_dev_ = atoi(argv[++i]);
67 std::cout << "invalid argument: " << argv[i] << "\n\n"
68 << "Usage: " << argv[0] << " <options>\n\n"
70 " --gpu <n> Use GPU<n> as the default GPU\n";
78 void Environment::SetUp() {
81 VkResult U_ASSERT_ONLY err;
82 VkInstanceCreateInfo inst_info = {};
83 std::vector<VkExtensionProperties> instance_extensions;
84 std::vector<VkExtensionProperties> device_extensions;
86 std::vector<const char *> instance_extension_names;
87 std::vector<const char *> device_extension_names;
89 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
90 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
92 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
94 #ifdef VK_USE_PLATFORM_XCB_KHR
95 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
100 instance_extensions = vk_testing::GetGlobalExtensions();
102 for (uint32_t i = 0; i < instance_extension_names.size(); i++) {
104 for (uint32_t j = 0; j < instance_extensions.size(); j++) {
105 if (!strcmp(instance_extension_names[i], instance_extensions[j].extensionName)) {
109 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i]
110 << " which is necessary to pass this test";
112 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
113 inst_info.pNext = NULL;
114 inst_info.pApplicationInfo = &app_;
115 inst_info.enabledExtensionCount = instance_extension_names.size();
116 inst_info.ppEnabledExtensionNames = (instance_extension_names.size()) ? &instance_extension_names[0] : NULL;
117 inst_info.enabledLayerCount = 0;
118 inst_info.ppEnabledLayerNames = NULL;
119 err = vkCreateInstance(&inst_info, NULL, &inst);
120 ASSERT_EQ(VK_SUCCESS, err);
121 err = vkEnumeratePhysicalDevices(inst, &count, NULL);
122 ASSERT_EQ(VK_SUCCESS, err);
123 ASSERT_LE(count, ARRAY_SIZE(gpus));
124 err = vkEnumeratePhysicalDevices(inst, &count, gpus);
125 ASSERT_EQ(VK_SUCCESS, err);
126 ASSERT_GT(count, default_dev_);
128 vk_testing::PhysicalDevice phys_dev(gpus[0]);
129 device_extensions = phys_dev.extensions();
131 for (uint32_t i = 0; i < device_extension_names.size(); i++) {
133 for (uint32_t j = 0; j < device_extensions.size(); j++) {
134 if (!strcmp(device_extension_names[i], device_extensions[j].extensionName)) {
138 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i]
139 << " which is necessary to pass this test";
142 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_) {
146 devs_[i]->init(device_extension_names);
147 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
152 void Environment::TearDown() {
153 // destroy devices first
154 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
159 vkDestroyInstance(inst, NULL);
161 } // vk_testing namespace