| Flutter Impeller |

Public Member Functions | Protected Member Functions | List of all members
impeller::BlitPass Class Referenceabstract

Blit passes encode blit into the underlying command buffer. More...

`#include <blit_pass.h>`

Inheritance diagram for impeller::BlitPass:

## Public Member Functions
virtual | ~BlitPass ()
virtual bool | IsValid () const =0
void | SetLabel (std::string label)
virtual bool | ConvertTextureToShaderRead (const std::shared_ptr< Texture > &texture)
| If the texture is not already in a shader read internal state, then convert it to that state. More...
bool | AddCopy (std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, std::optional< IRect > source_region=std::nullopt, IPoint destination_origin={}, std::string label="")
| Record a command to copy the contents of one texture to another texture. The blit area is limited by the intersection of the texture coverage with respect the source region and destination origin. More...
bool | AddCopy (std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, std::optional< IRect > source_region=std::nullopt, size_t destination_offset=0, std::string label="")
| Record a command to copy the contents of the buffer to the texture. More...
bool | AddCopy (BufferView source, std::shared_ptr< Texture > destination, std::optional< IRect > destination_region=std::nullopt, std::string label="", uint32_t slice=0, bool convert_to_read=true)
| Record a command to copy the contents of the buffer to the texture. More...
bool | GenerateMipmap (std::shared_ptr< Texture > texture, std::string label="")
| Record a command to generate all mip levels for a texture. More...
virtual bool | EncodeCommands (const std::shared_ptr< Allocator > &transients_allocator) const =0
| Encode the recorded commands to the underlying command buffer. More...

## Protected Member Functions
| BlitPass ()
virtual void | OnSetLabel (std::string label)=0
virtual bool | OnCopyTextureToTextureCommand (std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, IRect source_region, IPoint destination_origin, std::string label)=0
virtual bool | OnCopyTextureToBufferCommand (std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, IRect source_region, size_t destination_offset, std::string label)=0
virtual bool | OnCopyBufferToTextureCommand (BufferView source, std::shared_ptr< Texture > destination, IRect destination_region, std::string label, uint32_t slice, bool convert_to_read)=0
virtual bool | OnGenerateMipmapCommand (std::shared_ptr< Texture > texture, std::string label)=0

## Detailed Description

Blit passes encode blit into the underlying command buffer.

            Blit passes can be obtained from the command buffer in which
            the pass is meant to encode commands into.

See also
  `CommandBuffer`

Definition at line 26 of file blit_pass.h.

## Constructor & Destructor Documentation

## ◆ ~BlitPass()

impeller::BlitPass::~BlitPass | ( |  | ) |
| virtual default

## ◆ BlitPass()

impeller::BlitPass::BlitPass | ( |  | ) |
| explicit protected

Definition at line 15 of file blit_pass.cc.

15 {}

## Member Function Documentation

## ◆ AddCopy() [1/3]

bool impeller::BlitPass::AddCopy | ( | BufferView | source,
|  | std::shared_ptr< Texture > | destination,
|  | std::optional< IRect > | destination_region = `std::nullopt`,
|  | std::string | label = `""`,
|  | uint32_t | slice = `0`,
|  | bool | convert_to_read = `true`
| ) |  |

Record a command to copy the contents of the buffer to the texture.

Parameters

  [in] | source | The buffer view to read for copying.
  [in] | destination | The texture to overwrite using the source contents.
  [in] | destination_region | The offset to start writing to in the destination texture. If not provided, this defaults to the entire texture.
  [in] | label | The optional debug label to give the command.
  [in] | slice | For cubemap textures, the slice to write data to.
  [in] | convert_to_read | Whether to convert the texture to a shader read state. Defaults to true.

Returns
  If the command was valid for subsequent commitment.

If a region smaller than the texture size is provided, the contents are treated as containing tightly packed pixel data of that region. Only the portion of the texture in this region is replaced and existing data is preserved.

For example, to replace the top left 10 x 10 region of a larger 100 x 100 texture, the region is {0, 0, 10, 10} and the expected buffer size in bytes is 100 x bpp.

