-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice.hpp
167 lines (107 loc) · 3.69 KB
/
device.hpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#pragma once
#include "window.hpp" // INNER => Window class for window management
#include<vector>
using namespace std;
namespace Vulketa
{
struct swapChainSupportDetails
{
VkSurfaceCapabilitiesKHR capabilites;
vector<VkSurfaceFormatKHR> formats;
vector<VkPresentModeKHR> presentModes;
};
struct queueFamilyIndices
{
uint32_t graphicsFamily;
uint32_t presentFamily;
bool graphicsFamilyHasValue = false;
bool presentFamilyHasValue = false;
bool isComplete()
{
return graphicsFamilyHasValue && presentFamilyHasValue;
}
};
class Device
{
public:
#ifdef VULEKETA_DEGUB
const bool enable_validation_layers = false;
#else
const bool enable_validation_layers = true;
#endif
VkPhysicalDeviceProperties device_properties;
// Operators
Device(const Device &) = delete;
void operator=(const Device &) = delete;
Device(Device &&) = delete;
Device &operator=(Device &&) = delete;
// Getters
VkCommandPool get_command_pool()
{
return command_pool;
}
VkDevice get_device()
{
return device;
}
VkSurfaceKHR get_surface()
{
return surface;
}
VkQueue get_graphics_queue()
{
return graphics_queue;
}
VkQueue get_present_queue()
{
return present_queue;
}
// Gettters for queues families
swapChainSupportDetails get_swap_chain_support()
{
return query_swap_chain_support(physical_device);
}
queueFamilyIndices find_physical_queue_family()
{
return find_queue_families(physical_device);
}
uint32_t find_mem_type(uint32_t type_filder, VkMemoryPropertyFlags properties);
VkFormat find_supported_format( const vector<VkFormat> &candidates, VkImageTiling tiling, VkFormatFeatureFlags features);
void create_buffer( VkDevice size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &buffer_memory);
void copy_buffer(VkBuffer src_buffer, VkBuffer tartget_buffer, VkDeviceSize size);
void copy_buffer_to_image(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height, uint32_t layer_count);
void create_info_and_image( const VkImageCreateInfo &image_info, VkMemoryPropertyFlags properties, VkDeviceMemory &image_memory);
private:
VkInstance instance;
VkPhysicalDevice physical_device = VK_NULL_HANDLE;
VkDebugUtilsMessageSeverityFlagsEXT severity_flags = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
VkDebugUtilsMessageTypeFlagsEXT message_flags = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
VkDebugUtilsMessengerEXT debugger;
// Properties for device management
Window& window;
VkCommandPool command_pool;
VkDevice device;
VkSurfaceKHR surface;
VkQueue graphics_queue;
VkQueue present_queue;
const vector<const char*> validation_layers = { "VK_LAYER_KHRONOS_validation" };
const vector<const char*> deviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
// Queries for queues & swap chains
swapChainSupportDetails query_swap_chain_support(VkPhysicalDevice device);
queueFamilyIndices find_queue_families(VkPhysicalDevice device);
bool check_validation_layer_support();
bool check_device_extension_support(VkPhysicalDevice device);
vector<const char*> get_required_extensions();
// Configuration
void set_up_debugger();
void create_instance();
void create_surface();
void pick_physical_device();
bool is_suitable_device(VkPhysicalDevice device);
void create_command_pool();
void create_logical_device();
void has_glfw_required_instance_extensions();
void populate_debug_messenger(VkDebugUtilsMessengerCreateInfoEXT &creation_info);
};
}