| Flutter Impeller |

Classes | Public Member Functions | List of all members
impeller::AllocatedTextureSourceVK Class Referencefinal
Inheritance diagram for impeller::AllocatedTextureSourceVK:

## Public Member Functions
| AllocatedTextureSourceVK (std::weak_ptr< ResourceManagerVK > resource_manager, const TextureDescriptor &desc, VmaAllocator allocator, vk::Device device, bool supports_memoryless_textures)
| ~AllocatedTextureSourceVK ()=default
bool | IsValid () const
vk::Image | GetImage () const override
| Get the image handle for this texture source. More...
vk::ImageView | GetImageView () const override
| Retrieve the image view used for sampling/blitting/compute with this texture source. More...
vk::ImageView | GetRenderTargetView () const override
| Retrieve the image view used for render target attachments with this texture source. More...
bool | IsSwapchainImage () const override
| Determines if swapchain image. That is, an image used as the root render target. More...
Public Member Functions inherited from impeller::TextureSourceVK
virtual | ~TextureSourceVK ()
const TextureDescriptor & | GetTextureDescriptor () const
| Gets the texture descriptor for this image source. More...
fml::Status | SetLayout (const BarrierVK &barrier) const
| Encodes the layout transition `barrier` to `barrier.cmd_buffer` for the image. More...
vk::ImageLayout | SetLayoutWithoutEncoding (vk::ImageLayout layout) const
| Store the layout of the image. More...
vk::ImageLayout | GetLayout () const
| Get the last layout assigned to the TextureSourceVK. More...
virtual std::shared_ptr< YUVConversionVK > | GetYUVConversion () const
| When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary to setup custom samplers. This accessor provides this conversion if one is present. Most texture source have none. More...
void | SetCachedFramebuffer (const SharedHandleVK< vk::Framebuffer > &framebuffer)
void | SetCachedRenderPass (const SharedHandleVK< vk::RenderPass > &render_pass)
SharedHandleVK< vk::Framebuffer > | GetCachedFramebuffer () const
SharedHandleVK< vk::RenderPass > | GetCachedRenderPass () const

## Additional Inherited Members
Protected Member Functions inherited from impeller::TextureSourceVK
| TextureSourceVK (TextureDescriptor desc)
Protected Attributes inherited from impeller::TextureSourceVK
const TextureDescriptor | desc_

## Detailed Description

Definition at line 280 of file allocator_vk.cc.

## Constructor & Destructor Documentation

## ◆ AllocatedTextureSourceVK()

impeller::AllocatedTextureSourceVK::AllocatedTextureSourceVK | ( | std::weak_ptr< ResourceManagerVK > | resource_manager,
|  | const TextureDescriptor & | desc,
|  | VmaAllocator | allocator,
|  | vk::Device | device,
|  | bool | supports_memoryless_textures
| ) |  |
| inline

Definition at line 282 of file allocator_vk.cc.

