blob: 0e6d1fa60ab034b05c830b42daf68a3cac1e35cd [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);
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060070
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060071 bool32_t extFound;
72
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060073 instance_extensions = vk_testing::GetGlobalExtensions();
74
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060075 for (uint32_t i = 0; i < instance_extension_names.size(); i++) {
76 extFound = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060077 for (uint32_t j = 0; j < instance_extensions.size(); j++) {
78 if (!strcmp(instance_extension_names[i], instance_extensions[i].extName)) {
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -060079 extFound = 1;
80 }
81 }
82 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] << " which is necessary to pass this test";
83 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060084 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburnb317fad2015-04-04 14:52:07 -060085 inst_info.pNext = NULL;
86 inst_info.pAppInfo = &app_;
87 inst_info.pAllocCb = NULL;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060088 inst_info.extensionCount = instance_extension_names.size();
89 inst_info.ppEnabledExtensionNames = (instance_extension_names.size()) ? &instance_extension_names[0] : NULL;
90 inst_info.layerCount = 0;
91 inst_info.ppEnabledLayerNames = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060092 err = vkCreateInstance(&inst_info, &inst);
93 ASSERT_EQ(VK_SUCCESS, err);
Jon Ashburn83a64252015-04-15 11:31:12 -060094 err = vkEnumeratePhysicalDevices(inst, &count, NULL);
95 ASSERT_EQ(VK_SUCCESS, err);
96 ASSERT_LE(count, ARRAY_SIZE(gpus));
97 err = vkEnumeratePhysicalDevices(inst, &count, gpus);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060098 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour92400bb2015-03-02 16:38:52 -070099 ASSERT_GT(count, default_dev_);
100
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600101 vk_testing::PhysicalGpu phys_dev(gpus[0]);
102 device_extensions = phys_dev.extensions();
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600103
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600104 for (uint32_t i = 0; i < device_extension_names.size(); i++) {
105 extFound = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600106 for (uint32_t j = 0; j < device_extensions.size(); j++) {
107 if (!strcmp(device_extension_names[i], device_extensions[i].extName)) {
Courtney Goeltzenleuchter553b9cb2015-06-24 15:03:26 -0600108 extFound = 1;
109 }
110 }
111 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] << " which is necessary to pass this test";
112 }
113
Tony Barbour92400bb2015-03-02 16:38:52 -0700114 devs_.reserve(count);
115 for (uint32_t i = 0; i < count; i++) {
116 devs_.push_back(new Device(gpus[i]));
117 if (i == default_dev_) {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600118 devs_[i]->init(device_extension_names);
Tony Barbour92400bb2015-03-02 16:38:52 -0700119 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
120 }
121 }
122}
123
Tony Barbour92400bb2015-03-02 16:38:52 -0700124void Environment::TearDown()
125{
126 // destroy devices first
127 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
128 delete *it;
129 devs_.clear();
130
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600131 vkDestroyInstance(inst);
Tony Barbour92400bb2015-03-02 16:38:52 -0700132}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600133} // vk_testing namespace