blob: 03beb1249445b85866d452cf24fbddffb0a21807 [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"
4
5#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
6
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06007namespace vk_testing {
Tony Barbour34888cf2015-03-02 16:38:52 -07008
9Environment::Environment() :
Chia-I Wu053e6112015-04-09 14:08:10 +080010 m_connection(NULL), default_dev_(0)
Tony Barbour34888cf2015-03-02 16:38:52 -070011{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060012 app_.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
13 app_.pAppName = "vk_testing";
Tony Barbour34888cf2015-03-02 16:38:52 -070014 app_.appVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060015 app_.pEngineName = "vk_testing";
Tony Barbour34888cf2015-03-02 16:38:52 -070016 app_.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060017 app_.apiVersion = VK_API_VERSION;
Tony Barbour34888cf2015-03-02 16:38:52 -070018}
19
20bool Environment::parse_args(int argc, char **argv)
21{
22 int i;
23
24 for (i = 1; i < argc; i++) {
25#define ARG(name) (strcmp(argv[i], name) == 0)
26#define ARG_P(name) (i < argc - 1 && ARG(name))
27 if (ARG_P("--gpu")) {
28 default_dev_ = atoi(argv[++i]);
29 } else {
30 break;
31 }
32#undef ARG
33#undef ARG_P
34 }
35
36 if (i < argc) {
37 std::cout <<
38 "invalid argument: " << argv[i] << "\n\n" <<
39 "Usage: " << argv[0] << " <options>\n\n" <<
40 "Options:\n"
41 " --gpu <n> Use GPU<n> as the default GPU\n";
42
43 return false;
44 }
45
46 return true;
47}
48
49void Environment::SetUp()
50{
51
52 uint32_t count;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060053 VkResult err;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060054 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060055 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -060056 inst_info.pNext = NULL;
57 inst_info.pAppInfo = &app_;
58 inst_info.pAllocCb = NULL;
59 inst_info.extensionCount = 0;
60 inst_info.ppEnabledExtensionNames = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060061 err = vkCreateInstance(&inst_info, &inst);
62 ASSERT_EQ(VK_SUCCESS, err);
Jon Ashburn07b309a2015-04-15 11:31:12 -060063 err = vkEnumeratePhysicalDevices(inst, &count, NULL);
64 ASSERT_EQ(VK_SUCCESS, err);
65 ASSERT_LE(count, ARRAY_SIZE(gpus));
66 err = vkEnumeratePhysicalDevices(inst, &count, gpus);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060067 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour34888cf2015-03-02 16:38:52 -070068 ASSERT_GT(count, default_dev_);
69
70 devs_.reserve(count);
71 for (uint32_t i = 0; i < count; i++) {
72 devs_.push_back(new Device(gpus[i]));
73 if (i == default_dev_) {
74 devs_[i]->init();
75 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
76 }
77 }
78}
79
80void Environment::X11SetUp()
81{
82
83 uint32_t count;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060084 VkResult err;
Tony Barbour34888cf2015-03-02 16:38:52 -070085 const xcb_setup_t *setup;
86 xcb_screen_iterator_t iter;
87 int scr;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060088 VkInstanceCreateInfo instInfo = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060089 instInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -060090 instInfo.pNext = NULL;
91 instInfo.pAppInfo = &app_;
92 instInfo.pAllocCb = NULL;
93 instInfo.extensionCount = 0;
94 instInfo.ppEnabledExtensionNames = NULL;
Tony Barbour34888cf2015-03-02 16:38:52 -070095
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060096 err = vkCreateInstance(&instInfo, &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
105 m_connection = xcb_connect(NULL, &scr);
106
107 setup = xcb_get_setup(m_connection);
108 iter = xcb_setup_roots_iterator(setup);
109 while (scr-- > 0)
110 xcb_screen_next(&iter);
111
112 m_screen = iter.data;
113
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600114 VK_WSI_X11_CONNECTION_INFO connection_info = {};
Tony Barbour901f3bc2015-04-01 17:10:07 -0600115 connection_info.pConnection = m_connection;
116 connection_info.root = m_screen->root;
117 connection_info.provider = 0;
Tony Barbour34888cf2015-03-02 16:38:52 -0700118
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600119 err = vkWsiX11AssociateConnection(gpus[0], &connection_info);
Tony Barbour34888cf2015-03-02 16:38:52 -0700120 assert(!err);
121
122
123 devs_.reserve(count);
124 for (uint32_t i = 0; i < count; i++) {
125 devs_.push_back(new Device(gpus[i]));
126 if (i == default_dev_) {
127 devs_[i]->init();
128 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
129 }
130 }
131}
132
133void Environment::TearDown()
134{
Chia-I Wu053e6112015-04-09 14:08:10 +0800135 if (m_connection)
136 xcb_disconnect(m_connection);
137
Tony Barbour34888cf2015-03-02 16:38:52 -0700138 // 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