287 : TextureSourceVK(desc), resource_(std::move(resource_manager)) {
288 FML_DCHECK(desc.format != PixelFormat::kUnknown);
289 vk::ImageCreateInfo image_info;
290 image_info.flags = ToVKImageCreateFlags(desc.type);
291 image_info.imageType = vk::ImageType::e2D;
292 image_info.format = ToVKImageFormat(desc.format);
293 image_info.extent = VkExtent3D{
294 static_cast<uint32_t>(desc.size.width), // width
295 static_cast<uint32_t>(desc.size.height), // height
296 1u // depth
297 };
298 image_info.samples = ToVKSampleCount(desc.sample_count);
299 image_info.mipLevels = desc.mip_count;
300 image_info.arrayLayers = ToArrayLayerCount(desc.type);
301 image_info.tiling = vk::ImageTiling::eOptimal;
302 image_info.initialLayout = vk::ImageLayout::eUndefined;
303 image_info.usage = AllocatorVK::ToVKImageUsageFlags(
304 desc.format, desc.usage, desc.storage_mode,
305 supports_memoryless_textures);
306 image_info.sharingMode = vk::SharingMode::eExclusive;
307
308 VmaAllocationCreateInfo alloc_nfo = {};
309
310 alloc_nfo.usage = ToVMAMemoryUsage();
311 alloc_nfo.preferredFlags =
312 static_cast<VkMemoryPropertyFlags>(ToVKTextureMemoryPropertyFlags(
313 desc.storage_mode, supports_memoryless_textures));
314 alloc_nfo.flags = ToVmaAllocationCreateFlags(desc.storage_mode);
315
316 auto create_info_native =
317 static_cast<vk::ImageCreateInfo::NativeType>(image_info);
318
319 VkImage vk_image = VK_NULL_HANDLE;
320 VmaAllocation allocation = {};
321 VmaAllocationInfo allocation_info = {};
322 {
323 auto result = vk::Result{::vmaCreateImage(allocator, //
324 &create_info_native, //
325 &alloc_nfo, //
326 &vk_image, //
327 &allocation, //
328 &allocation_info //
329 )};
330 if (result != vk::Result::eSuccess) {
331 VALIDATION_LOG << "Unable to allocate Vulkan Image: "
332 << vk::to_string(result)
333 << " Type: " << TextureTypeToString(desc.type)
334 << " Mode: " << StorageModeToString(desc.storage_mode)
335 << " Usage: " << TextureUsageMaskToString(desc.usage)
336 << " [VK]Flags: " << vk::to_string(image_info.flags)
337 << " [VK]Format: " << vk::to_string(image_info.format)
338 << " [VK]Usage: " << vk::to_string(image_info.usage)
339 << " [VK]Mem. Flags: "
340 << vk::to_string(vk::MemoryPropertyFlags(
341 alloc_nfo.preferredFlags));
342 return;
343 }
344 }
345
346 auto image = vk::Image{vk_image};
347
348 vk::ImageViewCreateInfo view_info = {};
349 view_info.image = image;
350 view_info.viewType = ToVKImageViewType(desc.type);
351 view_info.format = image_info.format;
352 view_info.subresourceRange.aspectMask = ToVKImageAspectFlags(desc.format);
353 view_info.subresourceRange.levelCount = image_info.mipLevels;
354 view_info.subresourceRange.layerCount = ToArrayLayerCount(desc.type);
355
356 // Vulkan does not have an image format that is equivalent to
357 // `MTLPixelFormatA8Unorm`, so we use `R8Unorm` instead. Given that the
358 // shaders expect that alpha channel to be set in the cases, we swizzle.
359 // See: https://github.com/flutter/flutter/issues/115461 for more details.
360 if (desc.format == PixelFormat::kA8UNormInt) {
361 view_info.components.a = vk::ComponentSwizzle::eR;
362 view_info.components.r = vk::ComponentSwizzle::eA;
363 }
364
365 auto [result, image_view] = device.createImageViewUnique(view_info);
366 if (result != vk::Result::eSuccess) {
367 VALIDATION_LOG << "Unable to create an image view for allocation: "
368 << vk::to_string(result);
369 return;
370 }
371 // Create a specialized view for render target attachments.
372 view_info.subresourceRange.levelCount = 1u;
373 auto [rt_result, rt_image_view] = device.createImageViewUnique(view_info);
374 if (rt_result != vk::Result::eSuccess) {
375 VALIDATION_LOG << "Unable to create an image view for allocation: "
376 << vk::to_string(rt_result);
377 return;
378 }
379
380 resource_.Swap(ImageResource(ImageVMA{allocator, allocation, image},
381 std::move(image_view),
382 std::move(rt_image_view)));
383 is_valid_ = true;
384 }

References impeller::TextureDescriptor::format, impeller::TSize< T >::height, impeller::TextureDescriptor::mip_count, impeller::TextureDescriptor::sample_count, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::StorageModeToString(), impeller::TextureTypeToString(), impeller::TextureUsageMaskToString(), impeller::ToArrayLayerCount(), impeller::ToVKImageAspectFlags(), impeller::ToVKImageCreateFlags(), impeller::ToVKImageFormat(), impeller::ToVKImageViewType(), impeller::ToVKSampleCount(), impeller::ToVKTextureMemoryPropertyFlags(), impeller::ToVmaAllocationCreateFlags(), impeller::ToVMAMemoryUsage(), impeller::TextureDescriptor::type, impeller::TextureDescriptor::usage, VALIDATION_LOG, and impeller::TSize< T >::width.

## ◆ ~AllocatedTextureSourceVK()

impeller::AllocatedTextureSourceVK::~AllocatedTextureSourceVK | ( |  | ) |
| default

## Member Function Documentation

## ◆ GetImage()

vk::Image impeller::AllocatedTextureSourceVK::GetImage | ( |  | ) | const
| inline override virtual

