SpiecsEngine
 
Loading...
Searching...
No Matches
RendererPass.cpp
Go to the documentation of this file.
1/**
2* @file RendererPass.cpp
3* @brief The RendererPass Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
8#include "RendererPass.h"
9#include "Render/Vulkan/VulkanRenderBackend.h"
10#include "Render/Renderer/DescriptorSetManager/DescriptorSetManager.h"
11
12namespace Spices {
13
15 {
17
18 m_SubPasses->for_each([&](const std::string& name, const std::shared_ptr<RendererSubPass>& subpass) {
19 const String2 s2(m_PassName, name);
20 DescriptorSetManager::UnLoad(s2);
21 return false;
22 });
23 }
24
26 const std::string& subPassName ,
27 uint32_t index ,
29 ) const
30 {
32
33 if (m_SubPasses->has_key(subPassName))
34 {
35 std::stringstream ss;
36 ss << "RendererPass: " << m_PassName << ": SubPass: " << subPassName << " already added.";
37
38 SPICES_CORE_WARN(ss.str());
39 return nullptr;
40 }
41
42 auto ptr = std::make_shared<RendererSubPass>(subPassName, index, flags);
43 m_SubPasses->push_back(subPassName, ptr);
44 return ptr;
45 }
46
48 const std::string& attachmentName ,
49 const VkAttachmentDescription& description ,
50 uint32_t layers ,
51 const VkClearValue& clearValue
52 )
53 {
55
56 if (m_AttachmentDescriptions.has_key(attachmentName))
57 {
58 uint32_t index = 0;
59 m_AttachmentDescriptions.for_each([&](const auto& K, const auto& V) {
60 if (K == attachmentName)
61 {
62 return true;
63 }
64 else
65 {
66 index++;
67 return false;
68 }
69 });
70 return index;
71 }
72
73 if (attachmentName == "SwapChainImage")
74 {
76 }
77
78 m_MaxLayers = glm::max(m_MaxLayers, layers);
79 m_ClearValues.push_back(clearValue);
80 m_AttachmentDescriptions.push_back(attachmentName, description);
81
82 return static_cast<uint32_t>(m_AttachmentDescriptions.size() - 1);
83 }
84
86 const std::string& attachmentName ,
87 const VkAttachmentDescription& description ,
88 const VkClearValue& clearValue ,
89 uint32_t layers ,
90 const VkImageView& view
91 )
92 {
94
95 if (m_AttachmentDescriptions.has_key(attachmentName))
96 {
97 uint32_t index = 0;
98 m_AttachmentDescriptions.for_each([&](const auto& K, const auto& V) {
99 if (K == attachmentName)
100 {
101 return true;
102 }
103 else
104 {
105 index++;
106 return false;
107 }
108 });
109 return index;
110 }
111
112 if (attachmentName == "SwapChainImage")
113 {
115 }
116
117 m_MaxLayers = glm::max(m_MaxLayers, layers);
118 m_ClearValues.push_back(clearValue);
119 m_AttachmentDescriptions.push_back(attachmentName, description);
120 m_ImageViews.push_back(view);
121
122 return static_cast<uint32_t>(m_AttachmentDescriptions.size() - 1);
123 }
124
126 {
128
129 std::vector<VkAttachmentDescription> attachmentDescription;
130 m_AttachmentDescriptions.for_each([&](const std::string& name, const VkAttachmentDescription& description) {
131 attachmentDescription.push_back(description);
132 return false;
133 });
134
135 std::vector<VkSubpassDescription> subPassDescription;
136 m_SubPasses->for_each([&](const std::string& name, const std::shared_ptr<RendererSubPass>& subpass) {
137 subPassDescription.push_back(subpass->GetDescription());
138 return false;
139 });
140
141 std::vector<VkSubpassDependency> subPassDependency;
142 (*m_SubPasses->first())->AddFirstSubPassDependency();
143 m_SubPasses->for_each([&](const std::string& name, const std::shared_ptr<RendererSubPass>& subpass) {
144 subPassDependency.insert(subPassDependency.end(), subpass->GetDependency().begin(), subpass->GetDependency().end());
145 return false;
146 });
147
148 VkSubpassDependency outDependency{};
149 outDependency.srcSubpass = static_cast<uint32_t>(m_SubPasses->size() - 1);
150 outDependency.dstSubpass = VK_SUBPASS_EXTERNAL;
151 outDependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
152 outDependency.dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
153 outDependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
154 outDependency.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
155 outDependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
156
157 subPassDependency.push_back(outDependency);
158
159 VkRenderPassCreateInfo renderPassInfo{};
160 renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
161 renderPassInfo.attachmentCount = static_cast<uint32_t>(attachmentDescription.size());
162 renderPassInfo.pAttachments = attachmentDescription.data();
163 renderPassInfo.subpassCount = static_cast<uint32_t>(subPassDescription.size());
164 renderPassInfo.pSubpasses = subPassDescription.data();
165 renderPassInfo.dependencyCount = static_cast<uint32_t>(subPassDependency.size());
166 renderPassInfo.pDependencies = subPassDependency.data();
167
168 if (m_AttachmentDescriptions.size() != m_ImageViews.size() + 1 && m_AttachmentDescriptions.size() != m_ImageViews.size())
169 {
170 std::stringstream ss;
171 ss << m_PassName << ": RendererPss Create Failed: Not enough imageview for attachment.";
172
173 SPICES_CORE_ERROR(ss.str())
174 }
175
176 m_RenderPass = std::make_unique<VulkanRenderPass>(
177 VulkanRenderBackend::GetState(),
178 m_PassName,
179 m_Device,
180 renderPassInfo,
181 m_ImageViews,
182 m_MaxLayers,
183 m_IsSwapChainImageInUse
184 );
185 }
186}
#define SPICES_PROFILE_ZONE
uint32_t StatisticsFlags
Definition Querier.h:32
Basic interface of Queries.
Definition Querier.h:17
std::shared_ptr< RendererSubPass > AddSubPass(const std::string &subPassName, uint32_t index, Querier::StatisticsFlags flags) const
Add a subp ass to this renderer pass.
uint32_t AddAttachment(const std::string &attachmentName, const VkAttachmentDescription &description, const VkClearValue &clearValue, uint32_t layers, const VkImageView &view)
Add a attachment to this renderer pass.
uint32_t AddAttachment(const std::string &attachmentName, const VkAttachmentDescription &description, uint32_t layers, const VkClearValue &clearValue)
Add a attachment to this renderer pass.
std::string m_PassName
RenderPass's name.
void BuildRendererPass()
Build RenderPass.
bool m_IsSwapChainImageInUse
True if the RendererPass is using swapchain image.
This class is a wrapper of VulkanRenderPass. Used during Renderer.
This Class Combines some data relative to sub pass. Usually as a member variable of RendererPass.