HoviTron Video Pipeline
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
VulkanPipelineAbsract Class Referenceabstract

The abstract class that encapsulate vk::Pipeline object and contains common code between the two pipelines used in this project(blending and warping). More...

#include <VulkanPipelineAbstract.h>

Inheritance diagram for VulkanPipelineAbsract:
VulkanPipelineBlending VulkanPipelineWarping

Public Member Functions

virtual void init ()=0
 
virtual void cleanUp ()=0
 
void cmdBufferBindBuffer (vk::CommandBuffer &cmdBuffer, int index, InputProvider::StreamFrameInfo &frameInfo, int view)
 
void updateAllBuffer (uint32_t currentImage, int view)
 
void updateBuffer (uint32_t currentImage, int view)
 
virtual void createDescriptorSetLayout ()=0
 
uint32_t getIndexNumber ()
 

Data Fields

vk::Pipeline pipeline
 
vk::DescriptorSetLayout descriptorSetLayout
 
vk::PipelineLayout pipelineLayout
 

Protected Member Functions

virtual void createGraphicsPipeline ()=0
 
vk::ShaderModule createShaderModule (const Shader &shader)
 
void createPipeline (std::vector< vk::PipelineShaderStageCreateInfo > &arr)
 

Protected Attributes

VulkanContextcontext = nullptr
 
VulkanRenderPassrenderPass = nullptr
 
VulkanWrapperwrapper = nullptr
 
std::unique_ptr< BuffersControllerbufferController
 
int subPass = 0
 
int inputId = 0
 
int colorAttachmentNb = 0
 
bool depthTest = true
 
bool depthWrite = true
 

Detailed Description

The abstract class that encapsulate vk::Pipeline object and contains common code between the two pipelines used in this project(blending and warping).

The abstract class for common code between the two pipelines (blending and warping). It encapsulates vk::Pipeline object Buffers management for the pipeline is delegated to a class that inherit from the BuffersControllerAbstract class

Definition at line 44 of file VulkanPipelineAbstract.h.

Member Function Documentation

◆ cleanUp()

virtual void VulkanPipelineAbsract::cleanUp ( )
pure virtual

Clean up

Implemented in VulkanPipelineWarping, and VulkanPipelineBlending.

◆ cmdBufferBindBuffer()

void VulkanPipelineAbsract::cmdBufferBindBuffer ( vk::CommandBuffer &  cmdBuffer,
int  index,
InputProvider::StreamFrameInfo frameInfo,
int  view 
)

bind the needed buffer for this frame

Definition at line 194 of file VulkanPipelineAbstract.cpp.

195{
196 bufferController->bindBuffers(cmdBuffer, index, frameInfo, view);
197}
std::unique_ptr< BuffersController > bufferController

◆ createDescriptorSetLayout()

virtual void VulkanPipelineAbsract::createDescriptorSetLayout ( )
pure virtual

Create descriptor sets layout

Implemented in VulkanPipelineWarping, and VulkanPipelineBlending.

◆ createGraphicsPipeline()

virtual void VulkanPipelineAbsract::createGraphicsPipeline ( )
protectedpure virtual

Create the graphics pipeline

◆ createPipeline()

void VulkanPipelineAbsract::createPipeline ( std::vector< vk::PipelineShaderStageCreateInfo > &  arr)
protected

Create the pipeline

Definition at line 34 of file VulkanPipelineAbstract.cpp.

