| 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 56 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 274 of file blit_command_vk.cc.

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

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 239 of file blit_command_vk.cc.

239 {
240 return label;
241 }

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:39
impeller::BlitCommand::label
std::string label
Definition: blit_command.h:15
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:243
impeller::BackendCast< TextureVK, Texture >::Cast
static TextureVK & Cast(Texture &base)
Definition: backend_cast.h:13