Flutter Impeller
impeller::BlitCopyTextureToBufferCommandVK Struct Reference

#include <blit_command_vk.h>

Inheritance diagram for impeller::BlitCopyTextureToBufferCommandVK:
impeller::BlitCopyTextureToBufferCommand impeller::BlitEncodeVK impeller::BlitCommand impeller::BackendCast< BlitEncodeVK, BlitCommand >

Public Member Functions

 ~BlitCopyTextureToBufferCommandVK () override
 
std::string GetLabel () const override
 
bool Encode (CommandEncoderVK &encoder) const override
 
- Public Member Functions inherited from impeller::BlitEncodeVK
virtual ~BlitEncodeVK ()
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::BackendCast< BlitEncodeVK, BlitCommand >
static BlitEncodeVKCast (BlitCommand &base)
 
static const BlitEncodeVKCast (const BlitCommand &base)
 
static BlitEncodeVKCast (BlitCommand *base)
 
static const BlitEncodeVKCast (const BlitCommand *base)
 
- Public Attributes inherited from impeller::BlitCopyTextureToBufferCommand
std::shared_ptr< Texturesource
 
std::shared_ptr< DeviceBufferdestination
 
IRect source_region
 
size_t destination_offset
 
- Public Attributes inherited from impeller::BlitCommand
std::string label
 

Detailed Description

Definition at line 38 of file blit_command_vk.h.

Constructor & Destructor Documentation

◆ ~BlitCopyTextureToBufferCommandVK()

impeller::BlitCopyTextureToBufferCommandVK::~BlitCopyTextureToBufferCommandVK ( )
overridedefault

Member Function Documentation

◆ Encode()

bool impeller::BlitCopyTextureToBufferCommandVK::Encode ( CommandEncoderVK encoder) const
overridevirtual

Implements impeller::BlitEncodeVK.

Definition at line 115 of file blit_command_vk.cc.

115  {
116  const auto& cmd_buffer = encoder.GetCommandBuffer();
117 
118  // cast source and destination to TextureVK
119  const auto& src = TextureVK::Cast(*source);
120 
121  if (!encoder.Track(source) || !encoder.Track(destination)) {
122  return false;
123  }
124 
125  BarrierVK barrier;
126  barrier.cmd_buffer = cmd_buffer;
127  barrier.new_layout = vk::ImageLayout::eTransferSrcOptimal;
128  barrier.src_access = vk::AccessFlagBits::eShaderWrite |
129  vk::AccessFlagBits::eTransferWrite |
130  vk::AccessFlagBits::eColorAttachmentWrite;
131  barrier.src_stage = vk::PipelineStageFlagBits::eFragmentShader |
132  vk::PipelineStageFlagBits::eTransfer |
133  vk::PipelineStageFlagBits::eColorAttachmentOutput;
134  barrier.dst_access = vk::AccessFlagBits::eShaderRead;
135  barrier.dst_stage = vk::PipelineStageFlagBits::eVertexShader |
136  vk::PipelineStageFlagBits::eFragmentShader;
137 
138  const auto& dst = DeviceBufferVK::Cast(*destination);
139 
140  vk::BufferImageCopy image_copy;
141  image_copy.setBufferOffset(destination_offset);
142  image_copy.setBufferRowLength(0);
143  image_copy.setBufferImageHeight(0);
144  image_copy.setImageSubresource(
145  vk::ImageSubresourceLayers(vk::ImageAspectFlagBits::eColor, 0, 0, 1));
146  image_copy.setImageOffset(
147  vk::Offset3D(source_region.GetX(), source_region.GetY(), 0));
148  image_copy.setImageExtent(
149  vk::Extent3D(source_region.GetWidth(), source_region.GetHeight(), 1));
150 
151  if (!src.SetLayout(barrier)) {
152  VALIDATION_LOG << "Could not encode layout transition.";
153  return false;
154  }
155 
156  cmd_buffer.copyImageToBuffer(src.GetImage(), //
157  barrier.new_layout, //
158  dst.GetBuffer(), //
159  image_copy //
160  );
161 
162  // If the buffer is used for readback, then apply a transfer -> host memory
163  // barrier.
164  if (destination->GetDeviceBufferDescriptor().readback) {
165  vk::MemoryBarrier barrier;
166  barrier.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
167  barrier.dstAccessMask = vk::AccessFlagBits::eHostRead;
168 
169  cmd_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer,
170  vk::PipelineStageFlagBits::eHost, {}, 1,
171  &barrier, 0, {}, 0, {});
172  }
173 
174  return true;
175 }

References impeller::BackendCast< TextureVK, Texture >::Cast(), impeller::BackendCast< DeviceBufferVK, DeviceBuffer >::Cast(), impeller::BarrierVK::cmd_buffer, impeller::BlitCopyTextureToBufferCommand::destination, impeller::BlitCopyTextureToBufferCommand::destination_offset, impeller::BarrierVK::dst_access, impeller::BarrierVK::dst_stage, impeller::CommandEncoderVK::GetCommandBuffer(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::BarrierVK::new_layout, impeller::BlitCopyTextureToBufferCommand::source, impeller::BlitCopyTextureToBufferCommand::source_region, impeller::BarrierVK::src_access, impeller::BarrierVK::src_stage, impeller::CommandEncoderVK::Track(), and VALIDATION_LOG.

Referenced by impeller::testing::TEST().

◆ GetLabel()

std::string impeller::BlitCopyTextureToBufferCommandVK::GetLabel ( ) const
overridevirtual

Implements impeller::BlitEncodeVK.

Definition at line 111 of file blit_command_vk.cc.

111  {
112  return label;
113 }

References impeller::BlitCommand::label.


The documentation for this struct was generated from the following files:
impeller::TRect::GetX
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
Definition: rect.h:300
impeller::TRect::GetHeight
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:314
impeller::BlitCommand::label
std::string label
Definition: blit_command.h:15
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:308
impeller::BlitCopyTextureToBufferCommand::destination_offset
size_t destination_offset
Definition: blit_command.h:29
impeller::BlitCopyTextureToBufferCommand::destination
std::shared_ptr< DeviceBuffer > destination
Definition: blit_command.h:27
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::BackendCast< TextureVK, Texture >::Cast
static TextureVK & Cast(Texture &base)
Definition: backend_cast.h:13
impeller::BlitCopyTextureToBufferCommand::source
std::shared_ptr< Texture > source
Definition: blit_command.h:26
impeller::TRect::GetY
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
Definition: rect.h:304
impeller::BlitCopyTextureToBufferCommand::source_region
IRect source_region
Definition: blit_command.h:28