Definition at line 123 of file blit_pass.cc.

128 {
129 if (!destination) {
130 VALIDATION_LOG << "Attempted to add a texture blit with no destination.";
131 return false;
132 }
133 ISize destination_size = destination->GetSize();
134 IRect destination_region_value =
135 destination_region.value_or(IRect::MakeSize(destination_size));
136 if (destination_region_value.GetX() < 0 ||
137 destination_region_value.GetY() < 0 ||
138 destination_region_value.GetRight() > destination_size.width ||
139 destination_region_value.GetBottom() > destination_size.height) {
140 VALIDATION_LOG << "Blit region cannot be larger than destination texture.";
141 return false;
142 }
143
144 auto bytes_per_pixel =
145 BytesPerPixelForPixelFormat(destination->GetTextureDescriptor().format);
146 auto bytes_per_region = destination_region_value.Area() * bytes_per_pixel;
147
148 if (source.range.length != bytes_per_region) {
149 VALIDATION_LOG
150 << "Attempted to add a texture blit with out of bounds access.";
151 return false;
152 }
153 if (slice > 5) {
154 VALIDATION_LOG << "Invalid value for slice: " << slice;
155 return false;
156 }
157
158 return OnCopyBufferToTextureCommand(std::move(source), std::move(destination),
159 destination_region_value,
160 std::move(label), slice, convert_to_read);
161 }

References impeller::TRect< T >::Area(), impeller::BytesPerPixelForPixelFormat(), impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TSize< T >::height, impeller::Range::length, impeller::TRect< T >::MakeSize(), OnCopyBufferToTextureCommand(), impeller::BufferView::range, VALIDATION_LOG, and impeller::TSize< T >::width.

## ◆ AddCopy() [2/3]

bool impeller::BlitPass::AddCopy | ( | std::shared_ptr< Texture > | source,
|  | std::shared_ptr< DeviceBuffer > | destination,
|  | std::optional< IRect > | source_region = `std::nullopt`,
|  | size_t | destination_offset = `0`,
|  | std::string | label = `""`
| ) |  |

Record a command to copy the contents of the buffer to the texture.

Parameters

  [in] | source | The texture to read for copying.
  [in] | destination | The buffer to overwrite using the source contents.
  [in] | source_region | The optional region of the source texture to use for copying. If not specified, the full size of the source texture is used.
  [in] | destination_origin | The origin to start writing to in the destination texture.
  [in] | label | The optional debug label to give the command.

Returns
  If the command was valid for subsequent commitment.

Definition at line 83 of file blit_pass.cc.

87 {
88 if (!source) {
89 VALIDATION_LOG << "Attempted to add a texture blit with no source.";
90 return false;
91 }
92 if (!destination) {
93 VALIDATION_LOG << "Attempted to add a texture blit with no destination.";
94 return false;
95 }
96
97 if (!source_region.has_value()) {
98 source_region = IRect::MakeSize(source->GetSize());
99 }
100
101 auto bytes_per_pixel =
102 BytesPerPixelForPixelFormat(source->GetTextureDescriptor().format);
103 auto bytes_per_image = source_region->Area() * bytes_per_pixel;
104 if (destination_offset + bytes_per_image >
105 destination->GetDeviceBufferDescriptor().size) {
106 VALIDATION_LOG
107 << "Attempted to add a texture blit with out of bounds access.";
108 return false;
109 }
110
111 // Clip the source image.
112 source_region =
113 source_region->Intersection(IRect::MakeSize(source->GetSize()));
114 if (!source_region.has_value()) {
115 return true; // Nothing to blit.
116 }
117
118 return OnCopyTextureToBufferCommand(std::move(source), std::move(destination),
119 source_region.value(), destination_offset,
120 std::move(label));
121 }

References impeller::BytesPerPixelForPixelFormat(), impeller::TRect< T >::MakeSize(), OnCopyTextureToBufferCommand(), and VALIDATION_LOG.

## ◆ AddCopy() [3/3]

