| 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/formats.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
17 namespace impeller {
18
19 // These methods should only be used by render_pass_vk.h
20 struct FramebufferAndRenderPass {
21 SharedHandleVK<vk::Framebuffer> framebuffer = nullptr;
22 SharedHandleVK<vk::RenderPass> render_pass = nullptr;
23 };
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 ///
33 class TextureSourceVK {
34 public:
35 virtual ~TextureSourceVK();
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 ///
50 const TextureDescriptor& GetTextureDescriptor() const;
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.
140 void SetCachedFrameData(const FramebufferAndRenderPass& data,
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.
148 const FramebufferAndRenderPass& GetCachedFrameData(
149 SampleCount sample_count) const;
150
151 protected:
152 const TextureDescriptor desc_;
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_
barrier_vk.h
impeller::TextureSourceVK
Abstract base class that represents a vkImage and an vkImageView.
Definition: texture_source_vk.h:33
impeller::TextureSourceVK::TextureSourceVK
TextureSourceVK(TextureDescriptor desc)
Definition: texture_source_vk.cc:9
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::GetImageView
virtual vk::ImageView GetImageView() const =0
Retrieve the image view used for sampling/blitting/compute with this texture source.
impeller::TextureSourceVK::GetCachedFrameData
const FramebufferAndRenderPass & GetCachedFrameData(SampleCount sample_count) const
Definition: texture_source_vk.cc:66
impeller::TextureSourceVK::GetImage
virtual vk::Image GetImage() const =0
Get the image handle for this texture source.
impeller::TextureSourceVK::SetCachedFrameData
void SetCachedFrameData(const FramebufferAndRenderPass &data, SampleCount sample_count)
Definition: texture_source_vk.cc:61
impeller::TextureSourceVK::~TextureSourceVK
virtual ~TextureSourceVK()
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:152
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.h
formats_vk.h
impeller
Definition: allocation.cc:12
impeller::SharedHandleVK
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
Definition: shared_object_vk.h:53
impeller::SampleCount
SampleCount
Definition: formats.h:298
shared_object_vk.h
impeller::BarrierVK
Defines an operations and memory access barrier on a resource.
Definition: barrier_vk.h:27
impeller::FramebufferAndRenderPass
Definition: texture_source_vk.h:20
impeller::FramebufferAndRenderPass::framebuffer
SharedHandleVK< vk::Framebuffer > framebuffer
Definition: texture_source_vk.h:21
impeller::FramebufferAndRenderPass::render_pass
SharedHandleVK< vk::RenderPass > render_pass
Definition: texture_source_vk.h:22
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
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:69
vk.h
yuv_conversion_vk.h