Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
impeller::TextureVK Class Referencefinal

#include <texture_vk.h>

Inheritance diagram for impeller::TextureVK:
impeller::Texture impeller::BackendCast< TextureVK, Texture >

Public Member Functions

 TextureVK (std::weak_ptr< Context > context, std::shared_ptr< TextureSourceVK > source)
 
 ~TextureVK () override
 
vk::Image GetImage () const
 
vk::ImageView GetImageView () const
 
vk::ImageView GetRenderTargetView () const
 
bool SetLayout (const BarrierVK &barrier) const
 
vk::ImageLayout SetLayoutWithoutEncoding (vk::ImageLayout layout) const
 
vk::ImageLayout GetLayout () const
 
std::shared_ptr< const TextureSourceVKGetTextureSource () const
 
ISize GetSize () const override
 
void SetMipMapGenerated ()
 
bool IsSwapchainImage () const
 
std::shared_ptr< SamplerVKGetImmutableSamplerVariant (const SamplerVK &sampler) const
 
void SetCachedFramebuffer (const SharedHandleVK< vk::Framebuffer > &framebuffer)
 
void SetCachedRenderPass (const SharedHandleVK< vk::RenderPass > &render_pass)
 
SharedHandleVK< vk::Framebuffer > GetCachedFramebuffer () const
 
SharedHandleVK< vk::RenderPass > GetCachedRenderPass () const
 
- Public Member Functions inherited from impeller::Texture
virtual ~Texture ()
 
bool SetContents (const uint8_t *contents, size_t length, size_t slice=0, bool is_opaque=false)
 
bool SetContents (std::shared_ptr< const fml::Mapping > mapping, size_t slice=0, bool is_opaque=false)
 
bool IsOpaque () const
 
size_t GetMipCount () const
 
const TextureDescriptorGetTextureDescriptor () const
 
void SetCoordinateSystem (TextureCoordinateSystem coordinate_system)
 
TextureCoordinateSystem GetCoordinateSystem () const
 
virtual Scalar GetYCoordScale () const
 
bool NeedsMipmapGeneration () const
 

Private Member Functions

void SetLabel (std::string_view label) override
 
bool OnSetContents (const uint8_t *contents, size_t length, size_t slice) override
 
bool OnSetContents (std::shared_ptr< const fml::Mapping > mapping, size_t slice) override
 
bool IsValid () const override
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::BackendCast< TextureVK, Texture >
static TextureVKCast (Texture &base)
 
static const TextureVKCast (const Texture &base)
 
static TextureVKCast (Texture *base)
 
static const TextureVKCast (const Texture *base)
 
- Protected Member Functions inherited from impeller::Texture
 Texture (TextureDescriptor desc)
 
- Protected Attributes inherited from impeller::Texture
bool mipmap_generated_ = false
 

Detailed Description

Definition at line 19 of file texture_vk.h.

Constructor & Destructor Documentation

◆ TextureVK()

impeller::TextureVK::TextureVK ( std::weak_ptr< Context context,
std::shared_ptr< TextureSourceVK source 
)

Definition at line 14 of file texture_vk.cc.

16 : Texture(source->GetTextureDescriptor()),
17 context_(std::move(context)),
18 source_(std::move(source)) {}
Texture(TextureDescriptor desc)
Definition texture.cc:11
SkBitmap source
Definition examples.cpp:28

◆ ~TextureVK()

impeller::TextureVK::~TextureVK ( )
overridedefault

Member Function Documentation

◆ GetCachedFramebuffer()

SharedHandleVK< vk::Framebuffer > impeller::TextureVK::GetCachedFramebuffer ( ) const

Retrieve the last framebuffer object used with this texture.

May be nullptr if no previous framebuffer existed.

Definition at line 187 of file texture_vk.cc.

187 {
188 return source_->GetCachedFramebuffer();
189}

◆ GetCachedRenderPass()

SharedHandleVK< vk::RenderPass > impeller::TextureVK::GetCachedRenderPass ( ) const

Retrieve the last render pass object used with this texture.

May be nullptr if no previous render pass existed.

Definition at line 191 of file texture_vk.cc.

191 {
192 return source_->GetCachedRenderPass();
193}

◆ GetImage()

vk::Image impeller::TextureVK::GetImage ( ) const

Definition at line 147 of file texture_vk.cc.

147 {
148 return source_->GetImage();
149}

◆ GetImageView()

vk::ImageView impeller::TextureVK::GetImageView ( ) const

Definition at line 151 of file texture_vk.cc.

151 {
152 return source_->GetImageView();
153}

◆ GetImmutableSamplerVariant()

