| Flutter Impeller |

render_pass_builder_vk.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_RENDER_PASS_BUILDER_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_RENDER_PASS_BUILDER_VK_H_
7
8 #include <map>
9 #include <optional>
10
11 #include "impeller/core/formats.h"
12 #include "impeller/renderer/backend/vulkan/context_vk.h"
13 #include "impeller/renderer/backend/vulkan/vk.h"
14
15 namespace impeller {
16
17 static constexpr size_t kMaxColorAttachments = 16;
18 static constexpr size_t kMaxAttachments =
19 (kMaxColorAttachments * 2) + 1; // MSAA + resolve plus depth/stencil
20
21 class RenderPassBuilderVK {
22 public:
23 RenderPassBuilderVK();
24
25 ~RenderPassBuilderVK();
26
27 RenderPassBuilderVK(const RenderPassBuilderVK&) = delete;
28
29 RenderPassBuilderVK& operator=(const RenderPassBuilderVK&) = delete;
30
31 RenderPassBuilderVK& SetColorAttachment(
32 size_t index,
33 PixelFormat format,
34 SampleCount sample_count,
35 LoadAction load_action,
36 StoreAction store_action,
37 vk::ImageLayout current_layout = vk::ImageLayout::eUndefined,
38 bool is_swapchain = false);
39
40 RenderPassBuilderVK& SetDepthStencilAttachment(PixelFormat format,
41 SampleCount sample_count,
42 LoadAction load_action,
43 StoreAction store_action);
44
45 RenderPassBuilderVK& SetStencilAttachment(PixelFormat format,
46 SampleCount sample_count,
47 LoadAction load_action,
48 StoreAction store_action);
49
50 vk::UniqueRenderPass Build(const vk::Device& device) const;
51
52 // Visible for testing.
53 const std::map<size_t, vk::AttachmentDescription>& GetColorAttachments()
54 const;
55
56 // Visible for testing.
57 const std::map<size_t, vk::AttachmentDescription>& GetResolves() const;
58
59 // Visible for testing.
60 const std::optional<vk::AttachmentDescription>& GetDepthStencil() const;
61
62 // Visible for testing.
63 std::optional<vk::AttachmentDescription> GetColor0() const;
64
65 // Visible for testing.
66 std::optional<vk::AttachmentDescription> GetColor0Resolve() const;
67
68 private:
69 std::optional<vk::AttachmentDescription> color0_;
70 std::optional<vk::AttachmentDescription> color0_resolve_;
71 std::optional<vk::AttachmentDescription> depth_stencil_;
72
73 // Color attachment 0 is stored in the field above and not in these maps.
74 std::map<size_t, vk::AttachmentDescription> colors_;
75 std::map<size_t, vk::AttachmentDescription> resolves_;
76 };
77
78 //------------------------------------------------------------------------------
79 /// @brief Inserts the appropriate barriers to ensure that subsequent
80 /// commands can read from the specified image (itself a framebuffer
81 /// attachment) as an input attachment.
82 ///
83 /// Unlike most barriers, this barrier may only be inserted within a
84 /// Vulkan render-pass.
85 ///
86 /// The type of barrier inserted depends on the subpass setup and
87 /// self-dependencies. Only use this utility method for inserting
88 /// barriers in render passes created by `RenderPassBuilderVK`.
89 ///
90 /// @param[in] buffer The buffer
91 /// @param[in] image The image
92 ///
93 void InsertBarrierForInputAttachmentRead(const vk::CommandBuffer& buffer,
94 const vk::Image& image);
95
96 } // namespace impeller
97
98 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_RENDER_PASS_BUILDER_VK_H_
impeller::RenderPassBuilderVK
Definition: render_pass_builder_vk.h:21
impeller::RenderPassBuilderVK::GetColor0
std::optional< vk::AttachmentDescription > GetColor0() const
Definition: render_pass_builder_vk.cc:290
impeller::RenderPassBuilderVK::SetDepthStencilAttachment
RenderPassBuilderVK & SetDepthStencilAttachment(PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
Definition: render_pass_builder_vk.cc:86
impeller::RenderPassBuilderVK::GetColorAttachments
const std::map< size_t, vk::AttachmentDescription > & GetColorAttachments() const
Definition: render_pass_builder_vk.cc:275
impeller::RenderPassBuilderVK::GetResolves
const std::map< size_t, vk::AttachmentDescription > & GetResolves() const
Definition: render_pass_builder_vk.cc:280
impeller::RenderPassBuilderVK::SetStencilAttachment
RenderPassBuilderVK & SetStencilAttachment(PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
Definition: render_pass_builder_vk.cc:104
impeller::RenderPassBuilderVK::RenderPassBuilderVK
RenderPassBuilderVK()
impeller::RenderPassBuilderVK::GetDepthStencil
const std::optional< vk::AttachmentDescription > & GetDepthStencil() const
Definition: render_pass_builder_vk.cc:285
impeller::RenderPassBuilderVK::operator=
RenderPassBuilderVK & operator=(const RenderPassBuilderVK &)=delete
impeller::RenderPassBuilderVK::SetColorAttachment
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: render_pass_builder_vk.cc:38
impeller::RenderPassBuilderVK::RenderPassBuilderVK
RenderPassBuilderVK(const RenderPassBuilderVK &)=delete
impeller::RenderPassBuilderVK::Build
vk::UniqueRenderPass Build(const vk::Device &device) const
Definition: render_pass_builder_vk.cc:122
impeller::RenderPassBuilderVK::GetColor0Resolve
std::optional< vk::AttachmentDescription > GetColor0Resolve() const
Definition: render_pass_builder_vk.cc:296
impeller::RenderPassBuilderVK::~RenderPassBuilderVK
~RenderPassBuilderVK()
formats.h
impeller
Definition: allocation.cc:12
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::LoadAction
LoadAction
Definition: formats.h:202
impeller::StoreAction
StoreAction
Definition: formats.h:208
impeller::kMaxAttachments
static constexpr size_t kMaxAttachments
Definition: render_pass_builder_vk.h:18
impeller::InsertBarrierForInputAttachmentRead
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...
Definition: render_pass_builder_vk.cc:244
impeller::kMaxColorAttachments
static constexpr size_t kMaxColorAttachments
Definition: render_pass_builder_vk.h:17
impeller::SampleCount
SampleCount
Definition: formats.h:295
context_vk.h
vk.h