blob: c973f55ff260975c5a59b488caf6ae7b7daf3880 [file] [log] [blame]
Tony Barbour92400bb2015-03-02 16:38:52 -07001#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002#include "vktestbinding.h"
Tony Barbour92400bb2015-03-02 16:38:52 -07003#include "test_environment.h"
Courtney Goeltzenleuchter553b9cb2015-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 Barbour92400bb2015-03-02 16:38:52 -070011
12#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
13
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060014namespace vk_testing {
Tony Barbour92400bb2015-03-02 16:38:52 -070015
16Environment::Environment() :
Chia-I Wuf8693382015-04-16 22:02:10 +080017 default_dev_(0)
Tony Barbour92400bb2015-03-02 16:38:52 -070018{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060019 app_.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
20 app_.pAppName = "vk_testing";
Tony Barbour92400bb2015-03-02 16:38:52 -070021 app_.appVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060022 app_.pEngineName = "vk_testing";
Tony Barbour92400bb2015-03-02 16:38:52 -070023 app_.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060024 app_.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchteraca235e2015-06-23 08:54:19 -060025 app_.pNext = NULL;
Tony Barbour92400bb2015-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 Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060061 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -060062 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter553b9cb2015-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;
Tony Barbour59a47322015-06-24 16:06:58 -060073 err = vkGetGlobalExtensionCount(&extCount);
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060074 assert(!err);
75
76 VkExtensionProperties extProp;
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060077 bool32_t extFound;
78
79 for (uint32_t i = 0; i < instance_extension_names.size(); i++) {
80 extFound = 0;
81 for (uint32_t j = 0; j < extCount; j++) {
Tony Barbour59a47322015-06-24 16:06:58 -060082 err = vkGetGlobalExtensionProperties(j, &extProp);
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060083 assert(!err);
84 if (!strcmp(instance_extension_names[i], extProp.name)) {
85 instance_extensions.push_back(extProp);
86 extFound = 1;
87 }
88 }
89 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] << " which is necessary to pass this test";
90 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060091 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburnb317fad2015-04-04 14:52:07 -060092 inst_info.pNext = NULL;
93 inst_info.pAppInfo = &app_;
94 inst_info.pAllocCb = NULL;
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060095 inst_info.extensionCount = instance_extensions.size();
96 inst_info.pEnabledExtensions = (instance_extensions.size()) ? &instance_extensions[0] : NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060097 err = vkCreateInstance(&inst_info, &inst);
98 ASSERT_EQ(VK_SUCCESS, err);
Jon Ashburn83a64252015-04-15 11:31:12 -060099 err = vkEnumeratePhysicalDevices(inst, &count, NULL);
100 ASSERT_EQ(VK_SUCCESS, err);
101 ASSERT_LE(count, ARRAY_SIZE(gpus));
102 err = vkEnumeratePhysicalDevices(inst, &count, gpus);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600103 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour92400bb2015-03-02 16:38:52 -0700104 ASSERT_GT(count, default_dev_);
105
Tony Barbour59a47322015-06-24 16:06:58 -0600106 err = vkGetPhysicalDeviceExtensionCount(gpus[0], &extCount);
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600107 assert(!err);
108
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600109 for (uint32_t i = 0; i < device_extension_names.size(); i++) {
110 extFound = 0;
111 for (uint32_t j = 0; j < extCount; j++) {
Tony Barbour59a47322015-06-24 16:06:58 -0600112 err = vkGetPhysicalDeviceExtensionProperties(gpus[0], j, &extProp);
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600113 assert(!err);
114 if (!strcmp(device_extension_names[i], extProp.name)) {
115 device_extensions.push_back(extProp);
116 extFound = 1;
117 }
118 }
119 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] << " which is necessary to pass this test";
120 }
121
Tony Barbour92400bb2015-03-02 16:38:52 -0700122 devs_.reserve(count);
123 for (uint32_t i = 0; i < count; i++) {
124 devs_.push_back(new Device(gpus[i]));
125 if (i == default_dev_) {
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600126 devs_[i]->init(device_extensions);
Tony Barbour92400bb2015-03-02 16:38:52 -0700127 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
128 }
129 }
130}
131
Tony Barbour92400bb2015-03-02 16:38:52 -0700132void Environment::TearDown()
133{
134 // destroy devices first
135 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
136 delete *it;
137 devs_.clear();
138
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600139 vkDestroyInstance(inst);
Tony Barbour92400bb2015-03-02 16:38:52 -0700140}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600141} // vk_testing namespace