std::shared_ptr< SamplerVK > impeller::TextureVK::GetImmutableSamplerVariant ( const SamplerVK sampler) const

Definition at line 203 of file texture_vk.cc.

204 {
205 if (!source_) {
206 return nullptr;
207 }
208 auto conversion = source_->GetYUVConversion();
209 if (!conversion) {
210 // Most textures don't need a sampler conversion and will go down this path.
211 // Only needed for YUV sampling from external textures.
212 return nullptr;
213 }
214 return sampler.CreateVariantForConversion(std::move(conversion));
215}

◆ GetLayout()

vk::ImageLayout impeller::TextureVK::GetLayout ( ) const

Definition at line 169 of file texture_vk.cc.

169 {
170 return source_ ? source_->GetLayout() : vk::ImageLayout::eUndefined;
171}

◆ GetRenderTargetView()

vk::ImageView impeller::TextureVK::GetRenderTargetView ( ) const

Definition at line 173 of file texture_vk.cc.

173 {
174 return source_->GetRenderTargetView();
175}

◆ GetSize()

ISize impeller::TextureVK::GetSize ( ) const
overridevirtual

Implements impeller::Texture.

Definition at line 143 of file texture_vk.cc.

143 {
144 return GetTextureDescriptor().size;
145}
const TextureDescriptor & GetTextureDescriptor() const
Definition texture.cc:57

◆ GetTextureSource()

std::shared_ptr< const TextureSourceVK > impeller::TextureVK::GetTextureSource ( ) const

Definition at line 155 of file texture_vk.cc.

155 {
156 return source_;
157}

◆ IsSwapchainImage()

bool impeller::TextureVK::IsSwapchainImage ( ) const

Definition at line 199 of file texture_vk.cc.

199 {
200 return source_->IsSwapchainImage();
201}

◆ IsValid()

bool impeller::TextureVK::IsValid ( ) const
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 139 of file texture_vk.cc.

139 {
140 return !!source_;
141}

◆ OnSetContents() [1/2]

bool impeller::TextureVK::OnSetContents ( const uint8_t *  contents,
size_t  length,
size_t  slice 
)
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 32 of file texture_vk.cc.

34 {
35 if (!IsValid() || !contents) {
36 return false;
37 }
38
39 const auto& desc = GetTextureDescriptor();
40
41 // Out of bounds access.
42 if (length != desc.GetByteSizeOfBaseMipLevel()) {
43 VALIDATION_LOG << "Illegal to set contents for invalid size.";
44 return false;
45 }
46
47 auto context = context_.lock();
48 if (!context) {
49 VALIDATION_LOG << "Context died before setting contents on texture.";
50 return false;
51 }
52
53 auto staging_buffer =
54 context->GetResourceAllocator()->CreateBufferWithCopy(contents, length);
55
56 if (!staging_buffer) {
57 VALIDATION_LOG << "Could not create staging buffer.";
58 return false;
59 }
60
61 auto cmd_buffer = context->CreateCommandBuffer();
62
63 if (!cmd_buffer) {
64 return false;
65 }
66
67 const auto encoder = CommandBufferVK::Cast(*cmd_buffer).GetEncoder();
68
69 if (!encoder->Track(staging_buffer) || !encoder->Track(source_)) {
70 return false;
71 }
72
73 const auto& vk_cmd_buffer = encoder->GetCommandBuffer();
74
75 BarrierVK barrier;
76 barrier.cmd_buffer = vk_cmd_buffer;
77 barrier.new_layout = vk::ImageLayout::eTransferDstOptimal;
78 barrier.src_access = {};
79 barrier.src_stage = vk::PipelineStageFlagBits::eTopOfPipe;
80 barrier.dst_access = vk::AccessFlagBits::eTransferWrite;
81 barrier.dst_stage = vk::PipelineStageFlagBits::eTransfer;
82
83 if (!SetLayout(barrier)) {
84 return false;
85 }
86
87 vk::BufferImageCopy copy;
88 copy.bufferOffset = 0u;
89 copy.bufferRowLength = 0u; // 0u means tightly packed per spec.
90 copy.bufferImageHeight = 0u; // 0u means tightly packed per spec.
91 copy.imageOffset.x = 0u;
92 copy.imageOffset.y = 0u;
93 copy.imageOffset.z = 0u;
94 copy.imageExtent.width = desc.size.width;
95 copy.imageExtent.height = desc.size.height;
96 copy.imageExtent.depth = 1u;
97 copy.imageSubresource.aspectMask =
99 copy.imageSubresource.mipLevel = 0u;
100 copy.imageSubresource.baseArrayLayer = slice;
101 copy.imageSubresource.layerCount = 1u;
102
103 vk_cmd_buffer.copyBufferToImage(
104 DeviceBufferVK::Cast(*staging_buffer).GetBuffer(), // src buffer
105 GetImage(), // dst image
106 barrier.new_layout, // dst image layout
107 1u, // region count
108 &copy // regions
109 );
110
111 // Transition to shader-read.
112 {
113 BarrierVK barrier;
114 barrier.cmd_buffer = vk_cmd_buffer;
115 barrier.src_access = vk::AccessFlagBits::eColorAttachmentWrite |
116 vk::AccessFlagBits::eTransferWrite;
117 barrier.src_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput |
118 vk::PipelineStageFlagBits::eTransfer;
119 barrier.dst_access = vk::AccessFlagBits::eShaderRead;
120 barrier.dst_stage = vk::PipelineStageFlagBits::eFragmentShader;
121
122 barrier.new_layout = vk::ImageLayout::eShaderReadOnlyOptimal;
123
124 if (!SetLayout(barrier)) {
125 return false;
126 }
127 }
128
129 return context->GetCommandQueue()->Submit({cmd_buffer}).ok();
130}
static bool ok(int result)
static CommandBufferVK & Cast(CommandBuffer &base)
const std::shared_ptr< CommandEncoderVK > & GetEncoder()
vk::Buffer GetBuffer() const
bool IsValid() const override
bool SetLayout(const BarrierVK &barrier) const
vk::Image GetImage() const
uint32_t uint32_t * format
size_t length
Definition copy.py:1
constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format)
Definition formats_vk.h:564
#define VALIDATION_LOG
Definition validation.h:73

