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 tt {
14class gfx_device_vulkan;
15
16namespace pipeline_image {
17class pipeline_image;
18}
19namespace pipeline_flat {
20class pipeline_flat;
21}
22namespace pipeline_box {
23class pipeline_box;
24}
25namespace pipeline_SDF {
26class pipeline_SDF;
27}
28namespace pipeline_tone_mapper {
29class pipeline_tone_mapper;
30}
31
33 vk::Image image;
34 vk::ImageView image_view;
35 vk::Framebuffer frame_buffer;
36 aarectangle redraw_rectangle;
37 bool layout_is_present = false;
38};
39
40class gfx_surface_vulkan final : public gfx_surface {
41public:
42 using super = gfx_surface;
43
44 vk::SurfaceKHR intrinsic;
45
46 vk::SwapchainKHR swapchain;
47
48 static constexpr uint32_t defaultNumberOfSwapchainImages = 2;
49
50 int nrSwapchainImages;
51 vk::Extent2D swapchainImageExtent;
52 vk::SurfaceFormatKHR swapchainImageFormat;
53 std::vector<swapchain_image_info> swapchain_image_infos;
54
55 static const vk::Format depthImageFormat = vk::Format::eD32Sfloat;
56 VmaAllocation depthImageAllocation;
57 vk::Image depthImage;
58 vk::ImageView depthImageView;
59
60 static const vk::Format colorImageFormat = vk::Format::eR16G16B16A16Sfloat;
61 std::array<VmaAllocation,2> colorImageAllocations;
62 std::array<vk::Image,2> colorImages;
63 std::array<vk::ImageView,2> colorImageViews;
64 std::array<vk::DescriptorImageInfo, 2> colorDescriptorImageInfos;
65
66 vk::RenderPass renderPass;
67
68 vk::CommandBuffer commandBuffer;
69
70 vk::Semaphore imageAvailableSemaphore;
71 vk::Semaphore renderFinishedSemaphore;
72 vk::Fence renderFinishedFence;
73
79
80 gfx_surface_vulkan(gfx_system &system, vk::SurfaceKHR surface);
82
83 gfx_surface_vulkan(const gfx_surface_vulkan &) = delete;
84 gfx_surface_vulkan &operator=(const gfx_surface_vulkan &) = delete;
86 gfx_surface_vulkan &operator=(gfx_surface_vulkan &&) = delete;
87
88 void init() override;
89
90 void set_device(gfx_device *device) noexcept override;
91
92 gfx_device_vulkan &vulkan_device() const noexcept;
93
94 [[nodiscard]] extent2 update(extent2 minimum_size, extent2 maximum_size) noexcept override;
95
96 [[nodiscard]] std::optional<draw_context> render_start(aarectangle redraw_rectangle) override;
97 void render_finish(draw_context const &context, color background_color) override;
98
99protected:
100 void teardown() override;
101
102private:
103 gfx_queue_vulkan const *_graphics_queue;
104 gfx_queue_vulkan const *_present_queue;
105
106 void build(extent2 minimum_size, extent2 maximum_size);
107
108 std::optional<uint32_t> acquireNextImageFromSwapchain();
109 void presentImageToQueue(uint32_t frameBufferIndex, vk::Semaphore renderFinishedSemaphore);
110
111 void fill_command_buffer(swapchain_image_info &current_image, aarectangle scissor_rectangle, color background_color);
112 void submitCommandBuffer();
113
114 bool readSurfaceExtent(extent2 minimum_size, extent2 maximum_size);
115 bool checkSurfaceExtent();
116
117 void buildDevice();
118 void buildSemaphores();
119 void teardownSemaphores();
120 gfx_surface_state buildSwapchain();
121 void teardownSwapchain();
122 void buildCommandBuffers();
123 void teardownCommandBuffers();
124 void buildRenderPasses();
125 void teardownRenderPasses();
126 void buildFramebuffers();
127 void teardownFramebuffers();
128 void buildPipelines();
129 void teardownPipelines();
130 bool buildSurface();
131 void teardownSurface();
132 void teardownDevice();
133
134 void waitIdle();
135 std::tuple<uint32_t, vk::Extent2D> getImageCountAndExtent();
136};
137
138}
STL namespace.
This is a RGBA floating point color.
Definition color.hpp:36
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:29
Definition gfx_device.hpp:22
Definition gfx_device_vulkan.hpp:24
Definition gfx_queue_vulkan.hpp:12
Definition gfx_surface.hpp:16
Definition gfx_surface_vulkan.hpp:32
Definition gfx_surface_vulkan.hpp:40
void set_device(gfx_device *device) noexcept override
extent2 update(extent2 minimum_size, extent2 maximum_size) noexcept override
Update the surface.
Graphics system.
Definition gfx_system.hpp:21