| 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)
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 109 of file render_pass_builder_vk.cc.

110 {
111 // This must be less than `VkPhysicalDeviceLimits::maxColorAttachments` but we
112 // are not checking.
113 auto color_attachments_count =
114 colors_.empty() ? 0u : colors_.rbegin()->first + 1u;
115 if (color0_.has_value()) {
116 color_attachments_count++;
117 }
118
119 std::array<vk::AttachmentDescription, kMaxAttachments> attachments;
120 std::array<vk::AttachmentReference, kMaxColorAttachments> color_refs;
121 std::array<vk::AttachmentReference, kMaxColorAttachments> resolve_refs;
122 vk::AttachmentReference depth_stencil_ref = kUnusedAttachmentReference;
123 size_t attachments_index = 0;
124 size_t color_index = 0;
125 size_t resolve_index = 0;
126
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();
133
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();
140 } else {
141 resolve_refs.at(resolve_index++) = kUnusedAttachmentReference;
142 }
143 }
144
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;
151
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;
158 } else {
159 resolve_refs.at(resolve_index++) = kUnusedAttachmentReference;
160 }
161 }
162
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();
167 }
168
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());
176
177 subpass0.setPDepthStencilAttachment(&depth_stencil_ref);
178
179 vk::SubpassDependency self_dep;
180 self_dep.srcSubpass = 0u; // first subpass
181 self_dep.dstSubpass = 0u; // to itself
182 self_dep.srcStageMask = kSelfDependencySrcStageMask;
183 self_dep.srcAccessMask = kSelfDependencySrcAccessMask;
184 self_dep.dstStageMask = kSelfDependencyDstStageMask;
185 self_dep.dstAccessMask = kSelfDependencyDstAccessMask;
186 self_dep.dependencyFlags = kSelfDependencyFlags;
187
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);
193
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);
197 return {};
198 }
199 return std::move(pass);
200 }

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 248 of file render_pass_builder_vk.cc.

249 {
250 return color0_;
251 }

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

## ◆ GetColor0Resolve()

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

Definition at line 254 of file render_pass_builder_vk.cc.

255 {
256 return color0_resolve_;
257 }

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

## ◆ GetColorAttachments()

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

Definition at line 233 of file render_pass_builder_vk.cc.

233 {
234 return colors_;
235 }

## ◆ GetDepthStencil()

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

Definition at line 243 of file render_pass_builder_vk.cc.

243 {
244 return depth_stencil_;
245 }

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

## ◆ GetResolves()

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

Definition at line 238 of file render_pass_builder_vk.cc.

238 {
239 return resolves_;
240 }

## ◆ 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`
| ) |  |

Definition at line 28 of file render_pass_builder_vk.cc.

34 {
35 vk::AttachmentDescription desc;
36 desc.format = ToVKImageFormat(format);
37 desc.samples = ToVKSampleCount(sample_count);
38 desc.loadOp = ToVKAttachmentLoadOp(load_action);
39 desc.storeOp = ToVKAttachmentStoreOp(store_action, false);
40 desc.stencilLoadOp = vk::AttachmentLoadOp::eDontCare;
41 desc.stencilStoreOp = vk::AttachmentStoreOp::eDontCare;
42 if (load_action == LoadAction::kLoad) {
43 desc.initialLayout = current_layout;
44 } else {
45 desc.initialLayout = vk::ImageLayout::eUndefined;
46 }
47 desc.finalLayout = vk::ImageLayout::eGeneral;
48
49 const bool performs_resolves = StoreActionPerformsResolve(store_action);
50 if (index == 0u) {
51 color0_ = desc;
52
53 if (performs_resolves) {
54 desc.storeOp = ToVKAttachmentStoreOp(store_action, true);
55 desc.samples = vk::SampleCountFlagBits::e1;
56 color0_resolve_ = desc;
57 } else {
58 color0_resolve_ = std::nullopt;
59 }
60 } else {
61 colors_[index] = desc;
62 if (performs_resolves) {
63 desc.storeOp = ToVKAttachmentStoreOp(store_action, true);
64 desc.samples = vk::SampleCountFlagBits::e1;
65 resolves_[index] = desc;
66 } else {
67 resolves_.erase(index);
68 }
69 }
70 return *this;
71 }

References 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 73 of file render_pass_builder_vk.cc.

77 {
78 vk::AttachmentDescription desc;
79 desc.format = ToVKImageFormat(format);
80 desc.samples = ToVKSampleCount(sample_count);
81 desc.loadOp = ToVKAttachmentLoadOp(load_action);
82 desc.storeOp = ToVKAttachmentStoreOp(store_action, false);
83 desc.stencilLoadOp = desc.loadOp; // Not separable in Impeller.
84 desc.stencilStoreOp = desc.storeOp; // Not separable in Impeller.
85 desc.initialLayout = vk::ImageLayout::eUndefined;
86 desc.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
87 depth_stencil_ = desc;
88 return *this;
89 }

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 91 of file render_pass_builder_vk.cc.

95 {
96 vk::AttachmentDescription desc;
97 desc.format = ToVKImageFormat(format);
98 desc.samples = ToVKSampleCount(sample_count);
99 desc.loadOp = vk::AttachmentLoadOp::eDontCare;
100 desc.storeOp = vk::AttachmentStoreOp::eDontCare;
101 desc.stencilLoadOp = ToVKAttachmentLoadOp(load_action);
102 desc.stencilStoreOp = ToVKAttachmentStoreOp(store_action, false);
103 desc.initialLayout = vk::ImageLayout::eUndefined;
104 desc.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
105 depth_stencil_ = desc;
106 return *this;
107 }

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

impeller::ToVKSampleCount
constexpr vk::SampleCountFlagBits ToVKSampleCount(SampleCount sample_count)
Definition: formats_vk.h:214
impeller::LoadAction::kLoad
@ kLoad
impeller::kSelfDependencyDstAccessMask
constexpr auto kSelfDependencyDstAccessMask
Definition: render_pass_builder_vk.cc:19
impeller::kSelfDependencySrcStageMask
constexpr auto kSelfDependencySrcStageMask
Definition: render_pass_builder_vk.cc:12
impeller::kSelfDependencyFlags
constexpr auto kSelfDependencyFlags
Definition: render_pass_builder_vk.cc:22
impeller::ToVKAttachmentStoreOp
constexpr vk::AttachmentStoreOp ToVKAttachmentStoreOp(StoreAction store_action, bool is_resolve_texture)
Definition: formats_vk.h:319
impeller::ToVKImageFormat
constexpr vk::Format ToVKImageFormat(PixelFormat format)
Definition: formats_vk.h:146
impeller::kSelfDependencyDstStageMask
constexpr auto kSelfDependencyDstStageMask
Definition: render_pass_builder_vk.cc:17
impeller::ToVKAttachmentLoadOp
constexpr vk::AttachmentLoadOp ToVKAttachmentLoadOp(LoadAction load_action)
Definition: formats_vk.h:306
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
impeller::kUnusedAttachmentReference
static constexpr vk::AttachmentReference kUnusedAttachmentReference
Definition: formats_vk.h:438
impeller::kSelfDependencySrcAccessMask
constexpr auto kSelfDependencySrcAccessMask
Definition: render_pass_builder_vk.cc:14
impeller::StoreActionPerformsResolve
constexpr bool StoreActionPerformsResolve(StoreAction store_action)
Definition: formats_vk.h:343