| 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"
9 #include "impeller/core/texture_descriptor.h"
10 #include "impeller/renderer/backend/vulkan/barrier_vk.h"
11 #include "impeller/renderer/backend/vulkan/formats_vk.h"
12 #include "impeller/renderer/backend/vulkan/shared_object_vk.h"
13 #include "impeller/renderer/backend/vulkan/vk.h"
14 #include "impeller/renderer/backend/vulkan/yuv_conversion_vk.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 ///
26 class TextureSourceVK {
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 ///
43 const TextureDescriptor& GetTextureDescriptor() const;
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.
145 SharedHandleVK<vk::Framebuffer> GetCachedFramebuffer() const;
146
147 /// Retrieve the last render pass object used with this texture.
148 ///
149 /// May be nullptr if no previous render pass existed.
150 SharedHandleVK<vk::RenderPass> GetCachedRenderPass() const;
151
152 protected:
153 const TextureDescriptor desc_;
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_
barrier_vk.h
impeller::TextureSourceVK
Abstract base class that represents a vkImage and an vkImageView.
Definition: texture_source_vk.h:26
impeller::TextureSourceVK::TextureSourceVK
TextureSourceVK(TextureDescriptor desc)
Definition: texture_source_vk.cc:9
impeller::TextureSourceVK::SetCachedRenderPass
void SetCachedRenderPass(const SharedHandleVK< vk::RenderPass > &render_pass)
Definition: texture_source_vk.cc:64
impeller::TextureSourceVK::GetYUVConversion
virtual std::shared_ptr< YUVConversionVK > GetYUVConversion() const
When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary t...
Definition: texture_source_vk.cc:17
impeller::TextureSourceVK::GetRenderTargetView
virtual vk::ImageView GetRenderTargetView() const =0
Retrieve the image view used for render target attachments with this texture source.
impeller::TextureSourceVK::IsSwapchainImage
virtual bool IsSwapchainImage() const =0
Determines if swapchain image. That is, an image used as the root render target.
impeller::TextureSourceVK::GetTextureDescriptor
const TextureDescriptor & GetTextureDescriptor() const
Gets the texture descriptor for this image source.
Definition: texture_source_vk.cc:13
impeller::TextureSourceVK::GetCachedFramebuffer
SharedHandleVK< vk::Framebuffer > GetCachedFramebuffer() const
Definition: texture_source_vk.cc:69
impeller::TextureSourceVK::GetImageView
virtual vk::ImageView GetImageView() const =0
Retrieve the image view used for sampling/blitting/compute with this texture source.
impeller::TextureSourceVK::GetImage
virtual vk::Image GetImage() const =0
Get the image handle for this texture source.
impeller::TextureSourceVK::SetCachedFramebuffer
void SetCachedFramebuffer(const SharedHandleVK< vk::Framebuffer > &framebuffer)
Definition: texture_source_vk.cc:59
impeller::TextureSourceVK::~TextureSourceVK
virtual ~TextureSourceVK()
impeller::TextureSourceVK::GetCachedRenderPass
SharedHandleVK< vk::RenderPass > GetCachedRenderPass() const
Definition: texture_source_vk.cc:73
impeller::TextureSourceVK::GetLayout
vk::ImageLayout GetLayout() const
Get the last layout assigned to the TextureSourceVK.
Definition: texture_source_vk.cc:21
impeller::TextureSourceVK::SetLayoutWithoutEncoding
vk::ImageLayout SetLayoutWithoutEncoding(vk::ImageLayout layout) const
Store the layout of the image.
Definition: texture_source_vk.cc:25
impeller::TextureSourceVK::desc_
const TextureDescriptor desc_
Definition: texture_source_vk.h:153
impeller::TextureSourceVK::SetLayout
fml::Status SetLayout(const BarrierVK &barrier) const
Encodes the layout transition barrier to barrier.cmd_buffer for the image.
Definition: texture_source_vk.cc:32
formats_vk.h
impeller
Definition: allocation.cc:12
impeller::SharedHandleVK
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
Definition: shared_object_vk.h:53
shared_object_vk.h
impeller::BarrierVK
Defines an operations and memory access barrier on a resource.
Definition: barrier_vk.h:27
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
texture_descriptor.h
vk.h
yuv_conversion_vk.h