Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
VulkanDevice.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#ifdef CORRELATION_USE_VULKAN
12#include <vulkan/vulkan.h>
13#endif
14
15#include <cstdint>
16#include <string>
17
19
20#ifdef CORRELATION_USE_VULKAN
21
26class VulkanDevice {
27public:
28 VulkanDevice() noexcept = default;
29 ~VulkanDevice() noexcept { destroy(); }
30
31 VulkanDevice(const VulkanDevice &) = delete;
32 VulkanDevice &operator=(const VulkanDevice &) = delete;
33
34 VulkanDevice(VulkanDevice &&other) noexcept { moveFrom(other); }
35 VulkanDevice &operator=(VulkanDevice &&other) noexcept {
36 if (this != &other) {
37 destroy();
38 moveFrom(other);
39 }
40 return *this;
41 }
42
47 [[nodiscard]] bool initialize();
48
52 void destroy() noexcept;
53
58 [[nodiscard]] VkCommandBuffer beginSingleTimeCommands();
59
64 void endSingleTimeCommands(VkCommandBuffer command_buffer);
65
66 [[nodiscard]] VkInstance instance() const noexcept { return instance_; }
67 [[nodiscard]] VkPhysicalDevice physicalDevice() const noexcept { return physical_device_; }
68 [[nodiscard]] VkDevice device() const noexcept { return device_; }
69 [[nodiscard]] VkQueue graphicsQueue() const noexcept { return graphics_queue_; }
70 [[nodiscard]] uint32_t queueFamilyIndex() const noexcept { return queue_family_index_; }
71 [[nodiscard]] VkCommandPool commandPool() const noexcept { return command_pool_; }
72 [[nodiscard]] bool isValid() const noexcept { return device_ != VK_NULL_HANDLE; }
73 [[nodiscard]] std::string physicalDeviceName() const;
74
75private:
76 void moveFrom(VulkanDevice &other) noexcept;
77 [[nodiscard]] bool createInstance();
78 [[nodiscard]] bool pickPhysicalDevice();
79 [[nodiscard]] bool createLogicalDevice();
80 [[nodiscard]] bool createCommandPool();
81
82 VkInstance instance_{VK_NULL_HANDLE};
83 VkPhysicalDevice physical_device_{VK_NULL_HANDLE};
84 VkDevice device_{VK_NULL_HANDLE};
85 VkQueue graphics_queue_{VK_NULL_HANDLE};
86 uint32_t queue_family_index_{0};
87 VkCommandPool command_pool_{VK_NULL_HANDLE};
88};
89
90#endif // CORRELATION_USE_VULKAN
91
92} // namespace correlation::render3d::vulkan
Definition VulkanComputeService.hpp:24