| Flutter Impeller |

Public Member Functions | List of all members
impeller::BlitGenerateMipmapCommandVK Struct Reference

`#include <blit_command_vk.h>`

Inheritance diagram for impeller::BlitGenerateMipmapCommandVK:

## Public Member Functions
| ~BlitGenerateMipmapCommandVK () 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 BlitEncodeVK & | Cast (BlitCommand &base)
static const BlitEncodeVK & | Cast (const BlitCommand &base)
static BlitEncodeVK * | Cast (BlitCommand *base)
static const BlitEncodeVK * | Cast (const BlitCommand *base)
Public Attributes inherited from impeller::BlitGenerateMipmapCommand
std::shared_ptr< Texture > | texture
Public Attributes inherited from impeller::BlitCommand
std::string | label

## Detailed Description

Definition at line 55 of file blit_command_vk.h.

## Constructor & Destructor Documentation

## ◆ ~BlitGenerateMipmapCommandVK()

impeller::BlitGenerateMipmapCommandVK::~BlitGenerateMipmapCommandVK | ( |  | ) |
| override default

BlitGenerateMipmapCommandVK

## Member Function Documentation

## ◆ Encode()

bool impeller::BlitGenerateMipmapCommandVK::Encode | ( | CommandEncoderVK & | encoder | ) | const
| override virtual

Implements impeller::BlitEncodeVK.

Definition at line 246 of file blit_command_vk.cc.

246 {
247 auto& src = TextureVK::Cast(*texture);
248
249 const auto size = src.GetTextureDescriptor().size;
250 uint32_t mip_count = src.GetTextureDescriptor().mip_count;
251
252 if (mip_count < 2u) {
253 return true;
254 }
255
256 const auto& image = src.GetImage();
257 const auto& cmd = encoder.GetCommandBuffer();
258
259 if (!encoder.Track(texture)) {
260 return false;
261 }
262
263 // Transition the base mip level to transfer-src layout so we can read from
264 // it and transition the rest to dst-optimal since they are going to be
265 // written to.
266 InsertImageMemoryBarrier(
267 cmd, // command buffer
268 image, // image
269 vk::AccessFlagBits::eTransferWrite, // src access mask
270 vk::AccessFlagBits::eTransferRead, // dst access mask
271 src.GetLayout(), // old layout
272 vk::ImageLayout::eTransferSrcOptimal, // new layout
273 vk::PipelineStageFlagBits::eTransfer, // src stage
274 vk::PipelineStageFlagBits::eTransfer, // dst stage
275 0u // mip level
276 );
277 InsertImageMemoryBarrier(
278 cmd, // command buffer
279 image, // image
280 {}, // src access mask
281 vk::AccessFlagBits::eTransferWrite, // dst access mask
282 vk::ImageLayout::eUndefined, // old layout
283 vk::ImageLayout::eTransferDstOptimal, // new layout
284 vk::PipelineStageFlagBits::eTransfer, // src stage
285 vk::PipelineStageFlagBits::eTransfer, // dst stage
286 1u, // mip level
287 mip_count - 1 // mip level count
288 );
289
290 // Blit from the base mip level to all other levels.
291 for (size_t mip_level = 1u; mip_level < mip_count; mip_level++) {
292 vk::ImageBlit blit;
293
294 blit.srcSubresource.aspectMask = vk::ImageAspectFlagBits::eColor;
295 blit.srcSubresource.baseArrayLayer = 0u;
296 blit.srcSubresource.layerCount = 1u;
297 blit.srcSubresource.mipLevel = 0u;
298
299 blit.dstSubresource.aspectMask = vk::ImageAspectFlagBits::eColor;
300 blit.dstSubresource.baseArrayLayer = 0u;
301 blit.dstSubresource.layerCount = 1u;
302 blit.dstSubresource.mipLevel = mip_level;
303
304 // offsets[0] is origin.
305 blit.srcOffsets[1].x = size.width;
306 blit.srcOffsets[1].y = size.height;
307 blit.srcOffsets[1].z = 1u;
308
309 // offsets[0] is origin.
310 blit.dstOffsets[1].x = std::max<int32_t>(size.width >> mip_level, 1u);
311 blit.dstOffsets[1].y = std::max<int32_t>(size.height >> mip_level, 1u);
312 blit.dstOffsets[1].z = 1u;
313
314 cmd.blitImage(image, // src image
315 vk::ImageLayout::eTransferSrcOptimal, // src layout
316 image, // dst image
317 vk::ImageLayout::eTransferDstOptimal, // dst layout
318 1u, // region count
319 &blit, // regions
320 vk::Filter::eLinear // filter
321 );
322 }
323
324 // Transition all mip levels to shader read. The base mip level has a
325 // different "old" layout than the rest now.
326 InsertImageMemoryBarrier(
327 cmd, // command buffer
328 image, // image
329 vk::AccessFlagBits::eTransferWrite, // src access mask
330 vk::AccessFlagBits::eShaderRead, // dst access mask
331 vk::ImageLayout::eTransferSrcOptimal, // old layout
332 vk::ImageLayout::eShaderReadOnlyOptimal, // new layout
333 vk::PipelineStageFlagBits::eTransfer, // src stage
334 vk::PipelineStageFlagBits::eFragmentShader, // dst stage
335 0u // mip level
336 );
337 InsertImageMemoryBarrier(
338 cmd, // command buffer
339 image, // image
340 vk::AccessFlagBits::eTransferWrite, // src access mask
341 vk::AccessFlagBits::eShaderRead, // dst access mask
342 vk::ImageLayout::eTransferDstOptimal, // old layout
343 vk::ImageLayout::eShaderReadOnlyOptimal, // new layout
344 vk::PipelineStageFlagBits::eTransfer, // src stage
345 vk::PipelineStageFlagBits::eFragmentShader, // dst stage
346 1u, // mip level
347 mip_count - 1 // mip level count
348 );
349
350 // We modified the layouts of this image from underneath it. Tell it its new
351 // state so it doesn't try to perform redundant transitions under the hood.
352 src.SetLayoutWithoutEncoding(vk::ImageLayout::eShaderReadOnlyOptimal);
353
354 return true;
355 }