35{
36 auto descr = bufferController->getAttributeDescription();
37 D(std::cout << "pipeline attribute descrp: " << descr.size() << std::endl;)
38
39 auto descrBinding = bufferController->getBindingDescription();
40
41 vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
42 vk::PipelineVertexInputStateCreateFlags(), // flags
43 1, // vertexBindingDescriptions Count
44 &(descrBinding), // vertexBindingDescriptions
45 static_cast<uint32_t>((descr).size()), // vertexAttributeDescriptionsCount
46 (descr.data()) // vertexAttributeDescriptions
47 );
48
49 vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
50 vk::PipelineInputAssemblyStateCreateFlags(), // Flags
51 vk::PrimitiveTopology::eTriangleList, // Topology
52 0 // Primitive restart enable
53 );
54
55
56 //vk::Rect2D scissor{ {0,0},renderPass->renderingExtent };
57
58 //viewport state
59 vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo(
60 vk::PipelineViewportStateCreateFlags(),
62
63 //rasterizer
64 vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo(
65 vk::PipelineRasterizationStateCreateFlags(), // flags
66 false, // depthClampEnable
67 false, // rasterizerDiscardEnable
68 vk::PolygonMode::eFill, // polygonMode
69 vk::CullModeFlagBits::eNone, // cullMode
70 vk::FrontFace::eClockwise, // frontFace
71 false, // depthBiasEnable
72 0.0f, // depthBiasConstantFactor
73 0.0f, // depthBiasClamp
74 0.0f, // depthBiasSlopeFactor
75 1.0f // lineWidth
76 );
77
78 vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo(
79 vk::PipelineMultisampleStateCreateFlags(), // flags
80 vk::SampleCountFlagBits::e1 // rasterizationSamples
81 // other values can be default
82 );
83
84 //depthStencil ?
85
86 vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(
87 vk::PipelineDepthStencilStateCreateFlags(), // flags
88 true, // depthTestEnable
89 true, // depthWriteEnable
90 (! this->depthTest && depthWrite) ? vk::CompareOp::eAlways : vk::CompareOp::eLess, // depthCompareOp
91 false, // depthBoundTestEnable
92 false, // stencilTestEnable
93 {}, // front
94 {}, // back
95 0.0f, //minDepthBounds
96 1.0f //maxDepthBounds
97 );
98
99 //color blending
100 vk::ColorComponentFlags colorComponentFlags(vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG |
101 vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA);
102 vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState(
103 false, // blendEnable
104 vk::BlendFactor::eOne, // srcColorBlendFactor //change this for alpha blending
105 vk::BlendFactor::eZero, // dstColorBlendFactor //change this for alpha blending
106 vk::BlendOp::eAdd, // colorBlendOp
107 vk::BlendFactor::eOne, // srcAlphaBlendFactor
108 vk::BlendFactor::eZero, // dstAlphaBlendFactor
109 vk::BlendOp::eAdd, // alphaBlendOp
110 colorComponentFlags // colorWriteMask
111 );
112
113 //std::array<vk::PipelineColorBlendAttachmentState, 3> pipelineColorBlendAttachementArray = { pipelineColorBlendAttachmentState,pipelineColorBlendAttachmentState,pipelineColorBlendAttachmentState };
114 std::vector<vk::PipelineColorBlendAttachmentState> pipelineColorBlendAttachementArray(colorAttachmentNb, pipelineColorBlendAttachmentState);
115
116 vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(
117 vk::PipelineColorBlendStateCreateFlags(), // flags
118 false, // logicOpEnable
119 vk::LogicOp::eCopy, // logicOp //TODO check this
120 static_cast<uint32_t>(pipelineColorBlendAttachementArray.size()),
121 pipelineColorBlendAttachementArray.data(), // attachments
122 { { 0.0f, 0.0f, 0.0f, 0.0f } } // blendConstants
123 );
124
125 //dynamic state
126 //std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
127 //vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), dynamicStates.size(), dynamicStates.data());
128
129 //pipeline Layout
130 vk::PipelineLayoutCreateInfo pipelineLayoutInfo(
131 vk::PipelineLayoutCreateFlags(), //flags
132 1, //layoutCount
133 &descriptorSetLayout, //pSetLayout
134 0, //pushConstantRangeCount
135 nullptr); //pushConstantRange
136 pipelineLayout = context->device.createPipelineLayout(pipelineLayoutInfo);
137
138 //pipelineInfo
139 vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo(
140 vk::PipelineCreateFlags(), // flags
141 pipelineShaderStageCreateInfos.size(), //stageCount
142 pipelineShaderStageCreateInfos.data(), // stages
143 &pipelineVertexInputStateCreateInfo, // pVertexInputState
144 &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
145 nullptr, // pTessellationState
146 &pipelineViewportStateCreateInfo, // pViewportState
147 &pipelineRasterizationStateCreateInfo, // pRasterizationState
148 &pipelineMultisampleStateCreateInfo, // pMultisampleState
149 depthTest || depthWrite ? &pipelineDepthStencilStateCreateInfo : nullptr, // pDepthStencilState
150 &pipelineColorBlendStateCreateInfo, // pColorBlendState
151 nullptr, // pDynamicState
152 pipelineLayout, // layout
153 renderPass->renderPass, // renderPass
154 subPass //subPass
155 );
156
157 std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
158 vk::PipelineDynamicStateCreateInfo dynamicInfo(
159 vk::PipelineDynamicStateCreateFlags(),
160 static_cast<uint32_t> (dynamicStates.size()),
161 dynamicStates.data()
162 );
163
165 //vk::DynamicState::eViewport
166 graphicsPipelineCreateInfo.pDynamicState = &dynamicInfo;
167
168 }
169
170#ifdef __ANDROID__
171 pipeline = context->device.createGraphicsPipeline(nullptr, graphicsPipelineCreateInfo);
172#else
173 vk::Result result;
174 std::tie(result, pipeline) = context->device.createGraphicsPipeline(nullptr, graphicsPipelineCreateInfo);
175
176 switch (result)
177 {
178 case vk::Result::eSuccess: break;
179 case vk::Result::ePipelineCompileRequiredEXT:
180 // something meaningfull here
181 throw std::runtime_error("failed to create graphics pipeline! result was ePipelineCompileRequiredEXT");
182 break;
183 default: throw std::runtime_error("failed to create graphics pipeline!");; // should never happen
184 }
185#endif
186}
vk::Device device
Definition: VulkanContext.h:87
VulkanRenderPass * renderPass
vk::DescriptorSetLayout descriptorSetLayout
vk::PipelineLayout pipelineLayout
vk::RenderPass renderPass
bool isUsingDifferentViewSize()
const bool multiviewSetup