Get the image handle for this texture source.

Returns
  The image.

Implements impeller::TextureSourceVK.

Definition at line 390 of file allocator_vk.cc.

390 { return resource_->image.get().image; }

## ◆ GetImageView()

vk::ImageView impeller::AllocatedTextureSourceVK::GetImageView | ( |  | ) | const
| inline override virtual

Retrieve the image view used for sampling/blitting/compute with this texture source.

Returns
  The image view.

Implements impeller::TextureSourceVK.

Definition at line 392 of file allocator_vk.cc.

392 {
393 return resource_->image_view.get();
394 }

## ◆ GetRenderTargetView()

vk::ImageView impeller::AllocatedTextureSourceVK::GetRenderTargetView | ( |  | ) | const
| inline override virtual

Retrieve the image view used for render target attachments with this texture source.

ImageViews used as render target attachments cannot have any mip levels. In cases where we want to generate mipmaps with the result of this texture, we need to create multiple image views.

Returns
  The render target view.

Implements impeller::TextureSourceVK.

Definition at line 396 of file allocator_vk.cc.

396 {
397 return resource_->rt_image_view.get();
398 }

## ◆ IsSwapchainImage()

bool impeller::AllocatedTextureSourceVK::IsSwapchainImage | ( |  | ) | const
| inline override virtual

Determines if swapchain image. That is, an image used as the root render target.

Returns
  Whether or not this is a swapchain image.

Implements impeller::TextureSourceVK.

Definition at line 400 of file allocator_vk.cc.

400 { return false; }

## ◆ IsValid()

bool impeller::AllocatedTextureSourceVK::IsValid | ( |  | ) | const
| inline

Definition at line 388 of file allocator_vk.cc.

388 { return is_valid_; }

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

- impeller/renderer/backend/vulkan/allocator_vk.cc

impeller::ToVKSampleCount
constexpr vk::SampleCountFlagBits ToVKSampleCount(SampleCount sample_count)
Definition: formats_vk.h:203
impeller::TextureSourceVK::TextureSourceVK
TextureSourceVK(TextureDescriptor desc)
Definition: texture_source_vk.cc:9
impeller::PixelFormat::kA8UNormInt
@ kA8UNormInt
impeller::ToVKTextureMemoryPropertyFlags
static constexpr vk::Flags< vk::MemoryPropertyFlagBits > ToVKTextureMemoryPropertyFlags(StorageMode mode, bool supports_memoryless_textures)
Definition: allocator_vk.cc:249
impeller::ToArrayLayerCount
constexpr uint32_t ToArrayLayerCount(TextureType type)
Definition: formats_vk.h:517
impeller::UniqueResourceVKT::Swap
void Swap(ResourceType &&other)
Reclaims the existing resource, if any, and replaces it.
Definition: resource_manager_vk.h:183
impeller::ToVKImageCreateFlags
constexpr vk::ImageCreateFlags ToVKImageCreateFlags(TextureType type)
Definition: formats_vk.h:545
impeller::AllocatorVK::ToVKImageUsageFlags
static vk::ImageUsageFlags ToVKImageUsageFlags(PixelFormat format, TextureUsageMask usage, StorageMode mode, bool supports_memoryless_textures)
Definition: allocator_vk.cc:199
impeller::ToVKImageFormat
constexpr vk::Format ToVKImageFormat(PixelFormat format)
Definition: formats_vk.h:135
impeller::StorageModeToString
constexpr const char * StorageModeToString(StorageMode mode)
Definition: formats.h:61
impeller::ToVKImageViewType
constexpr vk::ImageViewType ToVKImageViewType(TextureType type)
Definition: formats_vk.h:531
impeller::ToVKImageAspectFlags
constexpr vk::ImageAspectFlags ToVKImageAspectFlags(PixelFormat format)
Definition: formats_vk.h:491
impeller::TextureUsageMaskToString
std::string TextureUsageMaskToString(TextureUsageMask mask)
Definition: formats.cc:81
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::ToVMAMemoryUsage
static constexpr VmaMemoryUsage ToVMAMemoryUsage()
Definition: allocator_vk.cc:244
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::TextureTypeToString
constexpr const char * TextureTypeToString(TextureType type)
Definition: formats.h:270
impeller::ToVmaAllocationCreateFlags
static VmaAllocationCreateFlags ToVmaAllocationCreateFlags(StorageMode mode)
Definition: allocator_vk.cc:267