13 vk::PipelineStageFlagBits::eColorAttachmentOutput;
15 vk::AccessFlagBits::eColorAttachmentWrite;
18 vk::PipelineStageFlagBits::eFragmentShader;
20 vk::AccessFlagBits::eInputAttachmentRead;
34 vk::ImageLayout current_layout) {
35 vk::AttachmentDescription desc;
40 desc.stencilLoadOp = vk::AttachmentLoadOp::eDontCare;
41 desc.stencilStoreOp = vk::AttachmentStoreOp::eDontCare;
43 desc.initialLayout = current_layout;
45 desc.initialLayout = vk::ImageLayout::eUndefined;
47 desc.finalLayout = vk::ImageLayout::eGeneral;
53 if (performs_resolves) {
55 desc.samples = vk::SampleCountFlagBits::e1;
56 color0_resolve_ = desc;
58 color0_resolve_ = std::nullopt;
61 colors_[index] = desc;
62 if (performs_resolves) {
64 desc.samples = vk::SampleCountFlagBits::e1;
65 resolves_[index] = desc;
67 resolves_.erase(index);
78 vk::AttachmentDescription desc;
83 desc.stencilLoadOp = desc.loadOp;
84 desc.stencilStoreOp = desc.storeOp;
85 desc.initialLayout = vk::ImageLayout::eUndefined;
86 desc.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
87 depth_stencil_ = desc;
96 vk::AttachmentDescription desc;
99 desc.loadOp = vk::AttachmentLoadOp::eDontCare;
100 desc.storeOp = vk::AttachmentStoreOp::eDontCare;
103 desc.initialLayout = vk::ImageLayout::eUndefined;
104 desc.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
105 depth_stencil_ = desc;
110 const vk::Device& device)
const {
113 auto color_attachments_count =
114 colors_.empty() ? 0u : colors_.rbegin()->first + 1u;
115 if (color0_.has_value()) {
116 color_attachments_count++;
119 std::array<vk::AttachmentDescription, kMaxAttachments> attachments;
120 std::array<vk::AttachmentReference, kMaxColorAttachments> color_refs;
121 std::array<vk::AttachmentReference, kMaxColorAttachments> resolve_refs;
123 size_t attachments_index = 0;
124 size_t color_index = 0;
125 size_t resolve_index = 0;
127 if (color0_.has_value()) {
128 vk::AttachmentReference color_ref;
129 color_ref.attachment = attachments_index;
130 color_ref.layout = vk::ImageLayout::eGeneral;
131 color_refs.at(color_index++) = color_ref;
132 attachments.at(attachments_index++) = color0_.value();
134 if (color0_resolve_.has_value()) {
135 vk::AttachmentReference resolve_ref;
136 resolve_ref.attachment = attachments_index;
137 resolve_ref.layout = vk::ImageLayout::eGeneral;
138 resolve_refs.at(resolve_index++) = resolve_ref;
139 attachments.at(attachments_index++) = color0_resolve_.value();
145 for (
const auto& color : colors_) {
146 vk::AttachmentReference color_ref;
147 color_ref.attachment = attachments_index;
148 color_ref.layout = vk::ImageLayout::eGeneral;
149 color_refs.at(color_index++) = color_ref;
150 attachments.at(attachments_index++) = color.second;
152 if (
auto found = resolves_.find(color.first); found != resolves_.end()) {
153 vk::AttachmentReference resolve_ref;
154 resolve_ref.attachment = attachments_index;
155 resolve_ref.layout = vk::ImageLayout::eGeneral;
156 resolve_refs.at(resolve_index++) = resolve_ref;
157 attachments.at(attachments_index++) = found->second;
163 if (depth_stencil_.has_value()) {
164 depth_stencil_ref.attachment = attachments_index;
165 depth_stencil_ref.layout = vk::ImageLayout::eGeneral;
166 attachments.at(attachments_index++) = depth_stencil_.value();
169 vk::SubpassDescription subpass0;
170 subpass0.pipelineBindPoint = vk::PipelineBindPoint::eGraphics;
171 subpass0.setPInputAttachments(color_refs.data());
172 subpass0.setInputAttachmentCount(color_index);
173 subpass0.setPColorAttachments(color_refs.data());
174 subpass0.setColorAttachmentCount(color_index);
175 subpass0.setPResolveAttachments(resolve_refs.data());
177 subpass0.setPDepthStencilAttachment(&depth_stencil_ref);
179 vk::SubpassDependency self_dep;
180 self_dep.srcSubpass = 0u;
181 self_dep.dstSubpass = 0u;
188 vk::RenderPassCreateInfo render_pass_desc;
189 render_pass_desc.setPAttachments(attachments.data());
190 render_pass_desc.setAttachmentCount(attachments_index);
191 render_pass_desc.setSubpasses(subpass0);
192 render_pass_desc.setDependencies(self_dep);
194 auto [result, pass] = device.createRenderPassUnique(render_pass_desc);
195 if (result != vk::Result::eSuccess) {
196 VALIDATION_LOG <<
"Failed to create render pass: " << vk::to_string(result);
199 return std::move(pass);
203 const vk::Image& image) {
206 vk::ImageMemoryBarrier barrier;
209 barrier.oldLayout = vk::ImageLayout::eGeneral;
210 barrier.newLayout = vk::ImageLayout::eGeneral;
211 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
212 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
213 barrier.image = image;
215 vk::ImageSubresourceRange image_levels;
216 image_levels.aspectMask = vk::ImageAspectFlagBits::eColor;
217 image_levels.baseArrayLayer = 0u;
218 image_levels.baseMipLevel = 0u;
219 image_levels.layerCount = VK_REMAINING_ARRAY_LAYERS;
220 image_levels.levelCount = VK_REMAINING_MIP_LEVELS;
221 barrier.subresourceRange = image_levels;
232 const std::map<size_t, vk::AttachmentDescription>&
237 const std::map<size_t, vk::AttachmentDescription>&
242 const std::optional<vk::AttachmentDescription>&
244 return depth_stencil_;
256 return color0_resolve_;
std::optional< vk::AttachmentDescription > GetColor0() const
RenderPassBuilderVK & SetDepthStencilAttachment(PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
const std::map< size_t, vk::AttachmentDescription > & GetColorAttachments() const
const std::map< size_t, vk::AttachmentDescription > & GetResolves() const
RenderPassBuilderVK & SetStencilAttachment(PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
const std::optional< vk::AttachmentDescription > & GetDepthStencil() const
RenderPassBuilderVK & SetColorAttachment(size_t index, PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action, vk::ImageLayout current_layout=vk::ImageLayout::eUndefined)
vk::UniqueRenderPass Build(const vk::Device &device) const
std::optional< vk::AttachmentDescription > GetColor0Resolve() const
static constexpr vk::AttachmentReference kUnusedAttachmentReference
constexpr auto kSelfDependencyDstAccessMask
constexpr auto kSelfDependencySrcAccessMask
constexpr bool StoreActionPerformsResolve(StoreAction store_action)
constexpr vk::AttachmentLoadOp ToVKAttachmentLoadOp(LoadAction load_action)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
constexpr vk::AttachmentStoreOp ToVKAttachmentStoreOp(StoreAction store_action, bool is_resolve_texture)
constexpr auto kSelfDependencySrcStageMask
constexpr auto kSelfDependencyDstStageMask
constexpr vk::SampleCountFlagBits ToVKSampleCount(SampleCount sample_count)
constexpr vk::Format ToVKImageFormat(PixelFormat format)
constexpr auto kSelfDependencyFlags
void InsertBarrierForInputAttachmentRead(const vk::CommandBuffer &buffer, const vk::Image &image)
Inserts the appropriate barriers to ensure that subsequent commands can read from the specified image...