Flutter Impeller
texture_source_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_TEXTURE_SOURCE_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_TEXTURE_SOURCE_VK_H_
7 
8 #include "flutter/fml/status.h"
15 
16 namespace impeller {
17 
18 //------------------------------------------------------------------------------
19 /// @brief Abstract base class that represents a vkImage and an
20 /// vkImageView.
21 ///
22 /// This is intended to be used with an impeller::TextureVK. Example
23 /// implementations represent swapchain images, uploaded textures,
24 /// Android Hardware Buffer backend textures, etc...
25 ///
27  public:
28  virtual ~TextureSourceVK();
29 
30  //----------------------------------------------------------------------------
31  /// @brief Gets the texture descriptor for this image source.
32  ///
33  /// @warning Texture descriptors from texture sources whose capabilities
34  /// are a superset of those that can be expressed with Vulkan
35  /// (like Android Hardware Buffer) are inferred. Stuff like size,
36  /// mip-counts, types is reliable. So use these descriptors as
37  /// advisory. Creating copies of texture sources from these
38  /// descriptors is usually not possible and depends on the
39  /// allocator used.
40  ///
41  /// @return The texture descriptor.
42  ///
44 
45  //----------------------------------------------------------------------------
46  /// @brief Get the image handle for this texture source.
47  ///
48  /// @return The image.
49  ///
50  virtual vk::Image GetImage() const = 0;
51 
52  //----------------------------------------------------------------------------
53  /// @brief Retrieve the image view used for sampling/blitting/compute
54  /// with this texture source.
55  ///
56  /// @return The image view.
57  ///
58  virtual vk::ImageView GetImageView() const = 0;
59 
60  //----------------------------------------------------------------------------
61  /// @brief Retrieve the image view used for render target attachments
62  /// with this texture source.
63  ///
64  /// ImageViews used as render target attachments cannot have any
65  /// mip levels. In cases where we want to generate mipmaps with
66  /// the result of this texture, we need to create multiple image
67  /// views.
68  ///
69  /// @return The render target view.
70  ///
71  virtual vk::ImageView GetRenderTargetView() const = 0;
72 
73  //----------------------------------------------------------------------------
74  /// @brief Encodes the layout transition `barrier` to
75  /// `barrier.cmd_buffer` for the image.
76  ///
77  /// The transition is from the layout stored via
78  /// `SetLayoutWithoutEncoding` to `barrier.new_layout`.
79  ///
80  /// @param[in] barrier The barrier.
81  ///
82  /// @return If the layout transition was successfully made.
83  ///
84  fml::Status SetLayout(const BarrierVK& barrier) const;
85 
86  //----------------------------------------------------------------------------
87  /// @brief Store the layout of the image.
88  ///
89  /// This just is bookkeeping on the CPU, to actually set the
90  /// layout use `SetLayout`.
91  ///
92  /// @param[in] layout The new layout.
93  ///
94  /// @return The old layout.
95  ///
96  vk::ImageLayout SetLayoutWithoutEncoding(vk::ImageLayout layout) const;
97 
98  //----------------------------------------------------------------------------
99  /// @brief Get the last layout assigned to the TextureSourceVK.
100  ///
101  /// This value is synchronized with the GPU via SetLayout so it
102  /// may not reflect the actual layout.
103  ///
104  /// @return The last known layout of the texture source.
105  ///
106  vk::ImageLayout GetLayout() const;
107 
108  //----------------------------------------------------------------------------
109  /// @brief When sampling from textures whose formats are not known to
110  /// Vulkan, a custom conversion is necessary to setup custom
111  /// samplers. This accessor provides this conversion if one is
112  /// present. Most texture source have none.
113  ///
114  /// @return The sampler conversion.
115  ///
116  virtual std::shared_ptr<YUVConversionVK> GetYUVConversion() const;
117 
118  //----------------------------------------------------------------------------
119  /// @brief Determines if swapchain image. That is, an image used as the
120  /// root render target.
121  ///
122  /// @return Whether or not this is a swapchain image.
123  ///
124  virtual bool IsSwapchainImage() const = 0;
125 
126  // These methods should only be used by render_pass_vk.h
127 
128  /// Store the last framebuffer object used with this texture.
129  ///
130  /// This field is only set if this texture is used as the resolve texture
131  /// of a render pass. By construction, this framebuffer should be compatible
132  /// with any future render passes.
133  void SetCachedFramebuffer(const SharedHandleVK<vk::Framebuffer>& framebuffer);
134 
135  /// Store the last render pass object used with this texture.
136  ///
137  /// This field is only set if this texture is used as the resolve texture
138  /// of a render pass. By construction, this framebuffer should be compatible
139  /// with any future render passes.
140  void SetCachedRenderPass(const SharedHandleVK<vk::RenderPass>& render_pass);
141 
142  /// Retrieve the last framebuffer object used with this texture.
143  ///
144  /// May be nullptr if no previous framebuffer existed.
146 
147  /// Retrieve the last render pass object used with this texture.
148  ///
149  /// May be nullptr if no previous render pass existed.
151 
152  protected:
154 
155  explicit TextureSourceVK(TextureDescriptor desc);
156 
157  private:
158  SharedHandleVK<vk::Framebuffer> framebuffer_;
159  SharedHandleVK<vk::RenderPass> render_pass_;
160  mutable vk::ImageLayout layout_ = vk::ImageLayout::eUndefined;
161 };
162 
163 } // namespace impeller
164 
165 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_TEXTURE_SOURCE_VK_H_
Abstract base class that represents a vkImage and an vkImageView.
TextureSourceVK(TextureDescriptor desc)
void SetCachedRenderPass(const SharedHandleVK< vk::RenderPass > &render_pass)
virtual std::shared_ptr< YUVConversionVK > GetYUVConversion() const
When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary t...
virtual vk::ImageView GetRenderTargetView() const =0
Retrieve the image view used for render target attachments with this texture source.
virtual bool IsSwapchainImage() const =0
Determines if swapchain image. That is, an image used as the root render target.
const TextureDescriptor & GetTextureDescriptor() const
Gets the texture descriptor for this image source.
SharedHandleVK< vk::Framebuffer > GetCachedFramebuffer() const
virtual vk::ImageView GetImageView() const =0
Retrieve the image view used for sampling/blitting/compute with this texture source.
virtual vk::Image GetImage() const =0
Get the image handle for this texture source.
void SetCachedFramebuffer(const SharedHandleVK< vk::Framebuffer > &framebuffer)
SharedHandleVK< vk::RenderPass > GetCachedRenderPass() const
vk::ImageLayout GetLayout() const
Get the last layout assigned to the TextureSourceVK.
vk::ImageLayout SetLayoutWithoutEncoding(vk::ImageLayout layout) const
Store the layout of the image.
const TextureDescriptor desc_
fml::Status SetLayout(const BarrierVK &barrier) const
Encodes the layout transition barrier to barrier.cmd_buffer for the image.
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
Defines an operations and memory access barrier on a resource.
Definition: barrier_vk.h:27
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...