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