| Flutter Impeller |

Public Member Functions | List of all members
impeller::RenderPassBuilderVK Class Reference

`#include <render_pass_builder_vk.h>`

## Public Member Functions
| RenderPassBuilderVK ()
| ~RenderPassBuilderVK ()
| RenderPassBuilderVK (const RenderPassBuilderVK &)=delete
RenderPassBuilderVK & | operator= (const RenderPassBuilderVK &)=delete
RenderPassBuilderVK & | SetColorAttachment (size_t index, PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action, vk::ImageLayout current_layout=vk::ImageLayout::eUndefined, bool is_swapchain=false)
RenderPassBuilderVK & | SetDepthStencilAttachment (PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
RenderPassBuilderVK & | SetStencilAttachment (PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
vk::UniqueRenderPass | Build (const vk::Device &device) const
const std::map< size_t, vk::AttachmentDescription > & | GetColorAttachments () const
const std::map< size_t, vk::AttachmentDescription > & | GetResolves () const
const std::optional< vk::AttachmentDescription > & | GetDepthStencil () const
std::optional< vk::AttachmentDescription > | GetColor0 () const
std::optional< vk::AttachmentDescription > | GetColor0Resolve () const

## Detailed Description

Definition at line 21 of file render_pass_builder_vk.h.

## Constructor & Destructor Documentation

## ◆ RenderPassBuilderVK() [1/2]

impeller::RenderPassBuilderVK::RenderPassBuilderVK | ( |  | ) |
| default

## ◆ ~RenderPassBuilderVK()

impeller::RenderPassBuilderVK::~RenderPassBuilderVK | ( |  | ) |
| default

## ◆ RenderPassBuilderVK() [2/2]

impeller::RenderPassBuilderVK::RenderPassBuilderVK | ( | const RenderPassBuilderVK & |  | ) |
| delete

## Member Function Documentation

## ◆ Build()

vk::UniqueRenderPass impeller::RenderPassBuilderVK::Build | ( | const vk::Device & | device | ) | const

Definition at line 122 of file render_pass_builder_vk.cc.

123 {
124 // This must be less than `VkPhysicalDeviceLimits::maxColorAttachments` but we
125 // are not checking.
126 auto color_attachments_count =
127 colors_.empty() ? 0u : colors_.rbegin()->first + 1u;
128 if (color0_.has_value()) {
129 color_attachments_count++;
130 }
131
132 std::array<vk::AttachmentDescription, kMaxAttachments> attachments;
133 std::array<vk::AttachmentReference, kMaxColorAttachments> color_refs;
134 std::array<vk::AttachmentReference, kMaxColorAttachments> resolve_refs;
135 vk::AttachmentReference depth_stencil_ref = kUnusedAttachmentReference;
136 size_t attachments_index = 0;
137 size_t color_index = 0;
138 size_t resolve_index = 0;
139
140 if (color0_.has_value()) {
141 vk::AttachmentReference color_ref;
142 color_ref.attachment = attachments_index;
143 color_ref.layout = vk::ImageLayout::eGeneral;
144 color_refs.at(color_index++) = color_ref;
145 attachments.at(attachments_index++) = color0_.value();
146
147 if (color0_resolve_.has_value()) {
148 vk::AttachmentReference resolve_ref;
149 resolve_ref.attachment = attachments_index;
150 resolve_ref.layout = vk::ImageLayout::eGeneral;
151 resolve_refs.at(resolve_index++) = resolve_ref;
152 attachments.at(attachments_index++) = color0_resolve_.value();
153 } else {
154 resolve_refs.at(resolve_index++) = kUnusedAttachmentReference;
155 }
156 }
157
158 for (const auto& color : colors_) {
159 vk::AttachmentReference color_ref;
160 color_ref.attachment = attachments_index;
161 color_ref.layout = vk::ImageLayout::eGeneral;
162 color_refs.at(color_index++) = color_ref;
163 attachments.at(attachments_index++) = color.second;
164
165 if (auto found = resolves_.find(color.first); found != resolves_.end()) {
166 vk::AttachmentReference resolve_ref;
167 resolve_ref.attachment = attachments_index;
168 resolve_ref.layout = vk::ImageLayout::eGeneral;
169 resolve_refs.at(resolve_index++) = resolve_ref;
170 attachments.at(attachments_index++) = found->second;
171 } else {
172 resolve_refs.at(resolve_index++) = kUnusedAttachmentReference;
173 }
174 }
175
176 if (depth_stencil_.has_value()) {
177 depth_stencil_ref.attachment = attachments_index;
178 depth_stencil_ref.layout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
179 attachments.at(attachments_index++) = depth_stencil_.value();
180 }
181
182 vk::SubpassDescription subpass0;
183 subpass0.pipelineBindPoint = vk::PipelineBindPoint::eGraphics;
184 subpass0.setPInputAttachments(color_refs.data());
185 subpass0.setInputAttachmentCount(color_index);
186 subpass0.setPColorAttachments(color_refs.data());
187 subpass0.setColorAttachmentCount(color_index);
188 subpass0.setPResolveAttachments(resolve_refs.data());
189
190 subpass0.setPDepthStencilAttachment(&depth_stencil_ref);
191
192 vk::SubpassDependency deps[3];
193 // Incoming dependency. If the attachments were previously used
194 // as attachments for a render pass, or sampled from/transfered to,
195 // then these operations must complete before we resolve anything
196 // to the onscreen.
197 deps[0].srcSubpass = VK_SUBPASS_EXTERNAL;
198 deps[0].dstSubpass = 0u;
199 deps[0].srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput |
200 vk::PipelineStageFlagBits::eFragmentShader;
201 deps[0].srcAccessMask = vk::AccessFlagBits::eShaderRead |
202 vk::AccessFlagBits::eColorAttachmentWrite;
203 deps[0].dstStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
204 deps[0].dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
205 deps[0].dependencyFlags = kSelfDependencyFlags;
206
207 // Self dependency for reading back the framebuffer, necessary for
208 // programmable blend support / framebuffer fetch.
209 deps[1].srcSubpass = 0u; // first subpass
210 deps[1].dstSubpass = 0u; // to itself
211 deps[1].srcStageMask = kSelfDependencySrcStageMask;
212 deps[1].srcAccessMask = kSelfDependencySrcAccessMask;
213 deps[1].dstStageMask = kSelfDependencyDstStageMask;
214 deps[1].dstAccessMask = kSelfDependencyDstAccessMask;
215 deps[1].dependencyFlags = kSelfDependencyFlags;
216
217 // Outgoing dependency. The resolve step or color attachment must complete
218 // before we can sample from the image. This dependency is ignored for the
219 // onscreen as we will already insert a barrier before presenting the
220 // swapchain.
221 deps[2].srcSubpass = 0u; // first subpass
222 deps[2].dstSubpass = VK_SUBPASS_EXTERNAL;
223 deps[2].srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
224 deps[2].srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
225 deps[2].dstStageMask = vk::PipelineStageFlagBits::eFragmentShader;
226 deps[2].dstAccessMask = vk::AccessFlagBits::eShaderRead;
227 deps[2].dependencyFlags = kSelfDependencyFlags;
228
229 vk::RenderPassCreateInfo render_pass_desc;
230 render_pass_desc.setPAttachments(attachments.data());
231 render_pass_desc.setAttachmentCount(attachments_index);
232 render_pass_desc.setSubpasses(subpass0);
233 render_pass_desc.setPDependencies(deps);
234 render_pass_desc.setDependencyCount(3);
235
236 auto [result, pass] = device.createRenderPassUnique(render_pass_desc);
237 if (result != vk::Result::eSuccess) {
238 VALIDATION_LOG << "Failed to create render pass: " << vk::to_string(result);
239 return {};
240 }
241 return std::move(pass);
242 }
impeller::kUnusedAttachmentReference
static constexpr vk::AttachmentReference kUnusedAttachmentReference
Definition: formats_vk.h:441
impeller::kSelfDependencyDstAccessMask
constexpr auto kSelfDependencyDstAccessMask
Definition: render_pass_builder_vk.cc:29
impeller::kSelfDependencySrcAccessMask
constexpr auto kSelfDependencySrcAccessMask
Definition: render_pass_builder_vk.cc:24
impeller::kSelfDependencySrcStageMask
constexpr auto kSelfDependencySrcStageMask
Definition: render_pass_builder_vk.cc:22
impeller::kSelfDependencyDstStageMask
constexpr auto kSelfDependencyDstStageMask
Definition: render_pass_builder_vk.cc:27
impeller::kSelfDependencyFlags
constexpr auto kSelfDependencyFlags
Definition: render_pass_builder_vk.cc:32
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::kSelfDependencyDstAccessMask, impeller::kSelfDependencyDstStageMask, impeller::kSelfDependencyFlags, impeller::kSelfDependencySrcAccessMask, impeller::kSelfDependencySrcStageMask, impeller::kUnusedAttachmentReference, and VALIDATION_LOG.

Referenced by impeller::CreateCompatRenderPassForPipeline(), impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded(), and impeller::testing::TEST().

## ◆ GetColor0()

std::optional< vk::AttachmentDescription > impeller::RenderPassBuilderVK::GetColor0 | ( |  | ) | const

Definition at line 290 of file render_pass_builder_vk.cc.

291 {
292 return color0_;
293 }

Referenced by impeller::testing::TEST().

## ◆ GetColor0Resolve()

std::optional< vk::AttachmentDescription > impeller::RenderPassBuilderVK::GetColor0Resolve | ( |  | ) | const

Definition at line 296 of file render_pass_builder_vk.cc.

297 {
298 return color0_resolve_;
299 }

Referenced by impeller::testing::TEST().

## ◆ GetColorAttachments()

const std::map< size_t, vk::AttachmentDescription > & impeller::RenderPassBuilderVK::GetColorAttachments | ( |  | ) | const

Definition at line 275 of file render_pass_builder_vk.cc.

275 {
276 return colors_;
277 }

## ◆ GetDepthStencil()

const std::optional< vk::AttachmentDescription > & impeller::RenderPassBuilderVK::GetDepthStencil | ( |  | ) | const

Definition at line 285 of file render_pass_builder_vk.cc.

285 {
286 return depth_stencil_;
287 }

Referenced by impeller::testing::TEST().

## ◆ GetResolves()

const std::map< size_t, vk::AttachmentDescription > & impeller::RenderPassBuilderVK::GetResolves | ( |  | ) | const

Definition at line 280 of file render_pass_builder_vk.cc.

280 {
281 return resolves_;
282 }

## ◆ operator=()

RenderPassBuilderVK& impeller::RenderPassBuilderVK::operator= | ( | const RenderPassBuilderVK & |  | ) |
| delete

## ◆ SetColorAttachment()

RenderPassBuilderVK & impeller::RenderPassBuilderVK::SetColorAttachment | ( | size_t | index,
|  | PixelFormat | format,
|  | SampleCount | sample_count,
|  | LoadAction | load_action,
|  | StoreAction | store_action,
|  | vk::ImageLayout | current_layout = `vk::ImageLayout::eUndefined`,
|  | bool | is_swapchain = `false`
| ) |  |

Definition at line 38 of file render_pass_builder_vk.cc.

45 {
46 vk::AttachmentDescription desc;
47 desc.format = ToVKImageFormat(format);
48 desc.samples = ToVKSampleCount(sample_count);
49 desc.loadOp = ToVKAttachmentLoadOp(load_action);
50 desc.storeOp = ToVKAttachmentStoreOp(store_action, false);
51 desc.stencilLoadOp = vk::AttachmentLoadOp::eDontCare;
52 desc.stencilStoreOp = vk::AttachmentStoreOp::eDontCare;
53 if (load_action == LoadAction::kLoad) {
54 desc.initialLayout = current_layout;
55 } else {
56 desc.initialLayout = vk::ImageLayout::eUndefined;
57 }
58 desc.finalLayout = ComputeFinalLayout(is_swapchain, sample_count);
59
60 const bool performs_resolves = StoreActionPerformsResolve(store_action);
61 if (index == 0u) {
62 color0_ = desc;
63
64 if (performs_resolves) {
65 desc.storeOp = ToVKAttachmentStoreOp(store_action, true);
66 desc.samples = vk::SampleCountFlagBits::e1;
67 desc.finalLayout = ComputeFinalLayout(is_swapchain, SampleCount::kCount1);
68 color0_resolve_ = desc;
69 } else {
70 color0_resolve_ = std::nullopt;
71 }
72 } else {
73 colors_[index] = desc;
74 if (performs_resolves) {
75 desc.storeOp = ToVKAttachmentStoreOp(store_action, true);
76 desc.samples = vk::SampleCountFlagBits::e1;
77 desc.finalLayout = ComputeFinalLayout(is_swapchain, SampleCount::kCount1);
78 resolves_[index] = desc;
79 } else {
80 resolves_.erase(index);
81 }
82 }
83 return *this;
84 }
e1
Vector3 e1
Definition: line_contents.cc:107
impeller::StoreActionPerformsResolve
constexpr bool StoreActionPerformsResolve(StoreAction store_action)
Definition: formats_vk.h:345
impeller::ToVKAttachmentLoadOp
constexpr vk::AttachmentLoadOp ToVKAttachmentLoadOp(LoadAction load_action)
Definition: formats_vk.h:308
impeller::ToVKAttachmentStoreOp
constexpr vk::AttachmentStoreOp ToVKAttachmentStoreOp(StoreAction store_action, bool is_resolve_texture)
Definition: formats_vk.h:321
impeller::LoadAction::kLoad
@ kLoad
impeller::ToVKSampleCount
constexpr vk::SampleCountFlagBits ToVKSampleCount(SampleCount sample_count)
Definition: formats_vk.h:216
impeller::ToVKImageFormat
constexpr vk::Format ToVKImageFormat(PixelFormat format)
Definition: formats_vk.h:146
impeller::SampleCount::kCount1
@ kCount1

References e1, impeller::kCount1, impeller::kLoad, impeller::StoreActionPerformsResolve(), impeller::ToVKAttachmentLoadOp(), impeller::ToVKAttachmentStoreOp(), impeller::ToVKImageFormat(), and impeller::ToVKSampleCount().

Referenced by impeller::CreateCompatRenderPassForPipeline(), impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded(), and impeller::testing::TEST().

## ◆ SetDepthStencilAttachment()

RenderPassBuilderVK & impeller::RenderPassBuilderVK::SetDepthStencilAttachment | ( | PixelFormat | format,
|  | SampleCount | sample_count,
|  | LoadAction | load_action,
|  | StoreAction | store_action
| ) |  |

Definition at line 86 of file render_pass_builder_vk.cc.

90 {
91 vk::AttachmentDescription desc;
92 desc.format = ToVKImageFormat(format);
93 desc.samples = ToVKSampleCount(sample_count);
94 desc.loadOp = ToVKAttachmentLoadOp(load_action);
95 desc.storeOp = ToVKAttachmentStoreOp(store_action, false);
96 desc.stencilLoadOp = desc.loadOp; // Not separable in Impeller.
97 desc.stencilStoreOp = desc.storeOp; // Not separable in Impeller.
98 desc.initialLayout = vk::ImageLayout::eUndefined;
99 desc.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
100 depth_stencil_ = desc;
101 return *this;
102 }

References impeller::ToVKAttachmentLoadOp(), impeller::ToVKAttachmentStoreOp(), impeller::ToVKImageFormat(), and impeller::ToVKSampleCount().

Referenced by impeller::CreateCompatRenderPassForPipeline(), impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded(), and impeller::testing::TEST().

## ◆ SetStencilAttachment()

RenderPassBuilderVK & impeller::RenderPassBuilderVK::SetStencilAttachment | ( | PixelFormat | format,
|  | SampleCount | sample_count,
|  | LoadAction | load_action,
|  | StoreAction | store_action
| ) |  |

Definition at line 104 of file render_pass_builder_vk.cc.

108 {
109 vk::AttachmentDescription desc;
110 desc.format = ToVKImageFormat(format);
111 desc.samples = ToVKSampleCount(sample_count);
112 desc.loadOp = vk::AttachmentLoadOp::eDontCare;
113 desc.storeOp = vk::AttachmentStoreOp::eDontCare;
114 desc.stencilLoadOp = ToVKAttachmentLoadOp(load_action);
115 desc.stencilStoreOp = ToVKAttachmentStoreOp(store_action, false);
116 desc.initialLayout = vk::ImageLayout::eUndefined;
117 desc.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
118 depth_stencil_ = desc;
119 return *this;
120 }

References impeller::ToVKAttachmentLoadOp(), impeller::ToVKAttachmentStoreOp(), impeller::ToVKImageFormat(), and impeller::ToVKSampleCount().

Referenced by impeller::CreateCompatRenderPassForPipeline(), impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded(), and impeller::testing::TEST().

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

- impeller/renderer/backend/vulkan/render_pass_builder_vk.h
- impeller/renderer/backend/vulkan/render_pass_builder_vk.cc