bool impeller::BlitPass::AddCopy | ( | std::shared_ptr< Texture > | source,
|  | std::shared_ptr< Texture > | destination,
|  | std::optional< IRect > | source_region = `std::nullopt`,
|  | IPoint | destination_origin = `{}`,
|  | std::string | label = `""`
| ) |  |

Record a command to copy the contents of one texture to another texture. The blit area is limited by the intersection of the texture coverage with respect the source region and destination origin.

Parameters

  [in] | source | The texture to read for copying.
  [in] | destination | The texture to overwrite using the source contents.
  [in] | source_region | The optional region of the source texture to use for copying. If not specified, the full size of the source texture is used.
  [in] | destination_origin | The origin to start writing to in the destination texture.
  [in] | label | The optional debug label to give the command.

Returns
  If the command was valid for subsequent commitment.

Definition at line 26 of file blit_pass.cc.

30 {
31 if (!source) {
32 VALIDATION_LOG << "Attempted to add a texture blit with no source.";
33 return false;
34 }
35 if (!destination) {
36 VALIDATION_LOG << "Attempted to add a texture blit with no destination.";
37 return false;
38 }
39
40 if (source->GetTextureDescriptor().sample_count !=
41 destination->GetTextureDescriptor().sample_count) {
42 VALIDATION_LOG << SPrintF(
43 "The source sample count (%d) must match the destination sample count "
44 "(%d) for blits.",
45 static_cast<int>(source->GetTextureDescriptor().sample_count),
46 static_cast<int>(destination->GetTextureDescriptor().sample_count));
47 return false;
48 }
49 if (source->GetTextureDescriptor().format !=
50 destination->GetTextureDescriptor().format) {
51 VALIDATION_LOG << SPrintF(
52 "The source pixel format (%s) must match the destination pixel format "
53 "(%s) "
54 "for blits.",
55 PixelFormatToString(source->GetTextureDescriptor().format),
56 PixelFormatToString(destination->GetTextureDescriptor().format));
57 return false;
58 }
59
60 if (!source_region.has_value()) {
61 source_region = IRect::MakeSize(source->GetSize());
62 }
63
64 // Clip the source image.
65 source_region =
66 source_region->Intersection(IRect::MakeSize(source->GetSize()));
67 if (!source_region.has_value()) {
68 return true; // Nothing to blit.
69 }
70
71 // Clip the destination image.
72 source_region = source_region->Intersection(
73 IRect::MakeOriginSize(-destination_origin, destination->GetSize()));
74 if (!source_region.has_value()) {
75 return true; // Nothing to blit.
76 }
77
78 return OnCopyTextureToTextureCommand(
79 std::move(source), std::move(destination), source_region.value(),
80 destination_origin, std::move(label));
81 }

References impeller::TRect< T >::MakeOriginSize(), impeller::TRect< T >::MakeSize(), OnCopyTextureToTextureCommand(), impeller::PixelFormatToString(), impeller::SPrintF(), and VALIDATION_LOG.

## ◆ ConvertTextureToShaderRead()

bool impeller::BlitPass::ConvertTextureToShaderRead | ( | const std::shared_ptr< Texture > & | texture | ) |
| virtual

If the texture is not already in a shader read internal state, then convert it to that state.

This API is only used by Vulkan.

Definition at line 163 of file blit_pass.cc.

164 {
165 return true;
166 }

## ◆ EncodeCommands()

virtual bool impeller::BlitPass::EncodeCommands | ( | const std::shared_ptr< Allocator > & | transients_allocator | ) | const
| pure virtual

Encode the recorded commands to the underlying command buffer.

Parameters

  transients_allocator | The transients allocator.

Returns
  If the commands were encoded to the underlying command buffer.

## ◆ GenerateMipmap()

bool impeller::BlitPass::GenerateMipmap | ( | std::shared_ptr< Texture > | texture,
|  | std::string | label = `""`
| ) |  |

Record a command to generate all mip levels for a texture.

Parameters

  [in] | texture | The texture to generate mipmaps for.
  [in] | label | The optional debug label to give the command.

