HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
gfx_surface_vulkan.hpp
1// Copyright Take Vos 2019-2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "gfx_surface.hpp"
8#include "gfx_queue_vulkan.hpp"
9#include <vulkan/vulkan.hpp>
10#include <vk_mem_alloc.h>
11#include <optional>
12
13namespace hi::inline v1 {
14class gfx_device_vulkan;
15namespace pipeline_image {
16class pipeline_image;
17}
18namespace pipeline_box {
19class pipeline_box;
20}
21namespace pipeline_SDF {
22class pipeline_SDF;
23}
24namespace pipeline_tone_mapper {
25class pipeline_tone_mapper;
26}
27
29 vk::Image image;
30 vk::ImageView image_view;
31 vk::Framebuffer frame_buffer;
32 aarectangle redraw_rectangle;
33 bool layout_is_present = false;
34};
35
36class gfx_surface_vulkan final : public gfx_surface {
37public:
38 using super = gfx_surface;
39
40 vk::SurfaceKHR intrinsic;
41
42 vk::SwapchainKHR swapchain;
43
44 static constexpr uint32_t defaultNumberOfSwapchainImages = 2;
45
46 uint32_t nrSwapchainImages;
47 vk::Extent2D swapchainImageExtent;
48 vk::SurfaceFormatKHR swapchainImageFormat;
49 std::vector<swapchain_image_info> swapchain_image_infos;
50
51 // static const vk::Format depthImageFormat = vk::Format::eD32Sfloat;
52 static const vk::Format depthImageFormat = vk::Format::eD16Unorm;
53 VmaAllocation depthImageAllocation;
54 vk::Image depthImage;
55 vk::ImageView depthImageView;
56
57 static const vk::Format colorImageFormat = vk::Format::eR16G16B16A16Sfloat;
58 std::array<VmaAllocation, 1> colorImageAllocations;
59 std::array<vk::Image, 1> colorImages;
60 std::array<vk::ImageView, 1> colorImageViews;
61 std::array<vk::DescriptorImageInfo, 1> colorDescriptorImageInfos;
62
63 vk::RenderPass renderPass;
64
65 vk::CommandBuffer commandBuffer;
66
67 vk::Semaphore imageAvailableSemaphore;
68 vk::Semaphore renderFinishedSemaphore;
69 vk::Fence renderFinishedFence;
70
75
76 gfx_surface_vulkan(gfx_system &system, vk::SurfaceKHR surface);
78
79 gfx_surface_vulkan(const gfx_surface_vulkan &) = delete;
80 gfx_surface_vulkan &operator=(const gfx_surface_vulkan &) = delete;
82 gfx_surface_vulkan &operator=(gfx_surface_vulkan &&) = delete;
83
84 void init() override;
85
86 void set_device(gfx_device *device) noexcept override;
87
88 gfx_device_vulkan &vulkan_device() const noexcept;
89 [[nodiscard]] extent2 size() const noexcept override;
90
91 void update(extent2 new_size) noexcept override;
92
93 [[nodiscard]] draw_context render_start(aarectangle redraw_rectangle) override;
94 void render_finish(draw_context const &context) override;
95
96protected:
97 void teardown() override;
98
99private:
100 gfx_queue_vulkan const *_graphics_queue;
101 gfx_queue_vulkan const *_present_queue;
102 extent2 _render_area_granularity;
103
104 void build(extent2 new_size);
105
106 std::optional<uint32_t> acquireNextImageFromSwapchain();
107 void presentImageToQueue(uint32_t frameBufferIndex, vk::Semaphore renderFinishedSemaphore);
108
109 void fill_command_buffer(swapchain_image_info &current_image, draw_context const &context);
110 void submitCommandBuffer();
111
112 bool readSurfaceExtent(extent2 minimum_size, extent2 maximum_size);
113 bool checkSurfaceExtent();
114
115 void buildDevice();
116 void buildSemaphores();
117 void teardownSemaphores();
118 gfx_surface_loss buildSwapchain(std::size_t new_count, extent2 new_size);
119 void teardownSwapchain();
120 void buildCommandBuffers();
121 void teardownCommandBuffers();
122 void buildRenderPasses();
123 void teardownRenderPasses();
124 void buildFramebuffers();
125 void teardownFramebuffers();
126 void buildPipelines();
127 void teardownPipelines();
128 bool buildSurface();
129 void teardownSurface();
130 void teardownDevice();
131
132 void waitIdle();
133
142 std::tuple<std::size_t, extent2> get_image_count_and_size(std::size_t new_count, extent2 new_size);
143};
144
145} // namespace hi::inline v1
STL namespace.
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:51
Definition gfx_device.hpp:22
Definition gfx_device_vulkan.hpp:20
Definition gfx_queue_vulkan.hpp:12
Definition gfx_surface.hpp:15
Definition gfx_surface_vulkan.hpp:28
Definition gfx_surface_vulkan.hpp:36
void set_device(gfx_device *device) noexcept override
Graphics system.
Definition gfx_system.hpp:21