| Flutter Impeller |

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

## Public Member Functions
| AllocatedTextureSourceVK (const ContextVK &context, 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 | SetCachedFrameData (const FramebufferAndRenderPass &data, SampleCount sample_count)
const FramebufferAndRenderPass & | GetCachedFrameData (SampleCount sample_count) 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 287 of file allocator_vk.cc.

## Constructor & Destructor Documentation

## ◆ AllocatedTextureSourceVK()

impeller::AllocatedTextureSourceVK::AllocatedTextureSourceVK | ( | const ContextVK & | context,
|  | const TextureDescriptor & | desc,
|  | VmaAllocator | allocator,
|  | vk::Device | device,
|  | bool | supports_memoryless_textures
| ) |  |
| inline

Definition at line 289 of file allocator_vk.cc.

294 : TextureSourceVK(desc), resource_(context.GetResourceManager()) {
295 FML_DCHECK(desc.format != PixelFormat::kUnknown);
296 vk::StructureChain<vk::ImageCreateInfo, vk::ImageCompressionControlEXT>
297 image_info_chain;
298 auto& image_info = image_info_chain.get();
299 image_info.flags = ToVKImageCreateFlags(desc.type);
300 image_info.imageType = vk::ImageType::e2D;
301 image_info.format = ToVKImageFormat(desc.format);
302 image_info.extent = VkExtent3D{
303 static_cast<uint32_t>(desc.size.width), // width
304 static_cast<uint32_t>(desc.size.height), // height
305 1u // depth
306 };
307 image_info.samples = ToVKSampleCount(desc.sample_count);
308 image_info.mipLevels = desc.mip_count;
309 image_info.arrayLayers = ToArrayLayerCount(desc.type);
310 image_info.tiling = vk::ImageTiling::eOptimal;
311 image_info.initialLayout = vk::ImageLayout::eUndefined;
312 image_info.usage = AllocatorVK::ToVKImageUsageFlags(
313 desc.format, desc.usage, desc.storage_mode,
314 supports_memoryless_textures);
315 image_info.sharingMode = vk::SharingMode::eExclusive;
316
317 vk::ImageCompressionFixedRateFlagsEXT frc_rates[1] = {
318 vk::ImageCompressionFixedRateFlagBitsEXT::eNone};
319
320 const auto frc_rate =
321 CapabilitiesVK::Cast(*context.GetCapabilities())
322 .GetSupportedFRCRate(desc.compression_type,
323 FRCFormatDescriptor{image_info});
324 if (frc_rate.has_value()) {
325 // This array must not be in a temporary scope.
326 frc_rates[0] = frc_rate.value();
327
328 auto& compression_info =
329 image_info_chain.get<vk::ImageCompressionControlEXT>();
330 compression_info.pFixedRateFlags = frc_rates;
331 compression_info.compressionControlPlaneCount = 1u;
332 compression_info.flags =
333 vk::ImageCompressionFlagBitsEXT::eFixedRateExplicit;
334 } else {
335 image_info_chain.unlink<vk::ImageCompressionControlEXT>();
336 }
337
338 VmaAllocationCreateInfo alloc_nfo = {};
339
340 alloc_nfo.usage = ToVMAMemoryUsage();
341 alloc_nfo.preferredFlags =
342 static_cast<VkMemoryPropertyFlags>(ToVKTextureMemoryPropertyFlags(
343 desc.storage_mode, supports_memoryless_textures));
344 alloc_nfo.flags = ToVmaAllocationCreateFlags(desc.storage_mode);
345
346 auto create_info_native =
347 static_cast<vk::ImageCreateInfo::NativeType>(image_info);
348
349 VkImage vk_image = VK_NULL_HANDLE;
350 VmaAllocation allocation = {};
351 VmaAllocationInfo allocation_info = {};
352 {
353 auto result = vk::Result{::vmaCreateImage(allocator, //
354 &create_info_native, //
355 &alloc_nfo, //
356 &vk_image, //
357 &allocation, //
358 &allocation_info //
359 )};
360 if (result != vk::Result::eSuccess) {
361 VALIDATION_LOG << "Unable to allocate Vulkan Image: "
362 << vk::to_string(result)
363 << " Type: " << TextureTypeToString(desc.type)
364 << " Mode: " << StorageModeToString(desc.storage_mode)
365 << " Usage: " << TextureUsageMaskToString(desc.usage)
366 << " [VK]Flags: " << vk::to_string(image_info.flags)
367 << " [VK]Format: " << vk::to_string(image_info.format)
368 << " [VK]Usage: " << vk::to_string(image_info.usage)
369 << " [VK]Mem. Flags: "
370 << vk::to_string(vk::MemoryPropertyFlags(
371 alloc_nfo.preferredFlags));
372 return;
373 }
374 }
375
376 auto image = vk::Image{vk_image};
377
378 vk::ImageViewCreateInfo view_info = {};
379 view_info.image = image;
380 view_info.viewType = ToVKImageViewType(desc.type);
381 view_info.format = image_info.format;
382 view_info.subresourceRange.aspectMask = ToVKImageAspectFlags(desc.format);
383 view_info.subresourceRange.levelCount = image_info.mipLevels;
384 view_info.subresourceRange.layerCount = ToArrayLayerCount(desc.type);
385
386 // Vulkan does not have an image format that is equivalent to
387 // `MTLPixelFormatA8Unorm`, so we use `R8Unorm` instead. Given that the
388 // shaders expect that alpha channel to be set in the cases, we swizzle.
389 // See: https://github.com/flutter/flutter/issues/115461 for more details.
390 if (desc.format == PixelFormat::kA8UNormInt) {
391 view_info.components.a = vk::ComponentSwizzle::eR;
392 view_info.components.r = vk::ComponentSwizzle::eA;
393 }
394
395 auto [result, image_view] = device.createImageViewUnique(view_info);
396 if (result != vk::Result::eSuccess) {
397 VALIDATION_LOG << "Unable to create an image view for allocation: "
398 << vk::to_string(result);
399 return;
400 }
401 // Create a specialized view for render target attachments.
402 view_info.subresourceRange.levelCount = 1u;
403 auto [rt_result, rt_image_view] = device.createImageViewUnique(view_info);
404 if (rt_result != vk::Result::eSuccess) {
405 VALIDATION_LOG << "Unable to create an image view for allocation: "
406 << vk::to_string(rt_result);
407 return;
408 }
409
410 resource_.Swap(ImageResource(
411 ImageVMA{allocator, allocation, image}, std::move(image_view),
412 std::move(rt_image_view), context.GetResourceAllocator(),
413 context.GetDeviceHolder()));
414 is_valid_ = true;
415 }
impeller::AllocatorVK::ToVKImageUsageFlags
static vk::ImageUsageFlags ToVKImageUsageFlags(PixelFormat format, TextureUsageMask usage, StorageMode mode, bool supports_memoryless_textures)
Definition: allocator_vk.cc:206
impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast
static CapabilitiesVK & Cast(Capabilities &base)
Definition: backend_cast.h:13
impeller::CapabilitiesVK::GetSupportedFRCRate
std::optional< vk::ImageCompressionFixedRateFlagBitsEXT > GetSupportedFRCRate(CompressionType compression_type, const FRCFormatDescriptor &desc) const
Get the fixed compression rate supported by the context for the given format and usage.
Definition: capabilities_vk.cc:755
impeller::TextureSourceVK::TextureSourceVK
TextureSourceVK(TextureDescriptor desc)
Definition: texture_source_vk.cc:9
impeller::UniqueResourceVKT::Swap
void Swap(ResourceType &&other)
Reclaims the existing resource, if any, and replaces it.
Definition: resource_manager_vk.h:181
impeller::ToArrayLayerCount
constexpr uint32_t ToArrayLayerCount(TextureType type)
Definition: formats_vk.h:539
impeller::TextureUsageMaskToString
std::string TextureUsageMaskToString(TextureUsageMask mask)
Definition: formats.cc:81
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::PixelFormat::kA8UNormInt
@ kA8UNormInt
impeller::TextureTypeToString
constexpr const char * TextureTypeToString(TextureType type)
Definition: formats.h:269
impeller::ToVMAMemoryUsage
static constexpr VmaMemoryUsage ToVMAMemoryUsage()
Definition: allocator_vk.cc:251
impeller::ToVKImageViewType
constexpr vk::ImageViewType ToVKImageViewType(TextureType type)
Definition: formats_vk.h:553
impeller::ToVKSampleCount
constexpr vk::SampleCountFlagBits ToVKSampleCount(SampleCount sample_count)
Definition: formats_vk.h:214
impeller::ToVKImageFormat
constexpr vk::Format ToVKImageFormat(PixelFormat format)
Definition: formats_vk.h:146
impeller::ToVmaAllocationCreateFlags
static VmaAllocationCreateFlags ToVmaAllocationCreateFlags(StorageMode mode)
Definition: allocator_vk.cc:274
impeller::ToVKTextureMemoryPropertyFlags
static constexpr vk::Flags< vk::MemoryPropertyFlagBits > ToVKTextureMemoryPropertyFlags(StorageMode mode, bool supports_memoryless_textures)
Definition: allocator_vk.cc:256
impeller::StorageModeToString
constexpr const char * StorageModeToString(StorageMode mode)
Definition: formats.h:60
impeller::ToVKImageCreateFlags
constexpr vk::ImageCreateFlags ToVKImageCreateFlags(TextureType type)
Definition: formats_vk.h:567
impeller::ToVKImageAspectFlags
constexpr vk::ImageAspectFlags ToVKImageAspectFlags(PixelFormat format)
Definition: formats_vk.h:513
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::TextureDescriptor::compression_type, impeller::TextureDescriptor::format, impeller::ContextVK::GetCapabilities(), impeller::ContextVK::GetDeviceHolder(), impeller::ContextVK::GetResourceAllocator(), 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 421 of file allocator_vk.cc.

421 { 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 423 of file allocator_vk.cc.

423 {
424 return resource_->image_view.get();
425 }

## ◆ 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 427 of file allocator_vk.cc.

427 {
428 return resource_->rt_image_view.get();
429 }

## ◆ 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 431 of file allocator_vk.cc.

431 { return false; }

## ◆ IsValid()

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

Definition at line 419 of file allocator_vk.cc.

419 { return is_valid_; }

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

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