Returns
  If the command was valid for subsequent commitment.

Definition at line 168 of file blit_pass.cc.

169 {
170 if (!texture) {
171 VALIDATION_LOG << "Attempted to add an invalid mipmap generation command "
172 "with no texture.";
173 return false;
174 }
175
176 return OnGenerateMipmapCommand(std::move(texture), std::move(label));
177 }

References OnGenerateMipmapCommand(), and VALIDATION_LOG.

## ◆ IsValid()

virtual bool impeller::BlitPass::IsValid | ( |  | ) | const
| pure virtual

## ◆ OnCopyBufferToTextureCommand()

virtual bool impeller::BlitPass::OnCopyBufferToTextureCommand | ( | BufferView | source,
|  | std::shared_ptr< Texture > | destination,
|  | IRect | destination_region,
|  | std::string | label,
|  | uint32_t | slice,
|  | bool | convert_to_read
| ) |  |
| protected pure virtual

Referenced by AddCopy().

## ◆ OnCopyTextureToBufferCommand()

virtual bool impeller::BlitPass::OnCopyTextureToBufferCommand | ( | std::shared_ptr< Texture > | source,
|  | std::shared_ptr< DeviceBuffer > | destination,
|  | IRect | source_region,
|  | size_t | destination_offset,
|  | std::string | label
| ) |  |
| protected pure virtual

Referenced by AddCopy().

## ◆ OnCopyTextureToTextureCommand()

virtual bool impeller::BlitPass::OnCopyTextureToTextureCommand | ( | std::shared_ptr< Texture > | source,
|  | std::shared_ptr< Texture > | destination,
|  | IRect | source_region,
|  | IPoint | destination_origin,
|  | std::string | label
| ) |  |
| protected pure virtual

Referenced by AddCopy().

## ◆ OnGenerateMipmapCommand()

virtual bool impeller::BlitPass::OnGenerateMipmapCommand | ( | std::shared_ptr< Texture > | texture,
|  | std::string | label
| ) |  |
| protected pure virtual

Referenced by GenerateMipmap().

## ◆ OnSetLabel()

virtual void impeller::BlitPass::OnSetLabel | ( | std::string | label | ) |
| protected pure virtual

Referenced by SetLabel().

## ◆ SetLabel()

void impeller::BlitPass::SetLabel | ( | std::string | label | ) |

Definition at line 19 of file blit_pass.cc.

19 {
20 if (label.empty()) {
21 return;
22 }
23 OnSetLabel(std::move(label));
24 }

References OnSetLabel().

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

- impeller/renderer/blit_pass.h
- impeller/renderer/blit_pass.cc

impeller::ISize
ISize64 ISize
Definition: size.h:140
impeller::BlitPass::OnCopyTextureToBufferCommand
virtual bool OnCopyTextureToBufferCommand(std::shared_ptr< Texture > source, std::shared_ptr< DeviceBuffer > destination, IRect source_region, size_t destination_offset, std::string label)=0
impeller::PixelFormatToString
constexpr const char * PixelFormatToString(PixelFormat format)
Definition: formats.h:140
impeller::BlitPass::OnCopyTextureToTextureCommand
virtual bool OnCopyTextureToTextureCommand(std::shared_ptr< Texture > source, std::shared_ptr< Texture > destination, IRect source_region, IPoint destination_origin, std::string label)=0
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:460
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
impeller::BlitPass::OnCopyBufferToTextureCommand
virtual bool OnCopyBufferToTextureCommand(BufferView source, std::shared_ptr< Texture > destination, IRect destination_region, std::string label, uint32_t slice, bool convert_to_read)=0
impeller::TRect::MakeOriginSize
constexpr static TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
Definition: rect.h:140
impeller::BlitPass::OnGenerateMipmapCommand
virtual bool OnGenerateMipmapCommand(std::shared_ptr< Texture > texture, std::string label)=0
impeller::BlitPass::OnSetLabel
virtual void OnSetLabel(std::string label)=0
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::TRect::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:146
impeller::IRect
IRect64 IRect
Definition: rect.h:772