blob: 7ba7f6929bfa703b5c55f3cfcda5ab3db065d8f9 [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"
4
5#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
6
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007namespace vk_testing {
Tony Barbour92400bb2015-03-02 16:38:52 -07008
9Environment::Environment() :
Chia-I Wuf8693382015-04-16 22:02:10 +080010 default_dev_(0)
Tony Barbour92400bb2015-03-02 16:38:52 -070011{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060012 app_.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
13 app_.pAppName = "vk_testing";
Tony Barbour92400bb2015-03-02 16:38:52 -070014 app_.appVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060015 app_.pEngineName = "vk_testing";
Tony Barbour92400bb2015-03-02 16:38:52 -070016 app_.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060017 app_.apiVersion = VK_API_VERSION;
Tony Barbour92400bb2015-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 Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060053 VkResult err;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -060054 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060055 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburnb317fad2015-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;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060060 inst_info.pEnabledExtensions = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060061 err = vkCreateInstance(&inst_info, &inst);
62 ASSERT_EQ(VK_SUCCESS, err);
Jon Ashburn83a64252015-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060067 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour92400bb2015-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
Tony Barbour92400bb2015-03-02 16:38:52 -070080void Environment::TearDown()
81{
82 // destroy devices first
83 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
84 delete *it;
85 devs_.clear();
86
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060087 vkDestroyInstance(inst);
Tony Barbour92400bb2015-03-02 16:38:52 -070088}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060089} // vk_testing namespace