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

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

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

213 {
214 return label;
215 }

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:217
impeller::BackendCast< TextureVK, Texture >::Cast
static TextureVK & Cast(Texture &base)
Definition: backend_cast.h:15