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_box {
20class pipeline_box;
21}
22namespace pipeline_SDF {
23class pipeline_SDF;
24}
25namespace pipeline_tone_mapper {
26class pipeline_tone_mapper;
27}
28
30 vk::Image image;
31 vk::ImageView image_view;
32 vk::Framebuffer frame_buffer;
33 aarectangle redraw_rectangle;
34 bool layout_is_present = false;
35};
36
37class gfx_surface_vulkan final : public gfx_surface {
38public:
39 using super = gfx_surface;
40
41 vk::SurfaceKHR intrinsic;
42
43 vk::SwapchainKHR swapchain;
44
45 static constexpr uint32_t defaultNumberOfSwapchainImages = 2;
46
47 uint32_t nrSwapchainImages;
48 vk::Extent2D swapchainImageExtent;
49 vk::SurfaceFormatKHR swapchainImageFormat;
50 std::vector<swapchain_image_info> swapchain_image_infos;
51
52 static const vk::Format depthImageFormat = vk::Format::eD32Sfloat;
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,2> colorImageAllocations;
59 std::array<vk::Image,2> colorImages;
60 std::array<vk::ImageView,2> colorImageViews;
61 std::array<vk::DescriptorImageInfo, 2> 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 [[nodiscard]] void update(extent2 new_size) noexcept override;
92
93 [[nodiscard]] std::optional<draw_context> render_start(aarectangle redraw_rectangle) override;
94 void render_finish(draw_context const &context, color background_color) override;
95
96protected:
97 void teardown() override;
98
99private:
100 gfx_queue_vulkan const *_graphics_queue;
101 gfx_queue_vulkan const *_present_queue;
102
103 void build(extent2 new_size);
104
105 std::optional<uint32_t> acquireNextImageFromSwapchain();
106 void presentImageToQueue(uint32_t frameBufferIndex, vk::Semaphore renderFinishedSemaphore);
107
108 void fill_command_buffer(swapchain_image_info &current_image, aarectangle scissor_rectangle, color background_color);
109 void submitCommandBuffer();
110
111 bool readSurfaceExtent(extent2 minimum_size, extent2 maximum_size);
112 bool checkSurfaceExtent();
113
114 void buildDevice();
115 void buildSemaphores();
116 void teardownSemaphores();
117 gfx_surface_state buildSwapchain(size_t new_count, extent2 new_size);
118 void teardownSwapchain();
119 void buildCommandBuffers();
120 void teardownCommandBuffers();
121 void buildRenderPasses();
122 void teardownRenderPasses();
123 void buildFramebuffers();
124 void teardownFramebuffers();
125 void buildPipelines();
126 void teardownPipelines();
127 bool buildSurface();
128 void teardownSurface();
129 void teardownDevice();
130
131 void waitIdle();
132
141 std::tuple<size_t, extent2> get_image_count_and_size(size_t new_count, extent2 new_size);
142};
143
144}
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:28
Definition gfx_device.hpp:22
Definition gfx_device_vulkan.hpp:23
Definition gfx_queue_vulkan.hpp:12
Definition gfx_surface.hpp:16
Definition gfx_surface_vulkan.hpp:29
Definition gfx_surface_vulkan.hpp:37
void set_device(gfx_device *device) noexcept override
void update(extent2 new_size) noexcept override
Update the surface.
extent2 size() const noexcept override
Get the size of the surface.
Graphics system.
Definition gfx_system.hpp:21