| 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, bool supports_framebuffer_fetch)
| ~AllocatedTextureSourceVK ()=default
bool | IsValid () const
vk::Image | GetImage () const override
vk::ImageView | GetImageView () const override
Public Member Functions inherited from impeller::TextureSourceVK
virtual | ~TextureSourceVK ()
const TextureDescriptor & | GetTextureDescriptor () const
fml::Status | SetLayout (const BarrierVK &barrier) const
vk::ImageLayout | SetLayoutWithoutEncoding (vk::ImageLayout layout) const
vk::ImageLayout | GetLayout () 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 264 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,
|  | bool | supports_framebuffer_fetch
| ) |  |
| inline

Definition at line 266 of file allocator_vk.cc.

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

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::ToVKImageUsageFlags(), 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

Implements impeller::TextureSourceVK.

Definition at line 365 of file allocator_vk.cc.

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

## ◆ GetImageView()

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

Implements impeller::TextureSourceVK.

Definition at line 367 of file allocator_vk.cc.

367 {
368 return resource_->image_view.get();
369 }

## ◆ IsValid()

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

Definition at line 363 of file allocator_vk.cc.

363 { 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:204
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:233
impeller::ToArrayLayerCount
constexpr uint32_t ToArrayLayerCount(TextureType type)
Definition: formats_vk.h:594
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:622
impeller::ToVKImageFormat
constexpr vk::Format ToVKImageFormat(PixelFormat format)
Definition: formats_vk.h:136
impeller::StorageModeToString
constexpr const char * StorageModeToString(StorageMode mode)
Definition: formats.h:55
impeller::ToVKImageViewType
constexpr vk::ImageViewType ToVKImageViewType(TextureType type)
Definition: formats_vk.h:608
impeller::ToVKImageAspectFlags
constexpr vk::ImageAspectFlags ToVKImageAspectFlags(PixelFormat format)
Definition: formats_vk.h:568
impeller::TextureUsageMaskToString
std::string TextureUsageMaskToString(TextureUsageMask mask)
Definition: formats.cc:81
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::ToVKImageUsageFlags
static constexpr vk::ImageUsageFlags ToVKImageUsageFlags(PixelFormat format, TextureUsageMask usage, StorageMode mode, bool supports_memoryless_textures, bool supports_framebuffer_fetch)
Definition: allocator_vk.cc:166
impeller::ToVMAMemoryUsage
static constexpr VmaMemoryUsage ToVMAMemoryUsage()
Definition: allocator_vk.cc:228
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
impeller::TextureTypeToString
constexpr const char * TextureTypeToString(TextureType type)
Definition: formats.h:264
impeller::ToVmaAllocationCreateFlags
static VmaAllocationCreateFlags ToVmaAllocationCreateFlags(StorageMode mode)
Definition: allocator_vk.cc:251