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"
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 
22  public:
24 
26 
28 
30 
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 
40  SampleCount sample_count,
41  LoadAction load_action,
42  StoreAction store_action);
43 
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_
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 & 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(const RenderPassBuilderVK &)=delete
vk::UniqueRenderPass Build(const vk::Device &device) const
std::optional< vk::AttachmentDescription > GetColor0Resolve() const
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
LoadAction
Definition: formats.h:202
StoreAction
Definition: formats.h:208
static constexpr size_t kMaxAttachments
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...
static constexpr size_t kMaxColorAttachments
SampleCount
Definition: formats.h:295