◆ OnSetContents() [2/2]

bool impeller::TextureVK::OnSetContents ( std::shared_ptr< const fml::Mapping mapping,
size_t  slice 
)
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 132 of file texture_vk.cc.

133 {
134 // Vulkan has no threading restrictions. So we can pass this data along to the
135 // client rendering API immediately.
136 return OnSetContents(mapping->GetMapping(), mapping->GetSize(), slice);
137}
bool OnSetContents(const uint8_t *contents, size_t length, size_t slice) override
Definition texture_vk.cc:32

◆ SetCachedFramebuffer()

void impeller::TextureVK::SetCachedFramebuffer ( const SharedHandleVK< vk::Framebuffer > &  framebuffer)

Store the last framebuffer object used with this texture.

This field is only set if this texture is used as the resolve texture of a render pass. By construction, this framebuffer should be compatible with any future render passes.

Definition at line 177 of file texture_vk.cc.

178 {
179 source_->SetCachedFramebuffer(framebuffer);
180}

◆ SetCachedRenderPass()

void impeller::TextureVK::SetCachedRenderPass ( const SharedHandleVK< vk::RenderPass > &  render_pass)

Store the last render pass object used with this texture.

This field is only set if this texture is used as the resolve texture of a render pass. By construction, this framebuffer should be compatible with any future render passes.

Definition at line 182 of file texture_vk.cc.

183 {
184 source_->SetCachedRenderPass(render_pass);
185}

◆ SetLabel()

void impeller::TextureVK::SetLabel ( std::string_view  label)
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 22 of file texture_vk.cc.

22 {
23 auto context = context_.lock();
24 if (!context) {
25 // The context may have died.
26 return;
27 }
28 ContextVK::Cast(*context).SetDebugName(GetImage(), label);
29 ContextVK::Cast(*context).SetDebugName(GetImageView(), label);
30}
bool SetDebugName(T handle, std::string_view label) const
Definition context_vk.h:108
vk::ImageView GetImageView() const

◆ SetLayout()

bool impeller::TextureVK::SetLayout ( const BarrierVK barrier) const

Definition at line 159 of file texture_vk.cc.

159 {
160 return source_ ? source_->SetLayout(barrier).ok() : false;
161}

◆ SetLayoutWithoutEncoding()

vk::ImageLayout impeller::TextureVK::SetLayoutWithoutEncoding ( vk::ImageLayout  layout) const

Definition at line 163 of file texture_vk.cc.

164 {
165 return source_ ? source_->SetLayoutWithoutEncoding(layout)
166 : vk::ImageLayout::eUndefined;
167}

◆ SetMipMapGenerated()

void impeller::TextureVK::SetMipMapGenerated ( )

Definition at line 195 of file texture_vk.cc.

195 {
196 mipmap_generated_ = true;
197}
bool mipmap_generated_
Definition texture.h:64

The documentation for this class was generated from the following files: