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