| 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
39 RenderPassBuilderVK& SetDepthStencilAttachment(PixelFormat format,
40 SampleCount sample_count,
41 LoadAction load_action,
42 StoreAction store_action);
43
44 RenderPassBuilderVK& SetStencilAttachment(PixelFormat format,
45 SampleCount sample_count,
46 LoadAction load_action,
47 StoreAction store_action);
48
49 vk::UniqueRenderPass Build(const vk::Device& device) const;
50
51 // Visible for testing.
52 const std::map<size_t, vk::AttachmentDescription>& GetColorAttachments()
53 const;
54
55 // Visible for testing.
56 const std::map<size_t, vk::AttachmentDescription>& GetResolves() const;
57
58 // Visible for testing.
59 const std::optional<vk::AttachmentDescription>& GetDepthStencil() const;
60
61 // Visible for testing.
62 std::optional<vk::AttachmentDescription> GetColor0() const;
63
64 // Visible for testing.
65 std::optional<vk::AttachmentDescription> GetColor0Resolve() const;
66
67 private:
68 std::optional<vk::AttachmentDescription> color0_;
69 std::optional<vk::AttachmentDescription> color0_resolve_;
70 std::optional<vk::AttachmentDescription> depth_stencil_;
71
72 // Color attachment 0 is stored in the field above and not in these maps.
73 std::map<size_t, vk::AttachmentDescription> colors_;
74 std::map<size_t, vk::AttachmentDescription> resolves_;
75 };
76
77 //------------------------------------------------------------------------------
78 /// @brief Inserts the appropriate barriers to ensure that subsequent
79 /// commands can read from the specified image (itself a framebuffer
80 /// attachment) as an input attachment.
81 ///
82 /// Unlike most barriers, this barrier may only be inserted within a
83 /// Vulkan render-pass.
84 ///
85 /// The type of barrier inserted depends on the subpass setup and
86 /// self-dependencies. Only use this utility method for inserting
87 /// barriers in render passes created by `RenderPassBuilderVK`.
88 ///
89 /// @param[in] buffer The buffer
90 /// @param[in] image The image
91 ///
92 void InsertBarrierForInputAttachmentRead(const vk::CommandBuffer& buffer,
93 const vk::Image& image);
94
95 } // namespace impeller
96
97 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_RENDER_PASS_BUILDER_VK_H_
impeller::StoreAction
StoreAction
Definition: formats.h:208
impeller::RenderPassBuilderVK::SetStencilAttachment
RenderPassBuilderVK & SetStencilAttachment(PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
Definition: render_pass_builder_vk.cc:91
formats.h
impeller::RenderPassBuilderVK
Definition: render_pass_builder_vk.h:21
impeller::RenderPassBuilderVK::GetColorAttachments
const std::map< size_t, vk::AttachmentDescription > & GetColorAttachments() const
Definition: render_pass_builder_vk.cc:233
vk.h
impeller::RenderPassBuilderVK::operator=
RenderPassBuilderVK & operator=(const RenderPassBuilderVK &)=delete
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::RenderPassBuilderVK::SetDepthStencilAttachment
RenderPassBuilderVK & SetDepthStencilAttachment(PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
Definition: render_pass_builder_vk.cc:73
impeller::RenderPassBuilderVK::GetDepthStencil
const std::optional< vk::AttachmentDescription > & GetDepthStencil() const
Definition: render_pass_builder_vk.cc:243
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)
Definition: render_pass_builder_vk.cc:28
impeller::RenderPassBuilderVK::RenderPassBuilderVK
RenderPassBuilderVK()
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:202
impeller::LoadAction
LoadAction
Definition: formats.h:202
impeller::RenderPassBuilderVK::GetResolves
const std::map< size_t, vk::AttachmentDescription > & GetResolves() const
Definition: render_pass_builder_vk.cc:238
impeller::RenderPassBuilderVK::GetColor0Resolve
std::optional< vk::AttachmentDescription > GetColor0Resolve() const
Definition: render_pass_builder_vk.cc:254
impeller::RenderPassBuilderVK::GetColor0
std::optional< vk::AttachmentDescription > GetColor0() const
Definition: render_pass_builder_vk.cc:248
impeller::RenderPassBuilderVK::~RenderPassBuilderVK
~RenderPassBuilderVK()
impeller::kMaxAttachments
static constexpr size_t kMaxAttachments
Definition: render_pass_builder_vk.h:18
impeller::kMaxColorAttachments
static constexpr size_t kMaxColorAttachments
Definition: render_pass_builder_vk.h:17
impeller::SampleCount
SampleCount
Definition: formats.h:295
impeller::RenderPassBuilderVK::Build
vk::UniqueRenderPass Build(const vk::Device &device) const
Definition: render_pass_builder_vk.cc:109
context_vk.h
impeller
Definition: allocation.cc:12