-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVulkanDevice.h
More file actions
84 lines (65 loc) · 2.93 KB
/
VulkanDevice.h
File metadata and controls
84 lines (65 loc) · 2.93 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
#pragma once
#include <cassert>
#include <iostream>
#include <optional>
#include <set>
#include <stdexcept>
#include <vector>
#include <vulkan/vulkan.h>
struct VulkanDevice
{
// Physical device representation
VkPhysicalDevice physicalDevice{};
// Logical device representation (application's interface of physical device)
VkDevice logicalDevice{};
// Properties of physical device including limits that the application can check against
VkPhysicalDeviceProperties properties{};
// Memory types and heaps of the physical device
VkPhysicalDeviceMemoryProperties memProperties{};
// Max usable samples
VkSampleCountFlagBits msaaSamples{};
// Supported depth format for physical device
VkFormat depthFormat{};
// Default command pool for the graphics queue family index
VkCommandPool commandPool{VK_NULL_HANDLE};
// Command buffers will be destroyed when commandPool is destroyed
std::vector<VkCommandBuffer> commandBuffers{};
struct
{
// Stores index of queue family
// Index is possible to be the different/same queue family for different kinds of operations
std::optional<uint32_t> graphics;
std::optional<uint32_t> present;
std::optional<uint32_t> compute;
std::optional<uint32_t> transfer;
bool isComplete()
{
// TODO: Can change to prefer physical device that supports drawing and
// presentation in the same queue for improved performance.
return graphics.has_value() && present.has_value() && compute.has_value() && transfer.has_value();
}
void reset()
{
graphics.reset();
present.reset();
compute.reset();
transfer.reset();
}
} queueFamilyIndices;
VkPhysicalDevice pickPhysicalDevice(VkInstance instance, VkSurfaceKHR surface, const std::vector<const char *> &enabledExtensions, VkPhysicalDeviceFeatures enabledFeatures);
VkDevice createLogicalDevice(bool enableValidationLayers, const std::vector<const char *> &validationLayers, const std::vector<const char *> &enabledExtensions, VkPhysicalDeviceFeatures enabledFeatures, void *pNextChain);
bool checkDeviceExtensionSupport(const std::vector<const char *> &enabledExtensions);
bool checkDeviceFeaturesSupport(VkPhysicalDeviceFeatures enabledFeatures);
void queryQueueFamilyIndices(VkSurfaceKHR surface);
VkSampleCountFlagBits getMaxUsableSampleCount();
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
VkFormat findSupportedFormat(const std::vector<VkFormat> &candidates, VkImageTiling tiling, VkFormatFeatureFlags features);
VkFormat findDepthFormat();
VkCommandBuffer beginSingleTimeCommands();
void endSingleTimeCommands(VkCommandBuffer commandBuffer, VkQueue queue);
void createCommandPool();
void createCommandBuffers(const uint32_t maxFramesInFlight);
void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory);
void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size, VkQueue queue);
void cleanup();
};