◆ createShaderModule()

vk::ShaderModule VulkanPipelineAbsract::createShaderModule ( const Shader shader)
protected

Cretae shader modules

Definition at line 22 of file VulkanPipelineAbstract.cpp.

23{
24 vk::ShaderModuleCreateInfo shaderModuleCreateInfo(vk::ShaderModuleCreateFlags(), shader.size, reinterpret_cast<const uint32_t*>(shader.source));
25 vk::ShaderModule shaderModule = context->device.createShaderModule(shaderModuleCreateInfo);
26#ifndef NDEBUG
27 vk::DebugUtilsObjectNameInfoEXT debug(vk::ObjectType::eShaderModule, (uint64_t) static_cast<VkShaderModule>(shaderModule), shader.name.c_str());
28 context->device.setDebugUtilsObjectNameEXT(debug);
29#endif // !NDEBUG
30
31 return shaderModule;
32}
char * source
Definition: Shader.h:45
size_t size
Definition: Shader.h:47
std::string name
Definition: Shader.h:50

◆ getIndexNumber()

uint32_t VulkanPipelineAbsract::getIndexNumber ( )

Return the indices that should be drawn

Definition at line 188 of file VulkanPipelineAbstract.cpp.

189{
190 return bufferController->getIndiceCount();
191}

◆ init()

virtual void VulkanPipelineAbsract::init ( )
pure virtual

Init process

Implemented in VulkanPipelineWarping, and VulkanPipelineBlending.

◆ updateAllBuffer()

void VulkanPipelineAbsract::updateAllBuffer ( uint32_t  currentImage,
int  view 
)

Update all the buffers

Definition at line 200 of file VulkanPipelineAbstract.cpp.

201{
202 bufferController->updateAllUniformBuffer(currentImage, view);
203}

◆ updateBuffer()

void VulkanPipelineAbsract::updateBuffer ( uint32_t  currentImage,
int  view 
)

Update only the buffers that may have changed

Definition at line 205 of file VulkanPipelineAbstract.cpp.

206{
207 bufferController->updateUniformBuffer(currentImage, view);
208}

Field Documentation

◆ bufferController

std::unique_ptr<BuffersController> VulkanPipelineAbsract::bufferController
protected

Pointer to the BufferController

Definition at line 79 of file VulkanPipelineAbstract.h.

◆ colorAttachmentNb

int VulkanPipelineAbsract::colorAttachmentNb = 0
protected

number of the color attachment that correspond

Definition at line 86 of file VulkanPipelineAbstract.h.

◆ context

VulkanContext* VulkanPipelineAbsract::context = nullptr
protected

Pointer to context

Definition at line 73 of file VulkanPipelineAbstract.h.

◆ depthTest

bool VulkanPipelineAbsract::depthTest = true
protected

true if depth test must be activated

Definition at line 88 of file VulkanPipelineAbstract.h.

◆ depthWrite

bool VulkanPipelineAbsract::depthWrite = true
protected

true if the depth must be written

Definition at line 90 of file VulkanPipelineAbstract.h.

◆ descriptorSetLayout

vk::DescriptorSetLayout VulkanPipelineAbsract::descriptorSetLayout

Descriptor set layoyout corresponding to this pipeline

Definition at line 65 of file VulkanPipelineAbstract.h.

◆ inputId

int VulkanPipelineAbsract::inputId = 0
protected

input camera id

Definition at line 84 of file VulkanPipelineAbstract.h.

◆ pipeline

vk::Pipeline VulkanPipelineAbsract::pipeline

vk::Pipeline object

Definition at line 63 of file VulkanPipelineAbstract.h.

◆ pipelineLayout

vk::PipelineLayout VulkanPipelineAbsract::pipelineLayout

vk::PipelineLayout corresponding to the pipeline

Definition at line 67 of file VulkanPipelineAbstract.h.

◆ renderPass

VulkanRenderPass* VulkanPipelineAbsract::renderPass = nullptr
protected

Pointer to the Vulkan render pass

Definition at line 75 of file VulkanPipelineAbstract.h.

◆ subPass

int VulkanPipelineAbsract::subPass = 0
protected

number of the subpass where this have to be executed

Definition at line 82 of file VulkanPipelineAbstract.h.

◆ wrapper

VulkanWrapper* VulkanPipelineAbsract::wrapper = nullptr
protected

Pointer to the Vulkanwrapper

Definition at line 77 of file VulkanPipelineAbstract.h.


The documentation for this class was generated from the following files: