blob: 85da9149018edc4ea704cf6f2651d2681fcaba8f [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 Wu5b66aa52015-04-16 22:02:10 +080010 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;
Courtney Goeltzenleuchterf194c542015-06-23 08:54:19 -060018 app_.pNext = NULL;
Tony Barbour34888cf2015-03-02 16:38:52 -070019}
20
21bool Environment::parse_args(int argc, char **argv)
22{
23 int i;
24
25 for (i = 1; i < argc; i++) {
26#define ARG(name) (strcmp(argv[i], name) == 0)
27#define ARG_P(name) (i < argc - 1 && ARG(name))
28 if (ARG_P("--gpu")) {
29 default_dev_ = atoi(argv[++i]);
30 } else {
31 break;
32 }
33#undef ARG
34#undef ARG_P
35 }
36
37 if (i < argc) {
38 std::cout <<
39 "invalid argument: " << argv[i] << "\n\n" <<
40 "Usage: " << argv[0] << " <options>\n\n" <<
41 "Options:\n"
42 " --gpu <n> Use GPU<n> as the default GPU\n";
43
44 return false;
45 }
46
47 return true;
48}
49
50void Environment::SetUp()
51{
52
53 uint32_t count;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060054 VkResult err;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060055 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060056 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -060057 inst_info.pNext = NULL;
58 inst_info.pAppInfo = &app_;
59 inst_info.pAllocCb = NULL;
60 inst_info.extensionCount = 0;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060061 inst_info.pEnabledExtensions = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060062 err = vkCreateInstance(&inst_info, &inst);
63 ASSERT_EQ(VK_SUCCESS, err);
Jon Ashburn07b309a2015-04-15 11:31:12 -060064 err = vkEnumeratePhysicalDevices(inst, &count, NULL);
65 ASSERT_EQ(VK_SUCCESS, err);
66 ASSERT_LE(count, ARRAY_SIZE(gpus));
67 err = vkEnumeratePhysicalDevices(inst, &count, gpus);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060068 ASSERT_EQ(VK_SUCCESS, err);
Tony Barbour34888cf2015-03-02 16:38:52 -070069 ASSERT_GT(count, default_dev_);
70
71 devs_.reserve(count);
72 for (uint32_t i = 0; i < count; i++) {
73 devs_.push_back(new Device(gpus[i]));
74 if (i == default_dev_) {
75 devs_[i]->init();
76 ASSERT_NE(true, devs_[i]->graphics_queues().empty());
77 }
78 }
79}
80
Tony Barbour34888cf2015-03-02 16:38:52 -070081void Environment::TearDown()
82{
83 // destroy devices first
84 for (std::vector<Device *>::iterator it = devs_.begin(); it != devs_.end(); it++)
85 delete *it;
86 devs_.clear();
87
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060088 vkDestroyInstance(inst);
Tony Barbour34888cf2015-03-02 16:38:52 -070089}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060090} // vk_testing namespace