blob: 4afd65fd4f9747a15a76641ae9993a03ea1363e6 [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);
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060070
71 uint32_t extCount = 0;
Tony Barbour426b9052015-06-24 16:06:58 -060072 err = vkGetGlobalExtensionCount(&extCount);
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060073 assert(!err);
74
75 VkExtensionProperties extProp;
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060076 bool32_t extFound;
77
78 for (uint32_t i = 0; i < instance_extension_names.size(); i++) {
79 extFound = 0;
80 for (uint32_t j = 0; j < extCount; j++) {
Tony Barbour426b9052015-06-24 16:06:58 -060081 err = vkGetGlobalExtensionProperties(j, &extProp);
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060082 assert(!err);
83 if (!strcmp(instance_extension_names[i], extProp.name)) {
84 instance_extensions.push_back(extProp);
85 extFound = 1;
86 }
87 }
88 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] << " which is necessary to pass this test";
89 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060090 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -060091 inst_info.pNext = NULL;
92 inst_info.pAppInfo = &app_;
93 inst_info.pAllocCb = NULL;
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -060094 inst_info.extensionCount = instance_extensions.size();
95 inst_info.pEnabledExtensions = (instance_extensions.size()) ? &instance_extensions[0] : NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060096 err = vkCreateInstance(&inst_info, &inst);
97 ASSERT_EQ(VK_SUCCESS, err);
Jon Ashburn07b309a2015-04-15 11:31:12 -060098 err = vkEnumeratePhysicalDevices(inst, &count, NULL);
99 ASSERT_EQ(VK_SUCCESS, err);
100 ASSERT_LE(count, ARRAY_SIZE(gpus));
101 err = vkEnumeratePhysicalDevices(inst, &count, gpus);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600102 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour34888cf2015-03-02 16:38:52 -0700103 ASSERT_GT(count, default_dev_);
104
Tony Barbour426b9052015-06-24 16:06:58 -0600105 err = vkGetPhysicalDeviceExtensionCount(gpus[0], &extCount);
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -0600106 assert(!err);
107
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -0600108 for (uint32_t i = 0; i < device_extension_names.size(); i++) {
109 extFound = 0;
110 for (uint32_t j = 0; j < extCount; j++) {
Tony Barbour426b9052015-06-24 16:06:58 -0600111 err = vkGetPhysicalDeviceExtensionProperties(gpus[0], j, &extProp);
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -0600112 assert(!err);
113 if (!strcmp(device_extension_names[i], extProp.name)) {
114 device_extensions.push_back(extProp);
115 extFound = 1;
116 }
117 }
118 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] << " which is necessary to pass this test";
119 }
120
Tony Barbour34888cf2015-03-02 16:38:52 -0700121 devs_.reserve(count);
122 for (uint32_t i = 0; i < count; i++) {
123 devs_.push_back(new Device(gpus[i]));
124 if (i == default_dev_) {
Courtney Goeltzenleuchter5733f6e2015-06-24 15:03:26 -0600125 devs_[i]->init(device_extensions);
Tony Barbour34888cf2015-03-02 16:38:52 -0700126 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
127 }
128 }
129}
130
Tony Barbour34888cf2015-03-02 16:38:52 -0700131void Environment::TearDown()
132{
133 // destroy devices first
134 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
135 delete *it;
136 devs_.clear();
137
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600138 vkDestroyInstance(inst);
Tony Barbour34888cf2015-03-02 16:38:52 -0700139}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600140} // vk_testing namespace