References impeller::BackendCast< TextureVK, Texture >::Cast(), impeller::CommandEncoderVK::GetCommandBuffer(), impeller::InsertImageMemoryBarrier(), impeller::BlitGenerateMipmapCommand::texture, and impeller::CommandEncoderVK::Track().

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

## ◆ GetLabel()

std::string impeller::BlitGenerateMipmapCommandVK::GetLabel | ( |  | ) | const
| override virtual

Implements impeller::BlitEncodeVK.

Definition at line 211 of file blit_command_vk.cc.

211 {
212 return label;
213 }

References impeller::BlitCommand::label.

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

- impeller/renderer/backend/vulkan/blit_command_vk.h
- impeller/renderer/backend/vulkan/blit_command_vk.cc

impeller::BlitGenerateMipmapCommand::texture
std::shared_ptr< Texture > texture
Definition: blit_command.h:38
impeller::BlitCommand::label
std::string label
Definition: blit_command.h:14
impeller::InsertImageMemoryBarrier
static void InsertImageMemoryBarrier(const vk::CommandBuffer &cmd, const vk::Image &image, vk::AccessFlags src_access_mask, vk::AccessFlags dst_access_mask, vk::ImageLayout old_layout, vk::ImageLayout new_layout, vk::PipelineStageFlags src_stage, vk::PipelineStageFlags dst_stage, uint32_t base_mip_level, uint32_t mip_level_count=1u)
Definition: blit_command_vk.cc:215
impeller::BackendCast< TextureVK, Texture >::Cast
static TextureVK & Cast(Texture &base)
Definition: backend_cast.h:14