HoviTron Video Pipeline
VulkanPipelineBlending.cpp
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
16#include "VulkanContext.h"
17#include "Shader.h"
19//#include "../RVSConfig/include/Application.h"
20#include "VulkanRenderPass.h"
21#include "VulkanWrapper.h"
22
24{
25 this->context = context;
26 this->renderPass = renderPass;
27 this->wrapper = wraps;
28 this->depthWrite = false;
29
30 this->subPass = 2 * inputCameraId + 1;
31 this->inputId = inputCameraId;
32
33 this->bufferController = std::make_unique<BufferControllerBlending>(context, renderPass, this, wraps, inputCameraId);
34
35 if (inputCameraId == this->renderPass->inputImage - 1) {
36 this->colorAttachmentNb = 1;
38 this->depthWrite = true;
39 }
40 }
41 else {
43 this->colorAttachmentNb = 3;
44 }
45 else {
46 this->colorAttachmentNb = 2; //outputAttachement
47 }
48 }
49
50
51
52 this->depthTest = false;
53
54}
55
57{
59 createGraphicsPipeline();
60 bufferController->init();
61}
62
64{
65 bufferController->cleanUp();
67 context->device.destroyPipeline(pipeline);
68 context->device.destroyPipelineLayout(pipelineLayout);
69}
70
72{
73 vk::DescriptorSetLayoutBinding uboLayoutBinding(
74 1, //binding
75 vk::DescriptorType::eUniformBuffer, //descriptor type
76 1, //descriptorCount
77 vk::ShaderStageFlagBits::eFragment, //stageFlags
78 nullptr //pimmutable sampler
79 );
80 vk::DescriptorSetLayoutBinding accu_imageLayoutBinding(
81 2, //binding
82 vk::DescriptorType::eInputAttachment, //descriptor type
83 1, //descriptorCount
84 vk::ShaderStageFlagBits::eFragment, //stageFlags
85 nullptr //pimmutable sampler
86 );
87 //input AttachementDescriptor
88 vk::DescriptorSetLayoutBinding new_imageLayoutBinding(
89 3, //binding
90 vk::DescriptorType::eInputAttachment, //descriptor type
91 1, //descriptorCount
92 vk::ShaderStageFlagBits::eFragment, //stageFlags
93 nullptr //pimmutable sampler
94 );
95 vk::DescriptorSetLayoutBinding accu_qualityLayoutBinding(
96 4, //binding
97 vk::DescriptorType::eInputAttachment, //descriptor type
98 1, //descriptorCount
99 vk::ShaderStageFlagBits::eFragment, //stageFlags
100 nullptr //pimmutable sampler
101 );
102 vk::DescriptorSetLayoutBinding new_triangle_qualityLayoutBinding(
103 5, //binding
104 vk::DescriptorType::eInputAttachment, //descriptor type
105 1, //descriptorCount
106 vk::ShaderStageFlagBits::eFragment, //stageFlags
107 nullptr //pimmutable sampler
108 );
109 vk::DescriptorSetLayoutBinding new_depthLayoutBinding(
110 6, //binding
111 vk::DescriptorType::eInputAttachment, //descriptor type
112 1, //descriptorCount
113 vk::ShaderStageFlagBits::eFragment, //stageFlags
114 nullptr //pimmutable sampler
115 );
116
117
118
119
120 std::vector<vk::DescriptorSetLayoutBinding> bindings = { uboLayoutBinding, new_imageLayoutBinding,new_triangle_qualityLayoutBinding, new_depthLayoutBinding,
121 accu_imageLayoutBinding, accu_qualityLayoutBinding};
122
124 vk::DescriptorSetLayoutBinding accu_depthLayoutBinding(
125 7, //binding
126 vk::DescriptorType::eInputAttachment, //descriptor type
127 1, //descriptorCount
128 vk::ShaderStageFlagBits::eFragment, //stageFlags
129 nullptr //pimmutable sampler
130 );
131 bindings.push_back(accu_depthLayoutBinding);
132 }
133
134 vk::DescriptorSetLayoutCreateInfo layoutInfo(vk::DescriptorSetLayoutCreateFlags(), static_cast<uint32_t>(bindings.size()), bindings.data());
135
136 descriptorSetLayout = context->device.createDescriptorSetLayout(layoutInfo);
137}
138
139void VulkanPipelineBlending::createGraphicsPipeline()
140{
141 vk::ShaderModule vertShaderModule = createShaderModule(ShadersList::getInstance()("blending.vert"));
142 vk::ShaderModule fragShaderModule;
143
144
146
147 if (inputId == 0 && inputId == renderPass->inputImage - 1) {
148 //use a modified shader for the first input and only input
149 fragShaderModule = createShaderModule(ShadersList::getInstance()("blendingFirstFinalD.frag"));
150 }
151 else if (inputId == 0) {
152 //use a modified shader for the first input
153 fragShaderModule = createShaderModule(ShadersList::getInstance()("blendingFirstD.frag"));
154 }
155 else if (inputId == renderPass->inputImage - 1) {
156 fragShaderModule = createShaderModule(ShadersList::getInstance()("blendingFinalD.frag"));
157 }
158 else {
159 fragShaderModule = createShaderModule(ShadersList::getInstance()("blendingD.frag"));
160 }
161 }
162 else {
163 if (inputId == 0 && inputId == renderPass->inputImage - 1) {
164 //use a modified shader for the first input and only input
165 fragShaderModule = createShaderModule(ShadersList::getInstance()("blendingFirstFinal.frag"));
166 }
167 else if (inputId == 0) {
168 //use a modified shader for the first input
169 fragShaderModule = createShaderModule(ShadersList::getInstance()("blendingFirst.frag"));
170 }
171 else if (inputId == renderPass->inputImage - 1) {
172 fragShaderModule = createShaderModule(ShadersList::getInstance()("blendingFinal.frag"));
173 }
174 else {
175 fragShaderModule = createShaderModule(ShadersList::getInstance()("blending.frag"));
176 }
177 }
178
179 std::vector<vk::PipelineShaderStageCreateInfo> pipelineShaderStageCreateInfos = {
180 vk::PipelineShaderStageCreateInfo(
181 vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertShaderModule, "main"), //main is entry point of the shader
182 vk::PipelineShaderStageCreateInfo(
183 vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragShaderModule, "main")
184 };
185
186 this->createPipeline(pipelineShaderStageCreateInfos);
187
188 context->device.destroyShaderModule(vertShaderModule);
189 context->device.destroyShaderModule(fragShaderModule);
190}
File that contains class and struct for the management of the ressources for the blending pipeline.
Contains the class that loads the SPIR-V shaders from files.
File that contain the VulkanContext class to manage Vulkan Instance, Physical device,...
file that conthains a class that manages the pipeline for the blending
file that contains the class that manage the renderPass containing the synthesis and blending steps
file that contains the VulkanWrapper class that manages the classes related to Vulkan code and ease t...
static ShadersList & getInstance()
Definition: Shader.cpp:99
class that manages tasks related to Vulkan context (Vulkan Instance, Vulkan Physical device,...
Definition: VulkanContext.h:59
vk::Device device
Definition: VulkanContext.h:87
std::unique_ptr< BuffersController > bufferController
void createPipeline(std::vector< vk::PipelineShaderStageCreateInfo > &arr)
VulkanRenderPass * renderPass
vk::ShaderModule createShaderModule(const Shader &shader)
vk::DescriptorSetLayout descriptorSetLayout
vk::PipelineLayout pipelineLayout
VulkanPipelineBlending(VulkanContext *context, VulkanRenderPass *renderPass, VulkanWrapper *wraps, int inputCameraId)
void createDescriptorSetLayout() override
Class that manage the renderPass containing the synthesis and blending steps.
Class that manages the classes related to Vulkan code and act as a wrapper around them.
Definition: VulkanWrapper.h:66
bool isDepthOutputRecquired()