MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ acquire_cached_image()

std::shared_ptr< Core::VKImage > MayaFlux::Portal::Graphics::TextureLoom::acquire_cached_image ( ImageCacheEntry &  entry,
const ImageKey &  key 
)

Reuse a matching image in an owner-held entry or create it once.

Parameters
entryCache entry retained by the image producer.
keyImmutable image allocation properties.
Returns
Matching image, or nullptr on failure.

Definition at line 434 of file TextureLoom.cpp.

436{
437 if (key.width == 0 || key.height == 0 || key.layers == 0
438 || key.mip_levels == 0)
439 return nullptr;
440
441 const auto usage = key.kind == ImageKey::Kind::STORAGE_2D
444 if (entry.image && entry.key == key && entry.image->is_initialized()
445 && entry.image->get_width() == key.width
446 && entry.image->get_height() == key.height
447 && entry.image->get_array_layers() == key.layers
448 && entry.image->get_mip_levels() == key.mip_levels
449 && entry.image->get_format() == to_vulkan_format(key.format)
450 && entry.image->get_usage() == usage) {
451 return entry.image;
452 }
453
454 std::shared_ptr<Core::VKImage> image;
455 switch (key.kind) {
457 if (key.layers != 1)
458 return nullptr;
459 image = create_2d(key.width, key.height, key.format, nullptr, key.mip_levels);
460 break;
462 if (key.mip_levels != 1)
463 return nullptr;
464 image = create_2d_array(key.width, key.height, key.layers, key.format, nullptr);
465 break;
467 if (key.layers != 1 || key.mip_levels != 1)
468 return nullptr;
469 image = create_storage_image(key.width, key.height, key.format);
470 break;
471 }
472
473 if (image) {
474 entry.key = key;
475 entry.image = image;
476 }
477 return image;
478}
IO::ImageData image
Definition Decoder.cpp:47
uint16_t usage
@ STORAGE
Storage image (compute shader read/write)
@ TEXTURE_2D
Sampled texture (shader read)
static vk::Format to_vulkan_format(ImageFormat format)
Convert Portal ImageFormat to Vulkan format.
std::shared_ptr< Core::VKImage > create_storage_image(uint32_t width, uint32_t height, ImageFormat format=ImageFormat::RGBA8)
Create a storage image (compute shader read/write)
std::shared_ptr< Core::VKImage > create_2d_array(uint32_t width, uint32_t height, uint32_t layers, ImageFormat format=ImageFormat::RGBA8, const void *data=nullptr)
Create a 2D texture array.
std::shared_ptr< Core::VKImage > create_2d(uint32_t width, uint32_t height, ImageFormat format=ImageFormat::RGBA8, const void *data=nullptr, uint32_t mip_levels=1)
Create a 2D texture.

References create_2d(), create_2d_array(), create_storage_image(), MayaFlux::Portal::Graphics::ImageKey::format, MayaFlux::Portal::Graphics::ImageKey::height, image, MayaFlux::Portal::Graphics::ImageCacheEntry::image, MayaFlux::Portal::Graphics::ImageCacheEntry::key, MayaFlux::Portal::Graphics::ImageKey::kind, MayaFlux::Portal::Graphics::ImageKey::layers, MayaFlux::Portal::Graphics::ImageKey::mip_levels, MayaFlux::Portal::Graphics::ImageKey::SAMPLED_2D, MayaFlux::Portal::Graphics::ImageKey::SAMPLED_ARRAY, MayaFlux::Core::VKImage::STORAGE, MayaFlux::Portal::Graphics::ImageKey::STORAGE_2D, MayaFlux::Core::VKImage::TEXTURE_2D, to_vulkan_format(), usage, and MayaFlux::Portal::Graphics::ImageKey::width.

Referenced by MayaFlux::Portal::Graphics::ImageCacheSet::acquire(), and refresh_cached_image().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: