UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
vulkan_display.hpp
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2021-2023 CESNET, z. s. p. o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#pragma once
39
40#include "vulkan_context.hpp"
42#include "vulkan_pipelines.hpp"
43#include "concurrent_queue.hpp"
44
45#include <array>
46#include <deque>
47#include <optional>
48#include <queue>
49#include <mutex>
50#include <string>
51#include <utility>
52
53namespace vulkan_display_detail {
54
55constexpr static unsigned filled_img_max_count = 1;
56constexpr auto waiting_time_for_filled_image = 50ms;
57constexpr size_t filled_image_queue_size = 1;
58
69
70
71} // vulkan_display_detail
72
73namespace vulkan_display {
74
76
78protected:
80public:
82};
83
85 std::string path_to_shaders;
88
89 vk::Device device;
90 std::mutex device_mutex{};
91
94
96
97 vk::DescriptorPool descriptor_pool;
98 vk::CommandPool command_pool;
99
100 std::array<detail::PerFrameResources, 3> frame_resources;
101 std::vector<detail::PerFrameResources*> free_frame_resources;
102
104
106 std::deque<TransferImageImpl> transfer_images{};
107
113 std::vector<TransferImageImpl*> available_images;
114
119 std::queue<RenderedImage> rendered_images;
120
121 bool destroyed = false;
122private:
124 //void create_transfer_image(transfer_image*& result, image_description description);
126
127 void record_graphics_commands(detail::PerFrameResources& commands, TransferImageImpl& transfer_image, uint32_t swapchain_image_id);
128
129 void reconfigure(const TransferImageImpl& transfer_image);
130
132public:
136
137 VulkanDisplay() = default;
138
139 VulkanDisplay(const VulkanDisplay& other) = delete;
140 VulkanDisplay& operator=(const VulkanDisplay& other) = delete;
141 VulkanDisplay(VulkanDisplay&& other) = delete;
143
144 ~VulkanDisplay() noexcept {
145 if (!destroyed) {
146 try {
147 destroy();
148 } catch (vk::SystemError &e) {
149 std::string err = std::string("~VulkanDisplay vk::SystemError: ") + e.what() + "\n";
151 }
152 }
153 }
154
155 void init(VulkanInstance&& instance, vk::SurfaceKHR surface, uint32_t transfer_image_count,
156 WindowChangedCallback& window, uint32_t gpu_index = no_gpu_selected,
157 std::string path_to_shaders = "./shaders", bool vsync = true, bool tearing_permitted = false);
158
159 void destroy();
160
163
166
171 bool queue_image(TransferImage img, bool discardable);
172
175
178 auto* ptr = image.get_transfer_image();
179 assert(ptr);
180 available_images.push_back(ptr);
181 }
182
183
184
190
192 uint32_t get_vulkan_version() const { return context.get_vulkan_version(); }
193
196
201 void window_parameters_changed(WindowParameters new_parameters);
202
203
208};
209
210} //vulkan_display
struct video_frame * frame
vulkan_display_detail::TransferImageImpl * get_transfer_image()
void discard_image(TransferImage image)
detail::ConversionPipeline conversion_pipeline
detail::VulkanContext context
TransferImageImpl & acquire_transfer_image()
VulkanDisplay(VulkanDisplay &&other)=delete
detail::RenderPipeline render_pipeline
VulkanDisplay & operator=(VulkanDisplay &&other)=delete
std::array< detail::PerFrameResources, 3 > frame_resources
std::queue< RenderedImage > rendered_images
detail::ConcurrentQueue< TransferImageImpl * > available_img_queue
available_img_queue - producer is the render thread, consumer is the provided thread
bool queue_image(TransferImage img, bool discardable)
void copy_and_queue_image(unsigned char *frame, ImageDescription description)
vk::DescriptorPool descriptor_pool
ImageDescription current_image_description
void reconfigure(const TransferImageImpl &transfer_image)
VulkanDisplay(const VulkanDisplay &other)=delete
std::vector< detail::PerFrameResources * > free_frame_resources
bool is_image_description_supported(ImageDescription description)
void init(VulkanInstance &&instance, vk::SurfaceKHR surface, uint32_t transfer_image_count, WindowChangedCallback &window, uint32_t gpu_index=no_gpu_selected, std::string path_to_shaders="./shaders", bool vsync=true, bool tearing_permitted=false)
void bind_transfer_image(TransferImageImpl &image, detail::PerFrameResources &resources)
std::vector< TransferImageImpl * > available_images
local to provider thread
detail::ConcurrentQueue< TransferImageImpl *, detail::filled_img_max_count > filled_img_queue
filled_img_queue - producer is the provider thread, consumer is the render thread
std::deque< TransferImageImpl > transfer_images
void record_graphics_commands(detail::PerFrameResources &commands, TransferImageImpl &transfer_image, uint32_t swapchain_image_id)
TransferImage acquire_image(ImageDescription description)
VulkanDisplay & operator=(const VulkanDisplay &other)=delete
WindowChangedCallback * window
virtual WindowParameters get_window_parameters()=0
static constexpr unsigned filled_img_max_count
std::function< void(vulkan_display::LogLevel, std::string_view)> vulkan_log_msg
constexpr auto waiting_time_for_filled_image
constexpr size_t filled_image_queue_size
constexpr uint32_t no_gpu_selected
const char * description
Definition cineform.cpp:126
static class worker_pool instance
Definition worker.cpp:250