vengine  0.0.1
3D graphics engine
Loading...
Searching...
No Matches
Device.hpp
Go to the documentation of this file.
1///
2/// @file Device.hpp
3/// @brief This file contains the Device class
4/// @namespace ven
5///
6
7#pragma once
8
9#include <vector>
10#include <stdexcept>
11
13
14namespace ven {
15
17 VkSurfaceCapabilitiesKHR capabilities;
18 std::vector<VkSurfaceFormatKHR> formats;
19 std::vector<VkPresentModeKHR> presentModes;
20 };
21
23 uint32_t graphicsFamily{};
24 uint32_t presentFamily{};
27 [[nodiscard]] bool isComplete() const { return graphicsFamilyHasValue && presentFamilyHasValue; }
28 };
29
30 ///
31 /// @class Device
32 /// @brief Class for device
33 /// @namespace ven
34 ///
35 class Device {
36
37 public:
38
39 #ifdef NDEBUG
40 const bool enableValidationLayers = false;
41 #else
42 const bool enableValidationLayers = true;
43 #endif
44
45 explicit Device(Window &window);
46 ~Device();
47
48 Device(const Device&) = delete;
49 Device& operator=(const Device&) = delete;
50 Device(Device&&) = delete;
51 Device& operator=(Device&&) = delete;
52
53 [[nodiscard]] VkCommandPool getCommandPool() const { return m_commandPool; }
54 [[nodiscard]] VkDevice device() const { return m_device; }
55 [[nodiscard]] VkSurfaceKHR surface() const { return m_surface; }
56 [[nodiscard]] VkQueue graphicsQueue() const { return m_graphicsQueue; }
57 [[nodiscard]] VkQueue presentQueue() const { return m_presentQueue; }
58
60 [[nodiscard]] uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties) const;
62 [[nodiscard]] VkPhysicalDevice getPhysicalDevice() const { return m_physicalDevice; }
63 [[nodiscard]] VkQueue getGraphicsQueue() const { return m_graphicsQueue; }
64 [[nodiscard]] VkFormat findSupportedFormat(const std::vector<VkFormat> &candidates, VkImageTiling tiling, VkFormatFeatureFlags features) const;
65 [[nodiscard]] VkPhysicalDeviceProperties getProperties() const { return m_properties; }
66 [[nodiscard]] VkInstance getInstance() const { return m_instance; }
67
68 // Buffer Helper Functions
69 void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory) const;
70 [[nodiscard]] VkCommandBuffer beginSingleTimeCommands() const;
71 void endSingleTimeCommands(VkCommandBuffer commandBuffer) const;
72 void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size) const;
73 void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height, uint32_t layerCount) const;
74
75 void createImageWithInfo(const VkImageCreateInfo &imageInfo, VkMemoryPropertyFlags properties, VkImage &image, VkDeviceMemory &imageMemory) const;
76 void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels = 1, uint32_t layerCount = 1) const;
77
78 private:
79
80 void createInstance();
83 void pickPhysicalDevice();
85 void createCommandPool();
86
87 // helper functions
88 bool isDeviceSuitable(VkPhysicalDevice device) const;
89 [[nodiscard]] std::vector<const char *> getRequiredExtensions() const;
90 [[nodiscard]] bool checkValidationLayerSupport() const;
91 QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device) const;
92 static void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo);
94 bool checkDeviceExtensionSupport(VkPhysicalDevice device) const;
96
98 VkDebugUtilsMessengerEXT m_debugMessenger;
99 VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
100 VkCommandPool m_commandPool;
101 VkDevice m_device;
102 VkInstance m_instance;
103 VkSurfaceKHR m_surface;
106 VkPhysicalDeviceProperties m_properties;
107
108 const std::vector<const char *> m_validationLayers = {"VK_LAYER_KHRONOS_validation"};
109 const std::vector<const char *> m_deviceExtensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
110
111 }; // class Device
112
113} // namespace ven
This file contains the Window class.
Class for device.
Definition Device.hpp:35
VkInstance getInstance() const
Definition Device.hpp:66
void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels=1, uint32_t layerCount=1) const
Definition device.cpp:504
VkSurfaceKHR m_surface
Definition Device.hpp:103
void endSingleTimeCommands(VkCommandBuffer commandBuffer) const
Definition device.cpp:432
void createCommandPool()
Definition device.cpp:171
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device) const
Definition device.cpp:334
VkPhysicalDevice getPhysicalDevice() const
Definition Device.hpp:62
const bool enableValidationLayers
Definition Device.hpp:42
void createInstance()
Definition device.cpp:55
VkQueue graphicsQueue() const
Definition Device.hpp:56
bool checkValidationLayerSupport() const
Definition device.cpp:227
void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory) const
Definition device.cpp:384
VkDevice m_device
Definition Device.hpp:101
void setupDebugMessenger()
Definition device.cpp:217
VkPhysicalDeviceProperties m_properties
Definition Device.hpp:106
void pickPhysicalDevice()
Definition device.cpp:98
VkCommandPool m_commandPool
Definition Device.hpp:100
VkDevice device() const
Definition Device.hpp:54
QueueFamilyIndices findPhysicalQueueFamilies() const
Definition Device.hpp:61
VkDebugUtilsMessengerEXT m_debugMessenger
Definition Device.hpp:98
bool checkDeviceExtensionSupport(VkPhysicalDevice device) const
Definition device.cpp:290
VkCommandPool getCommandPool() const
Definition Device.hpp:53
void createLogicalDevice()
Definition device.cpp:124
Device(Window &window)
Definition device.cpp:32
Device & operator=(Device &&)=delete
void createImageWithInfo(const VkImageCreateInfo &imageInfo, VkMemoryPropertyFlags properties, VkImage &image, VkDeviceMemory &imageMemory) const
Definition device.cpp:481
VkPhysicalDeviceProperties getProperties() const
Definition Device.hpp:65
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device) const
Definition device.cpp:306
VkCommandBuffer beginSingleTimeCommands() const
Definition device.cpp:413
Device(const Device &)=delete
const std::vector< const char * > m_deviceExtensions
Definition Device.hpp:109
void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size) const
Definition device.cpp:447
VkQueue presentQueue() const
Definition Device.hpp:57
VkQueue m_presentQueue
Definition Device.hpp:105
bool isDeviceSuitable(VkPhysicalDevice device) const
Definition device.cpp:187
VkSurfaceKHR surface() const
Definition Device.hpp:55
VkInstance m_instance
Definition Device.hpp:102
Device & operator=(const Device &)=delete
VkQueue getGraphicsQueue() const
Definition Device.hpp:63
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties) const
Definition device.cpp:369
std::vector< const char * > getRequiredExtensions() const
Definition device.cpp:252
const std::vector< const char * > m_validationLayers
Definition Device.hpp:108
void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height, uint32_t layerCount) const
Definition device.cpp:460
Device(Device &&)=delete
void createSurface()
Definition Device.hpp:82
Window & m_window
Definition Device.hpp:97
static void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo)
Definition device.cpp:204
void hasGlfwRequiredInstanceExtensions() const
Definition device.cpp:267
VkPhysicalDevice m_physicalDevice
Definition Device.hpp:99
VkQueue m_graphicsQueue
Definition Device.hpp:104
VkFormat findSupportedFormat(const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features) const
Definition device.cpp:355
SwapChainSupportDetails getSwapChainSupport() const
Definition Device.hpp:59
Class for window.
Definition Window.hpp:26
void createWindowSurface(VkInstance instance, VkSurfaceKHR *surface) const
Definition window.cpp:27
bool isComplete() const
Definition Device.hpp:27
std::vector< VkPresentModeKHR > presentModes
Definition Device.hpp:19
VkSurfaceCapabilitiesKHR capabilities
Definition Device.hpp:17
std::vector< VkSurfaceFormatKHR > formats
Definition Device.hpp:18