blob: 402b1477005323f594c7e854faa31918f8e6d6f5 [file] [log] [blame]
Tony Barbour34888cf2015-03-02 16:38:52 -07001#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002#include "vktestbinding.h"
Tony Barbour34888cf2015-03-02 16:38:52 -07003#include "test_environment.h"
Ian Elliott331f4e82015-07-06 14:33:04 -06004#include "vk_wsi_swapchain.h"
5#include "vk_wsi_device_swapchain.h"
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -06006
7#if defined(NDEBUG) && defined(__GNUC__)
8#define U_ASSERT_ONLY __attribute__((unused))
9#else
10#define U_ASSERT_ONLY
11#endif
Tony Barbour34888cf2015-03-02 16:38:52 -070012
13#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
14
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060015namespace vk_testing {
Tony Barbour34888cf2015-03-02 16:38:52 -070016
17Environment::Environment() :
Chia-I Wu5b66aa52015-04-16 22:02:10 +080018 default_dev_(0)
Tony Barbour34888cf2015-03-02 16:38:52 -070019{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060020 app_.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
21 app_.pAppName = "vk_testing";
Tony Barbour34888cf2015-03-02 16:38:52 -070022 app_.appVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060023 app_.pEngineName = "vk_testing";
Tony Barbour34888cf2015-03-02 16:38:52 -070024 app_.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060025 app_.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterf194c542015-06-23 08:54:19 -060026 app_.pNext = NULL;
Tony Barbour34888cf2015-03-02 16:38:52 -070027}
28
29bool Environment::parse_args(int argc, char **argv)
30{
31 int i;
32
33 for (i = 1; i < argc; i++) {
34#define ARG(name) (strcmp(argv[i], name) == 0)
35#define ARG_P(name) (i < argc - 1 && ARG(name))
36 if (ARG_P("--gpu")) {
37 default_dev_ = atoi(argv[++i]);
38 } else {
39 break;
40 }
41#undef ARG
42#undef ARG_P
43 }
44
45 if (i < argc) {
46 std::cout <<
47 "invalid argument: " << argv[i] << "\n\n" <<
48 "Usage: " << argv[0] << " <options>\n\n" <<
49 "Options:\n"
50 " --gpu <n> Use GPU<n> as the default GPU\n";
51
52 return false;
53 }
54
55 return true;
56}
57
58void Environment::SetUp()
59{
60
61 uint32_t count;
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060062 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060063 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060064 std::vector<VkExtensionProperties> instance_extensions;
65 std::vector<VkExtensionProperties> device_extensions;
66
Courtney Goeltzenleuchter61414de2015-07-07 11:47:33 -060067 std::vector<const char *> instance_extension_names;
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060068 std::vector<const char *> device_extension_names;
Courtney Goeltzenleuchter61414de2015-07-07 11:47:33 -060069 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060070
Ian Elliott331f4e82015-07-06 14:33:04 -060071 instance_extension_names.push_back(VK_WSI_SWAPCHAIN_EXTENSION_NAME);
72 device_extension_names.push_back(VK_WSI_DEVICE_SWAPCHAIN_EXTENSION_NAME);
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060073
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -060074 VkBool32 extFound;
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060075
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -060076 instance_extensions = vk_testing::GetGlobalExtensions();
77
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060078 for (uint32_t i = 0; i < instance_extension_names.size(); i++) {
79 extFound = 0;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -060080 for (uint32_t j = 0; j < instance_extensions.size(); j++) {
Courtney Goeltzenleuchterb774fb42015-07-06 15:45:58 -060081 if (!strcmp(instance_extension_names[i], instance_extensions[j].extName)) {
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060082 extFound = 1;
83 }
84 }
85 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] << " which is necessary to pass this test";
86 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060087 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -060088 inst_info.pNext = NULL;
89 inst_info.pAppInfo = &app_;
90 inst_info.pAllocCb = NULL;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -060091 inst_info.extensionCount = instance_extension_names.size();
92 inst_info.ppEnabledExtensionNames = (instance_extension_names.size()) ? &instance_extension_names[0] : NULL;
93 inst_info.layerCount = 0;
94 inst_info.ppEnabledLayerNames = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060095 err = vkCreateInstance(&inst_info, &inst);
96 ASSERT_EQ(VK_SUCCESS, err);
Jon Ashburn07b309a2015-04-15 11:31:12 -060097 err = vkEnumeratePhysicalDevices(inst, &count, NULL);
98 ASSERT_EQ(VK_SUCCESS, err);
99 ASSERT_LE(count, ARRAY_SIZE(gpus));
100 err = vkEnumeratePhysicalDevices(inst, &count, gpus);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600101 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour34888cf2015-03-02 16:38:52 -0700102 ASSERT_GT(count, default_dev_);
103
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800104 vk_testing::PhysicalDevice phys_dev(gpus[0]);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600105 device_extensions = phys_dev.extensions();
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -0600106
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -0600107 for (uint32_t i = 0; i < device_extension_names.size(); i++) {
108 extFound = 0;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600109 for (uint32_t j = 0; j < device_extensions.size(); j++) {
Ian Elliott331f4e82015-07-06 14:33:04 -0600110 if (!strcmp(device_extension_names[i], device_extensions[j].extName)) {
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -0600111 extFound = 1;
112 }
113 }
114 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] << " which is necessary to pass this test";
115 }
116
Tony Barbour34888cf2015-03-02 16:38:52 -0700117 devs_.reserve(count);
118 for (uint32_t i = 0; i < count; i++) {
119 devs_.push_back(new Device(gpus[i]));
120 if (i == default_dev_) {
Courtney Goeltzenleuchter61414de2015-07-07 11:47:33 -0600121 devs_[i]->init(device_layer_names, device_extension_names);
Tony Barbour34888cf2015-03-02 16:38:52 -0700122 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
123 }
124 }
125}
126
Tony Barbour34888cf2015-03-02 16:38:52 -0700127void Environment::TearDown()
128{
129 // destroy devices first
130 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
131 delete *it;
132 devs_.clear();
133
Courtney Goeltzenleuchter3fc66282015-07-06 15:45:16 -0600134 if (inst)
135 vkDestroyInstance(inst);
Tony Barbour34888cf2015-03-02 16:38:52 -0700136}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600137} // vk_testing namespace