CsPaint  1.0.1
cspaint_device.h
1 
19 #ifndef INCLUDED_CSPAINT_DEVICE_H
20 #define INCLUDED_CSPAINT_DEVICE_H
21 
22 #include <any>
23 #include <future>
24 #include <map>
25 #include <memory>
26 #include <string>
27 #include <vector>
28 #include <vulkan/vulkan.hpp>
29 
30 #include <cspaint_fwd.h>
31 
32 namespace CsPaint
33 {
34 
35 class device : public std::enable_shared_from_this<device>
36 {
37  private:
38  struct private_tag {
39  };
40 
41  public:
42  using handle = std::shared_ptr<device>;
43 
44  device(CsPaint::context_handle context_handle, vk::PhysicalDevice vk_device, private_tag = private_tag{});
45 
46  buffer_handle createBuffer(uint64_t bufferSize, vk::BufferUsageFlagBits usage,
47  vk::SharingMode mode = vk::SharingMode::eExclusive);
48 
49  template <typename T, typename Alloc>
51  createBuffer(const std::vector<T, Alloc> &vec, vk::BufferUsageFlagBits usage, vk::SharingMode = vk::SharingMode::eExclusive);
52 
53  buffer_handle createBuffer(const void *data, uint64_t size, vk::BufferUsageFlagBits usage,
54  vk::SharingMode = vk::SharingMode::eExclusive);
55 
56  image_handle createImage(uint32_t width, uint32_t height, vk::Format imageFormat, vk::ImageTiling imageTiling,
57  vk::ImageUsageFlags imageUsage, vk::MemoryPropertyFlags memoryFlags, vk::ImageAspectFlags aspectFlags);
58 
59  std::future<image_handle> createTexture(const void *data, uint64_t size, uint32_t width, uint32_t height, vk::Format imageFormat,
60  vk::MemoryPropertyFlags memoryFlags, vk::ImageAspectFlags aspectFlags);
61 
62  template <typename T, typename Alloc>
63  std::future<image_handle> createTexture(const std::vector<T, Alloc> data, uint32_t width, uint32_t height,
64  vk::Format imageFormat, vk::MemoryPropertyFlags memoryFlags,
65  vk::ImageAspectFlags aspectFlags);
66 
67  descriptor_pool_handle createDescriptorPool(uint32_t size, vk::DescriptorType, uint32_t count);
68 
69  shader_handle createShader(std::vector<char> input) const;
70  shader_handle createShader(std::vector<uint32_t> input) const;
71 
73 
76 
79 
80  const vk::PhysicalDevice &physicalDevice() const;
81  const vk::Device &graphicsDevice() const;
82 
83  bool hasDeviceMemory();
84 
85  memorypool_handle memoryPool(vk::MemoryPropertyFlags memoryProperties);
86 
87  device(const device &) = delete;
88  void operator=(const device &) = delete;
89 
90 private:
91  std::pair<vk::UniqueDevice, std::vector<vk::Queue>> createLogicalDevice(const vk::QueueFamilyProperties &properties,
92  uint32_t id);
93 
94  context_handle m_context;
95  vk::PhysicalDevice m_device;
96  vk::UniqueDevice m_graphicsDevice;
97  vk::UniqueDevice m_transferDevice;
98  uint32_t m_graphicsCommandQueueFamily;
99  uint32_t m_transferCommandQueueFamily;
100  mutable command_pool_handle m_graphicsCommandPool;
101  mutable command_pool_handle m_transferCommandPool;
102  std::vector<vk::Queue> m_graphicsQueues;
103  std::vector<vk::Queue> m_transferQueues;
104 };
105 }; // namespace CsPaint
106 
107 template <typename T, typename Alloc>
109 CsPaint::device::createBuffer(const std::vector<T, Alloc> &vec, vk::BufferUsageFlagBits usage, vk::SharingMode sharingMode)
110 {
111  return createBuffer(static_cast<const void *>(vec.data()), vec.size() * sizeof(T), usage, sharingMode);
112 }
113 
114 template <typename T, typename Alloc>
115 std::future<CsPaint::image_handle>
116 CsPaint::device::createTexture(const std::vector<T, Alloc> vec, uint32_t width, uint32_t height, vk::Format imageFormat,
117  vk::MemoryPropertyFlags memoryFlags, vk::ImageAspectFlags aspectFlags)
118 {
119  return createTexture(static_cast<const void *>(vec.data()), vec.size() * sizeof(T), width, height, imageFormat, memoryFlags,
120  aspectFlags);
121 }
122 
123 
124 #endif
void operator=(const device &) = delete
std::shared_ptr< memorypool > memorypool_handle
Definition: cspaint_fwd.h:51
queue_handle transferQueue() const
std::shared_ptr< queue > queue_handle
Definition: cspaint_fwd.h:57
const vk::PhysicalDevice & physicalDevice() const
command_pool_handle graphicsCommandPool() const
std::shared_ptr< command_pool > command_pool_handle
Definition: cspaint_fwd.h:33
renderpass_handle createRenderPass() const
Definition: cspaint_buffer.h:26
command_pool_handle transferCommandPool() const
Definition: cspaint_device.h:35
std::shared_ptr< device > handle
Definition: cspaint_device.h:42
const vk::Device & graphicsDevice() const
std::shared_ptr< buffer > buffer_handle
Definition: cspaint_fwd.h:27
device(CsPaint::context_handle context_handle, vk::PhysicalDevice vk_device, private_tag=private_tag{})
std::future< image_handle > createTexture(const void *data, uint64_t size, uint32_t width, uint32_t height, vk::Format imageFormat, vk::MemoryPropertyFlags memoryFlags, vk::ImageAspectFlags aspectFlags)
buffer_handle createBuffer(uint64_t bufferSize, vk::BufferUsageFlagBits usage, vk::SharingMode mode=vk::SharingMode::eExclusive)
memorypool_handle memoryPool(vk::MemoryPropertyFlags memoryProperties)
bool hasDeviceMemory()
shader_handle createShader(std::vector< char > input) const
descriptor_pool_handle createDescriptorPool(uint32_t size, vk::DescriptorType, uint32_t count)
std::shared_ptr< image > image_handle
Definition: cspaint_fwd.h:48
queue_handle graphicsQueue() const
image_handle createImage(uint32_t width, uint32_t height, vk::Format imageFormat, vk::ImageTiling imageTiling, vk::ImageUsageFlags imageUsage, vk::MemoryPropertyFlags memoryFlags, vk::ImageAspectFlags aspectFlags)
std::shared_ptr< context > context_handle
Definition: cspaint_fwd.h:36
std::shared_ptr< descriptor_pool > descriptor_pool_handle
Definition: cspaint_fwd.h:42
std::shared_ptr< renderpass > renderpass_handle
Definition: cspaint_fwd.h:60
std::shared_ptr< shader > shader_handle
Definition: cspaint_fwd.h:63