HatchitGraphics
ht_vkswapchain.h
1 
25 #pragma once
26 
27 #include <ht_swapchain.h>
28 
29 #include <ht_vkpipeline.h>
30 #include <ht_vkrendertarget.h>
31 #include <ht_vkqueue.h>
32 
33 namespace Hatchit {
34 
35  namespace Graphics {
36 
37  namespace Vulkan {
38 
39  struct SwapchainBuffer {
40  VkImage image;
41  VkCommandBuffer command;
42  VkImageView view;
43  };
44 
45  struct DepthBuffer {
46  VkFormat format;
47  VkImage image;
48  VkMemoryAllocateInfo memAllocInfo;
49  VkDeviceMemory memory;
50  VkImageView view;
51  };
52 
53  class VKRenderer;
54 
55  class HT_API VKSwapChain : public SwapChain
56  {
57  public:
58  VKSwapChain(const RendererParams& rendererParams, VKDevice* device, VKQueue* queue);
59  ~VKSwapChain();
60 
61  void VClear(float* color) override;
62  bool VInitialize(uint32_t width, uint32_t height) override;
63  void VResize(uint32_t width, uint32_t height) override;
64  void VExecute(std::vector<RenderPassHandle> renderPasses) override;
65  void VSetInput(RenderPassHandle handle) override;
66  void VPresent() override;
67 
68  const VkCommandBuffer& GetVKCurrentCommand() const;
69  const VkSurfaceKHR& GetVKSurface() const;
70  const uint32_t& GetVKGraphicsQueueIndex() const;
71 
72  const VkClearValue& GetVKClearColor() const;
73 
74  bool BuildSwapchainCommands(VkClearValue clearColor);
75 
76  VkResult VKGetNextImage(VkSemaphore presentSemaphore);
77  bool VKPostPresentBarrier(const VkQueue& queue);
78  bool VKPrePresentBarrier(const VkQueue& queue);
79  VkResult VKPresent(const VkQueue& queue, const VkSemaphore& renderSemaphore);
80 
81  void VKSetIncomingRenderPass(VKRenderPass* renderPass);
82 
83  private:
84  VkInstance m_instance;
85  VkPhysicalDevice m_gpu;
86  VkDevice m_device;
87  VkQueue m_queue;
88  VkCommandPool m_commandPool;
89  VkDescriptorPool m_descriptorPool;
90 
91  VkPipelineStageFlags m_submitStages;
92  VkSemaphore m_presentSemaphore;
93  VkSemaphore m_renderSemaphore;
94  VkSubmitInfo m_submitInfo;
95 
96  bool m_dirty;
97 
98  VkSurfaceKHR m_surface;
99  VkPhysicalDeviceProperties m_gpuProps;
100  std::vector<VkQueueFamilyProperties> m_queueProps;
101  uint32_t m_graphicsQueueNodeIndex;
102 
103  VkFormat m_preferredColorFormat;
104  VkFormat m_preferredDepthFormat;
105  VkColorSpaceKHR m_colorSpace;
106  VkClearValue m_clearColor;
107 
108  //Void pointers because their contents are dependant on the platform
109  void* m_window;
110  void* m_display;
111 
112  VkRenderPass m_renderPass;
113  PipelineHandle m_pipelineHandle; //Hold this so it doesn't deref and destroy the pipeline
114  VKPipeline* m_pipeline;
115  VkDescriptorSet m_descriptorSet;
116 
117  std::vector<VkCommandBuffer> m_postPresentCommands;
118  std::vector<VkCommandBuffer> m_prePresentCommands;
119 
120  VkSwapchainKHR m_swapchain;
121  std::vector<SwapchainBuffer> m_swapchainBuffers;
122  std::vector<VkFramebuffer> m_framebuffers;
123  DepthBuffer m_depthBuffer;
124 
125  UniformBlock_vk m_vertexBuffer;
126  std::vector<Texture_vk> m_inputTextures;
127 
128  bool vkPrepare();
129  bool vkPrepareResources();
130 
131  bool createAllocatorPools();
132 
133  bool prepareSurface();
134 
135  bool getQueueProperties();
136 
137  bool findSutibleQueue();
138 
139  bool getPreferredFormats();
140 
141  //Prepare the swapchain base
142  bool prepareSwapchain(VkFormat preferredColorFormat, VkColorSpaceKHR colorSpace,
143  std::vector<VkPresentModeKHR> presentModes, VkSurfaceCapabilitiesKHR surfaceCapabilities, VkExtent2D surfaceExtents);
144 
145  //Prepare the swapchain depth buffer
146  bool prepareSwapchainDepth(const VkFormat& preferredDepthFormat, VkExtent2D extent);
147 
148  //Prepare the internal render pass
149  bool prepareRenderPass();
150 
151  //Prepare the framebuffers for the swapchain images
152  bool prepareFramebuffers(VkExtent2D extents);
153 
154  //Allocate the command buffers
155  bool allocateCommandBuffers();
156 
157  bool submitBarrier(const VkQueue& queue, const VkCommandBuffer& command);
158 
159  //Helpers for destruction / recreation
160  void destroySurface();
161  void destroyPipeline();
162  void destroyDepth();
163  void destroyFramebuffers();
164  void destroySwapchainBuffers();
165  void destroyRenderPass();
166  void destroySwapchain();
167 
168  };
169  }
170  }
171 }
Definition: ht_vkswapchain.h:39
Definition: ht_vkrenderer.h:34
Definition: ht_vkqueue.h:39
Definition: ht_vkpipeline.h:42
Definition: ht_vkswapchain.h:55
Definition: ht_vkswapchain.h:45
Definition: ht_renderer.h:69
Hatchit Engine Copyright(c) 2015-2016 Third-Degree.
Definition: ht_color.h:19
Definition: ht_swapchain.h:38
Definition: ht_vkrenderpass.h:41
Vulkan device wrapper.
Definition: ht_vkdevice.h:29