blob: 5d3a580086fed8d8eff38c3d0d94f1cbda406d52 [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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060053 VK_RESULT err;
54 VK_INSTANCE_CREATE_INFO inst_info = {};
55 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);
63 err = vkEnumerateGpus(inst, ARRAY_SIZE(gpus), &count, gpus);
64 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour34888cf2015-03-02 16:38:52 -070065 ASSERT_GT(count, default_dev_);
66
67 devs_.reserve(count);
68 for (uint32_t i = 0; i < count; i++) {
69 devs_.push_back(new Device(gpus[i]));
70 if (i == default_dev_) {
71 devs_[i]->init();
72 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
73 }
74 }
75}
76
77void Environment::X11SetUp()
78{
79
80 uint32_t count;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060081 VK_RESULT err;
Tony Barbour34888cf2015-03-02 16:38:52 -070082 const xcb_setup_t *setup;
83 xcb_screen_iterator_t iter;
84 int scr;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060085 VK_INSTANCE_CREATE_INFO instInfo = {};
86 instInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -060087 instInfo.pNext = NULL;
88 instInfo.pAppInfo = &app_;
89 instInfo.pAllocCb = NULL;
90 instInfo.extensionCount = 0;
91 instInfo.ppEnabledExtensionNames = NULL;
Tony Barbour34888cf2015-03-02 16:38:52 -070092
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060093 err = vkCreateInstance(&instInfo, &inst);
94 ASSERT_EQ(VK_SUCCESS, err);
95 err = vkEnumerateGpus(inst, ARRAY_SIZE(gpus), &count, gpus);
96 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour34888cf2015-03-02 16:38:52 -070097 ASSERT_GT(count, default_dev_);
98
99 m_connection = xcb_connect(NULL, &scr);
100
101 setup = xcb_get_setup(m_connection);
102 iter = xcb_setup_roots_iterator(setup);
103 while (scr-- > 0)
104 xcb_screen_next(&iter);
105
106 m_screen = iter.data;
107
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600108 VK_WSI_X11_CONNECTION_INFO connection_info = {};
Tony Barbour901f3bc2015-04-01 17:10:07 -0600109 connection_info.pConnection = m_connection;
110 connection_info.root = m_screen->root;
111 connection_info.provider = 0;
Tony Barbour34888cf2015-03-02 16:38:52 -0700112
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600113 err = vkWsiX11AssociateConnection(gpus[0], &connection_info);
Tony Barbour34888cf2015-03-02 16:38:52 -0700114 assert(!err);
115
116
117 devs_.reserve(count);
118 for (uint32_t i = 0; i < count; i++) {
119 devs_.push_back(new Device(gpus[i]));
120 if (i == default_dev_) {
121 devs_[i]->init();
122 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
123 }
124 }
125}
126
127void Environment::TearDown()
128{
Chia-I Wu053e6112015-04-09 14:08:10 +0800129 if (m_connection)
130 xcb_disconnect(m_connection);
131
Tony Barbour34888cf2015-03-02 16:38:52 -0700132 // destroy devices first
133 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
134 delete *it;
135 devs_.clear();
136
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600137 vkDestroyInstance(inst);
Tony Barbour34888cf2015-03-02 16:38:52 -0700138}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600139} // vk_testing namespace