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

◆ to_image_array() [2/2]

std::shared_ptr< Core::VKImage > MayaFlux::Kakshya::TextureContainer::to_image_array ( const std::shared_ptr< Buffers::VKBuffer > &  staging) const

Upload all layers as a Vulkan 2D array texture, reusing a staging buffer.

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.

Parameters
stagingHost-visible staging VKBuffer sized to at least byte_size().
Returns
Initialised VKImage with array_layers > 1, or nullptr on failure.

Definition at line 473 of file TextureContainer.cpp.

475{
476 const auto n = static_cast<uint32_t>(m_data.size());
477 if (n == 0)
478 return nullptr;
479
480 if (n == 1) {
481 std::shared_ptr<Core::VKImage> img;
483 auto [ptr, bytes] = variant_bytes(m_data[0]);
484 if (!ptr || bytes == 0)
485 return;
486 auto& loom = TextureLoom::instance();
487 img = loom.create_2d(m_width, m_height, m_format, nullptr);
488 if (img)
489 loom.upload_data(img, ptr, bytes, staging);
490 });
491 return img;
492 }
493
494 const size_t layer_bytes = byte_size();
495 std::vector<uint8_t> combined(layer_bytes * n);
496 for (uint32_t i = 0; i < n; ++i) {
497 bool ok = seqlock_read_void(m_slot_locks[i], 8, [&] {
498 auto [ptr, bytes] = variant_bytes(m_data[i]);
499 if (!ptr || bytes != layer_bytes) {
501 "TextureContainer::to_image_array(staging) layer {} size mismatch", i);
502 return;
503 }
504 std::memcpy(combined.data() + i * layer_bytes, ptr, layer_bytes);
505 });
506
507 if (!ok)
508 return nullptr;
509 }
510
511 auto& loom = TextureLoom::instance();
512 auto img = loom.create_2d_array(m_width, m_height, n, m_format, nullptr);
513 if (!img)
514 return nullptr;
515 loom.upload_data(img, combined.data(), combined.size(), staging);
516 return img;
517}
#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.
@ 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.