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

◆ to_image_array() [1/2]

std::shared_ptr< Core::VKImage > MayaFlux::Kakshya::TextureContainer::to_image_array ( ) const

Upload all layers as a Vulkan 2D array texture.

Concatenates pixel data from all layers in order (layer 0 first) and calls TextureLoom::create_2d_array. The returned VKImage has array_layers == get_layer_count() and an image view of type VK_IMAGE_VIEW_TYPE_2D_ARRAY, making it bindable as sampler2DArray in GLSL.

All layers must have been populated before calling this. Empty layers contribute zero bytes and will produce incorrect GPU data.

Returns
Initialised VKImage with array_layers > 1, or nullptr on failure.

Definition at line 436 of file TextureContainer.cpp.

437{
438 const auto n = static_cast<uint32_t>(m_data.size());
439 if (n == 0)
440 return nullptr;
441
442 if (n == 1) {
443 std::shared_ptr<Core::VKImage> img;
445 auto [ptr, bytes] = variant_bytes(m_data[0]);
446 if (!ptr || bytes == 0)
447 return;
449 });
450 return img;
451 }
452
453 const size_t layer_bytes = byte_size();
454 std::vector<uint8_t> combined(layer_bytes * n);
455 for (uint32_t i = 0; i < n; ++i) {
456 bool ok = seqlock_read_void(m_slot_locks[i], 8, [&] {
457 auto [ptr, bytes] = variant_bytes(m_data[i]);
458 if (!ptr || bytes != layer_bytes) {
460 "TextureContainer::to_image_array layer {} has unexpected byte count ({} vs {})",
461 i, bytes, layer_bytes);
462 return;
463 }
464 std::memcpy(combined.data() + i * layer_bytes, ptr, layer_bytes);
465 });
466 if (!ok)
467 return nullptr;
468 }
469
470 return TextureLoom::instance().create_2d_array(m_width, m_height, n, m_format, combined.data());
471}
#define MF_ERROR(comp, ctx,...)
const uint8_t * ptr
Portal::Graphics::ImageFormat m_format
size_t byte_size() const
Total byte count of the pixel buffer.
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.
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
bool seqlock_read_void(const Seqlock &lock, uint32_t max_attempts, Fn &&fn)
Invoke a void read functor under a Seqlock with a bounded retry count.
Definition SeqLock.hpp:222

References MF_ERROR, and ptr.