HoviTron Video Pipeline
VulkanWrapper.h
Go to the documentation of this file.
1/* ----------------------
2* Copyright 2023 Université Libre de Bruxelles(ULB), Universidad Politécnica de Madrid(UPM), CREAL, Deutsches Zentrum für Luft - und Raumfahrt(DLR)
3
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at < http://www.apache.org/licenses/LICENSE-2.0>
7
8* Unless required by applicable law or agreed to in writing, software
9* distributed under the License is distributed on an "AS IS" BASIS,
10* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11* See the License for the specific language governing permissionsand
12* limitations under the License.
13---------------------- */
14
15
16/*****************************************************************/
28#pragma once
29
30#include <vector>
31
32#include"VulkanContext.h"
33#include"VulkanDrawing.h"
34
35#include"VulkanRenderPass.h"
36
37
38
39
40#ifdef __ANDROID__
41#include <android/log.h>
42#include <android_native_app_glue.h>
43#endif
44
45
46#include "commonVulkan.h"
47#include "InputProvider.h"
48#include "RenderingParameters.h"
49
50
51class Window;
52class WindowAbstract;
53class InputProvider;
54
55//Indicate which type of pipeline is used
56enum class PipelineMode{
57 Raster
58};
59
67public:
68#ifdef __ANDROID__
69 VulkanWrapper(WindowAbstract* window, android_app* appAndroid);
70#else
72 VulkanWrapper(WindowAbstract* window, PipelineMode pmode);
73#endif
74#if USE_OPENXR
76 XrGraphicsBindingVulkan2KHR getGraphicsBinding();
78 void endCleanUp();
79#else
80#endif
81#ifdef HVT_UDP_CONTROL
86 void init(unsigned short portNumber);
87#else
92 void init();
93#endif
95 void endInit(InputProvider * input, StartingPosition startingPt = StartingPosition::Average);
97 void start();
99 void cleanUp();
101 void recreateSwapChain();
103 void updateSpaceTransform(glm::vec3 translation, glm::vec3 rotation);
105 void updateSpaceTransform(glm::vec3 translation, glm::vec3 rotation, glm::vec4 fov, int view);
107 void waitIdle();
109 void createImageCall(uint32_t width, uint32_t height, vk::Format format, vk::ImageTiling tiling, vk::ImageUsageFlags usage, vk::MemoryPropertyFlags properties, vk::Image& image, vk::DeviceMemory& imageMemory);
111 void createBufferCall(vk::DeviceSize size, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags properties, vk::Buffer& buffer, vk::DeviceMemory& bufferMemory);
113 void copyMemory(VkDeviceSize& size, vk::DeviceMemory& memory, unsigned char* dataToCopy);
115 void destroyImageAndMemory(std::vector<vk::Image> &vectorImage, std::vector<vk::DeviceMemory> &vectorMemory);
117 void destroyBufferAndMemory(std::vector<vk::Buffer>& vectorBuffer, std::vector<vk::DeviceMemory>& vectorMemory);
121 void setBlendingFactor(float blendingfactor);
123 void setTriangleThreshold(float triangleThreshold);
126
130 vk::Extent2D getSwapchainExtend(int view = 0); //size of the swapchainExtend
132 vk::Extent2D getRenderOutputExtent();
133
135 std::vector<vk::Format> getRenderPassSupportedDepthFormats() const;
137 vk::Format getSwapchainFormat(int view = 0);
139 vk::Format getDepthSwapchainFormat(int view = 0);
140
146 vk::ImageLayout getLayoutAfterRenderpass();
147
153 int getAttachmentSize();
158 int getViewNumber();
160 void setAverageInputPosition(std::vector<InputProvider::StreamFrameInfo>& frameInfo);
161
163 void addDeltaToStartingPoint(glm::vec3 dPos, glm::vec3 dRot);
164
166 void setCorrectionRotation(int camId, glm::vec3 rotationCorrection);
168 void setCorrectionTranslation(int camId, glm::vec3 translationCorrection);
170 void setCorrectionFocal(int camId, glm::vec2 focals);
172 void setCorrectionPrincipalPt(int camId, glm::vec2 principalPt);
174 void setScaleFactor(float scaleFactor);
175
177 bool framebufferResized = false;
178
180 const vk::Format internalColorAttachmentFormat = vk::Format::eR8G8B8A8Unorm;//vk::Format::eR32G32B32A32Sfloat;
182 const vk::Format internal1DAttachmentFormat = vk::Format::eR32Sfloat;
184 const vk::Format qualityAttachmentFormat = vk::Format::eR32Sfloat;
185
186
187
189 const bool multiviewSetup;
192
195
198
200 const std::vector<glm::vec3> getCorrectionVectorRotation();
202 const std::vector<InputProvider::StreamFrameInfo> getFramesInfo(int view);
208 std::vector<bool> getCameraActivation();
210 void toggleCamera(int i);
212 void setCameraActivation(std::vector<bool> activation);
213
214
215
216 using RenderPassType = VulkanRenderpass;
217
218private:
219#ifdef HVT_UDP_CONTROL
220 //mutex used to avoid race condition because of the UDP server running on another thread
221 std::mutex mutexAct;
222 //port requested for the UDP server
223 unsigned short port = 0;
224#endif
225 //default path where the offset info or the input camera are stored
226 const char* fileN = "./DumpCorrectionsVectors.txt";
227#ifdef __ANDROID__
228 android_app* appAndroid;
229#endif
230 //pointer to the window requested by the system
231 WindowAbstract* window = nullptr;
232
233 //unique_ptr to the renderpass
234 std::unique_ptr<VulkanRenderPassAbstract> renderPass;
235 //Reference to the VulkanDrawing class
236 VulkanDrawing drawing;
237 //Pointer to the Input provider that will provide the data
238 InputProvider* inputProvider = nullptr;
239
240 //store the requested attachment size
241 int attachmentSize = 1;
242
243 //Contains an offset to be applied to the rotation of the input cameras
244 std::vector<glm::vec3> correctionVectorRotation;
245 //contains an offset to be applied to the translation of the input cameras
246 std::vector<glm::vec3> correctionVectorTranslation;
247 //contains an offset to be applied to the focal of the input cameras
248 std::vector<glm::vec2> correctionFocal;
249 //contains an offset to be applied to the principle pts of the input cameras
250 std::vector<glm::vec2> correctionPrincipalPt;
251
252 //Vector that contains a boolean that control if an input camera is in use or not
253 std::vector<bool> cameraActivation;
254 //The number of cameras used as input have changed, some ressources have to be changed
255 bool requestChange = false;
256
257 //The informations retrieved from the inputProvider each new frame
258 std::vector<InputProvider::StreamFrameInfo> streamFrameInfos;
259
260};
File that contain the VulkanContext class to manage Vulkan Instance, Physical device,...
Contains the class that manage the drawing process (manage and record command buffer,...
file that contains the class that manage the renderPass containing the synthesis and blending steps
Abstract interface around getting source views parameters and data.
Definition: InputProvider.h:35
Class that encapsulates the rendering parameters (RVS internal parameters + virtual camera parameters...
class that manages tasks related to Vulkan context (Vulkan Instance, Vulkan Physical device,...
Definition: VulkanContext.h:59
The class that manages the drawing operation (manage and record command buffers).
Definition: VulkanDrawing.h:46
Class that manages the classes related to Vulkan code and act as a wrapper around them.
Definition: VulkanWrapper.h:66
void loadConfigurationsFromDisk()
const std::vector< InputProvider::StreamFrameInfo > getFramesInfo(int view)
bool isDepthOutputRecquired()
void copyMemory(VkDeviceSize &size, vk::DeviceMemory &memory, unsigned char *dataToCopy)
void setCorrectionTranslation(int camId, glm::vec3 translationCorrection)
void destroyBufferAndMemory(std::vector< vk::Buffer > &vectorBuffer, std::vector< vk::DeviceMemory > &vectorMemory)
void recreateSwapChain()
void setScaleFactor(float scaleFactor)
void addDeltaToStartingPoint(glm::vec3 dPos, glm::vec3 dRot)
void saveConfigurationsToDisk()
const vk::Format internal1DAttachmentFormat
bool framebufferResized
void setTriangleThreshold(float triangleThreshold)
void setCorrectionFocal(int camId, glm::vec2 focals)
vk::Extent2D getRenderOutputExtent()
void endInit(InputProvider *input, StartingPosition startingPt=StartingPosition::Average)
std::vector< vk::Format > getRenderPassSupportedDepthFormats() const
void createImageCall(uint32_t width, uint32_t height, vk::Format format, vk::ImageTiling tiling, vk::ImageUsageFlags usage, vk::MemoryPropertyFlags properties, vk::Image &image, vk::DeviceMemory &imageMemory)
bool requireAverageInputPosition
void setCorrectionPrincipalPt(int camId, glm::vec2 principalPt)
void setAverageInputPosition(std::vector< InputProvider::StreamFrameInfo > &frameInfo)
const vk::Format internalColorAttachmentFormat
vk::Extent2D getSwapchainExtend(int view=0)
VulkanContext context
void setBlendingFactor(float blendingfactor)
const std::vector< glm::vec3 > getCorrectionVectorRotation()
bool isUsingDifferentViewSize()
void destroyImageAndMemory(std::vector< vk::Image > &vectorImage, std::vector< vk::DeviceMemory > &vectorMemory)
void updateSpaceTransform(glm::vec3 translation, glm::vec3 rotation)
vk::Format getDepthSwapchainFormat(int view=0)
void createBufferCall(vk::DeviceSize size, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags properties, vk::Buffer &buffer, vk::DeviceMemory &bufferMemory)
const bool multiviewSetup
vk::Format getSwapchainFormat(int view=0)
RenderingParameters params
const vk::Format qualityAttachmentFormat
std::vector< bool > getCameraActivation()
VulkanContext * getContext()
void setCameraActivation(std::vector< bool > activation)
void toggleCamera(int i)
vk::ImageLayout getLayoutAfterRenderpass()
void setCorrectionRotation(int camId, glm::vec3 rotationCorrection)
Abstraction of the way of the result is displayed (screen or HMD).
file that contains the common include for the Vulkan part