Mandrill 2025.6.0
Loading...
Searching...
No Matches
Pass.h
1#pragma once
2
3#include "Common.h"
4
5#include "Device.h"
6#include "Swapchain.h"
7
8namespace Mandrill
9{
16 class Pass
17 {
18 public:
19 MANDRILL_NON_COPYABLE(Pass)
20
21
27 MANDRILL_API Pass(ptr<Device> pDevice, std::vector<ptr<Image>> colorAttachments, ptr<Image> pDepthAttachment);
28
40 MANDRILL_API Pass(ptr<Device> pDevice, VkExtent2D extent, VkFormat format, uint32_t colorAttachmentCount = 1,
41 bool depthAttachment = true, VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT);
42
53 MANDRILL_API Pass(ptr<Device> pDevice, VkExtent2D extent, std::vector<VkFormat> formats,
54 bool depthAttachment = true, VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT);
55
60 MANDRILL_API ~Pass();
61
68 MANDRILL_API void transitionForRendering(VkCommandBuffer cmd, ptr<Image> pImage) const;
69
77 MANDRILL_API void transitionForBlitting(VkCommandBuffer cmd, ptr<Image> pImage) const;
78
84 MANDRILL_API void begin(VkCommandBuffer cmd);
85
93 MANDRILL_API void begin(VkCommandBuffer cmd, glm::vec4 clearColor,
94 VkAttachmentLoadOp loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR);
95
103 MANDRILL_API void begin(VkCommandBuffer cmd, ptr<Image> pImage);
104
110 MANDRILL_API void end(VkCommandBuffer cmd) const;
111
118 MANDRILL_API void end(VkCommandBuffer cmd, ptr<Image> pImage) const;
119
126 MANDRILL_API void update(std::vector<ptr<Image>> colorAttachments, ptr<Image> pDepthAttachment);
127
133 MANDRILL_API void update(VkExtent2D extent);
134
139 MANDRILL_API VkPipelineRenderingCreateInfo getPipelineRenderingCreateInfo() const
140 {
141 return mPipelineRenderingCreateInfo;
142 }
143
148 MANDRILL_API const std::vector<ptr<Image>>& getColorAttachments() const
149 {
150 return mColorAttachments;
151 }
152
158 MANDRILL_API ptr<Image> getOutput() const
159 {
160 return mpResolveAttachment ? mpResolveAttachment : mColorAttachments[0];
161 }
162
167 MANDRILL_API VkExtent2D getExtent() const
168 {
169 return mExtent;
170 }
171
177 MANDRILL_API VkSampleCountFlagBits getSampleCount() const
178 {
179 return mpResolveAttachment ? mpDevice->getSampleCount() : VK_SAMPLE_COUNT_1_BIT;
180 }
181
182 private:
183 void createExplicitPass(std::vector<ptr<Image>> colorAttachments, ptr<Image> depthAttachment);
184 void createImplicitPass(bool depthAttachment, VkSampleCountFlagBits sampleCount);
185
186 ptr<Device> mpDevice;
187
188 VkPipelineRenderingCreateInfo mPipelineRenderingCreateInfo;
189 VkExtent2D mExtent;
190
191 std::vector<VkFormat> mFormats;
192
193 bool mImplicitAttachments;
194 std::vector<ptr<Image>> mColorAttachments;
195 ptr<Image> mpDepthAttachment;
196 ptr<Image> mpResolveAttachment;
197 };
198} // namespace Mandrill
Pass class that abstracts the use of dynamic rendering (no render passes) in Vulkan....
Definition Pass.h:17
MANDRILL_API void transitionForRendering(VkCommandBuffer cmd, ptr< Image > pImage) const
Transition an image for rendering. Call before begin() in an explicit pass.
Definition Pass.cpp:32
MANDRILL_API void update(std::vector< ptr< Image > > colorAttachments, ptr< Image > pDepthAttachment)
Update an explicit pass with new attachments. Typically call on swapchain recreation.
Definition Pass.cpp:183
MANDRILL_API void transitionForBlitting(VkCommandBuffer cmd, ptr< Image > pImage) const
Transition an image for blitting. Call after end() and before Swapchain::present(....
Definition Pass.cpp:40
MANDRILL_API VkPipelineRenderingCreateInfo getPipelineRenderingCreateInfo() const
Get the pipeline rendering create info. This is needed for pipeline creation when using dynamic rende...
Definition Pass.h:139
MANDRILL_API void begin(VkCommandBuffer cmd)
Begin a pass without clearing the color attachments.
Definition Pass.cpp:48
MANDRILL_API void end(VkCommandBuffer cmd) const
End a pass.
Definition Pass.cpp:161
MANDRILL_API const std::vector< ptr< Image > > & getColorAttachments() const
Get the list of color attachments of the pass.
Definition Pass.h:148
MANDRILL_API ~Pass()
Destructor for pass.
Definition Pass.cpp:28
MANDRILL_API ptr< Image > getOutput() const
Get the output image of the pass. If multi-sampling was used, the resolve images is returned,...
Definition Pass.h:158
MANDRILL_API VkSampleCountFlagBits getSampleCount() const
Get the sample count of the pass. If VK_SAMPLE_COUNT_1_BIT is set, that means that there is no resolv...
Definition Pass.h:177
MANDRILL_API VkExtent2D getExtent() const
Get the extent of the pass.
Definition Pass.h:167