forked from LunarG/VulkanSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice.cpp
More file actions
92 lines (75 loc) · 2.73 KB
/
Copy pathdevice.cpp
File metadata and controls
92 lines (75 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Vulkan Samples
*
* Copyright (C) 2015-2016 Valve Corporation
* Copyright (C) 2015-2016 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
VULKAN_SAMPLE_SHORT_DESCRIPTION
create and destroy a Vulkan physical device
*/
/* This is part of the draw cube progression */
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <util_init.hpp>
int sample_main(int argc, char *argv[]) {
struct sample_info info = {};
init_global_layer_properties(info);
init_instance(info, "vulkansamples_device");
init_enumerate_device(info);
/* VULKAN_KEY_START */
VkDeviceQueueCreateInfo queue_info = {};
vkGetPhysicalDeviceQueueFamilyProperties(info.gpus[0], &info.queue_count,
NULL);
assert(info.queue_count >= 1);
info.queue_props.resize(info.queue_count);
vkGetPhysicalDeviceQueueFamilyProperties(info.gpus[0], &info.queue_count,
info.queue_props.data());
assert(info.queue_count >= 1);
bool found = false;
for (unsigned int i = 0; i < info.queue_count; i++) {
if (info.queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
queue_info.queueFamilyIndex = i;
found = true;
break;
}
}
assert(found);
assert(info.queue_count >= 1);
float queue_priorities[1] = {0.0};
queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queue_info.pNext = NULL;
queue_info.queueCount = 1;
queue_info.pQueuePriorities = queue_priorities;
VkDeviceCreateInfo device_info = {};
device_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
device_info.pNext = NULL;
device_info.queueCreateInfoCount = 1;
device_info.pQueueCreateInfos = &queue_info;
device_info.enabledExtensionCount = 0;
device_info.ppEnabledExtensionNames = NULL;
device_info.enabledLayerCount = 0;
device_info.ppEnabledLayerNames = NULL;
device_info.pEnabledFeatures = NULL;
VkDevice device;
VkResult U_ASSERT_ONLY res =
vkCreateDevice(info.gpus[0], &device_info, NULL, &device);
assert(res == VK_SUCCESS);
vkDestroyDevice(device, NULL);
/* VULKAN_KEY_END */
destroy_instance(info);
return 0;
}