blob: bdb7d6435c883db2c6d8bb8110e01b171b4dba16 [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"
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -06004#include "vk_wsi_lunarg.h"
5
6#if defined(NDEBUG) && defined(__GNUC__)
7#define U_ASSERT_ONLY __attribute__((unused))
8#else
9#define U_ASSERT_ONLY
10#endif
Tony Barbour34888cf2015-03-02 16:38:52 -070011
12#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
13
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060014namespace vk_testing {
Tony Barbour34888cf2015-03-02 16:38:52 -070015
16Environment::Environment() :
Chia-I Wu5b66aa52015-04-16 22:02:10 +080017 default_dev_(0)
Tony Barbour34888cf2015-03-02 16:38:52 -070018{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060019 app_.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
20 app_.pAppName = "vk_testing";
Tony Barbour34888cf2015-03-02 16:38:52 -070021 app_.appVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060022 app_.pEngineName = "vk_testing";
Tony Barbour34888cf2015-03-02 16:38:52 -070023 app_.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060024 app_.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterf194c542015-06-23 08:54:19 -060025 app_.pNext = NULL;
Tony Barbour34888cf2015-03-02 16:38:52 -070026}
27
28bool Environment::parse_args(int argc, char **argv)
29{
30 int i;
31
32 for (i = 1; i < argc; i++) {
33#define ARG(name) (strcmp(argv[i], name) == 0)
34#define ARG_P(name) (i < argc - 1 && ARG(name))
35 if (ARG_P("--gpu")) {
36 default_dev_ = atoi(argv[++i]);
37 } else {
38 break;
39 }
40#undef ARG
41#undef ARG_P
42 }
43
44 if (i < argc) {
45 std::cout <<
46 "invalid argument: " << argv[i] << "\n\n" <<
47 "Usage: " << argv[0] << " <options>\n\n" <<
48 "Options:\n"
49 " --gpu <n> Use GPU<n> as the default GPU\n";
50
51 return false;
52 }
53
54 return true;
55}
56
57void Environment::SetUp()
58{
59
60 uint32_t count;
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060061 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060062 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060063 std::vector<VkExtensionProperties> instance_extensions;
64 std::vector<VkExtensionProperties> device_extensions;
65
66 std::vector<const char*> instance_extension_names;
67 std::vector<const char *> device_extension_names;
68
69 instance_extension_names.push_back(VK_WSI_LUNARG_EXTENSION_NAME);
70 device_extension_names.push_back(VK_WSI_LUNARG_EXTENSION_NAME);
71
72 uint32_t extCount = 0;
73 size_t extSize = sizeof(extCount);
74 err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_COUNT, 0, &extSize, &extCount);
75 assert(!err);
76
77 VkExtensionProperties extProp;
78 extSize = sizeof(VkExtensionProperties);
79 bool32_t extFound;
80
81 for (uint32_t i = 0; i < instance_extension_names.size(); i++) {
82 extFound = 0;
83 for (uint32_t j = 0; j < extCount; j++) {
84 err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_PROPERTIES, j, &extSize, &extProp);
85 assert(!err);
86 if (!strcmp(instance_extension_names[i], extProp.name)) {
87 instance_extensions.push_back(extProp);
88 extFound = 1;
89 }
90 }
91 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] << " which is necessary to pass this test";
92 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060093 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -060094 inst_info.pNext = NULL;
95 inst_info.pAppInfo = &app_;
96 inst_info.pAllocCb = NULL;
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060097 inst_info.extensionCount = instance_extensions.size();
98 inst_info.pEnabledExtensions = (instance_extensions.size()) ? &instance_extensions[0] : NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060099 err = vkCreateInstance(&inst_info, &inst);
100 ASSERT_EQ(VK_SUCCESS, err);
Jon Ashburn07b309a2015-04-15 11:31:12 -0600101 err = vkEnumeratePhysicalDevices(inst, &count, NULL);
102 ASSERT_EQ(VK_SUCCESS, err);
103 ASSERT_LE(count, ARRAY_SIZE(gpus));
104 err = vkEnumeratePhysicalDevices(inst, &count, gpus);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600105 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour34888cf2015-03-02 16:38:52 -0700106 ASSERT_GT(count, default_dev_);
107
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -0600108 extSize = sizeof(extCount);
109 err = vkGetPhysicalDeviceExtensionInfo(gpus[0], VK_EXTENSION_INFO_TYPE_COUNT, 0, &extSize, &extCount);
110 assert(!err);
111
112 extSize = sizeof(VkExtensionProperties);
113 for (uint32_t i = 0; i < device_extension_names.size(); i++) {
114 extFound = 0;
115 for (uint32_t j = 0; j < extCount; j++) {
116 err = vkGetPhysicalDeviceExtensionInfo(gpus[0], VK_EXTENSION_INFO_TYPE_PROPERTIES, j, &extSize, &extProp);
117 assert(!err);
118 if (!strcmp(device_extension_names[i], extProp.name)) {
119 device_extensions.push_back(extProp);
120 extFound = 1;
121 }
122 }
123 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] << " which is necessary to pass this test";
124 }
125
Tony Barbour34888cf2015-03-02 16:38:52 -0700126 devs_.reserve(count);
127 for (uint32_t i = 0; i < count; i++) {
128 devs_.push_back(new Device(gpus[i]));
129 if (i == default_dev_) {
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -0600130 devs_[i]->init(device_extensions);
Tony Barbour34888cf2015-03-02 16:38:52 -0700131 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
132 }
133 }
134}
135
Tony Barbour34888cf2015-03-02 16:38:52 -0700136void Environment::TearDown()
137{
138 // destroy devices first
139 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
140 delete *it;
141 devs_.clear();
142
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600143 vkDestroyInstance(inst);
Tony Barbour34888cf2015-03-02 16:38:52 -0700144}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600145} // vk_testing namespace