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 315 of file TextureContainer.cpp.

317{
318 const auto n = static_cast<uint32_t>(m_data.size());
319 if (n == 0)
320 return nullptr;
321
322 if (n == 1) {
323 std::shared_ptr<Core::VKImage> img;
325 auto [ptr, bytes] = variant_bytes(m_data[0]);
326 if (!ptr || bytes == 0)
327 return;
328 auto& loom = TextureLoom::instance();
329 img = loom.create_2d(m_width, m_height, m_format, nullptr);
330 if (img)
331 loom.upload_data(img, ptr, bytes, staging);
332 });
333 return img;
334 }
335
336 const size_t layer_bytes = byte_size();
337 std::vector<uint8_t> combined(layer_bytes * n);
338 for (uint32_t i = 0; i < n; ++i) {
339 bool ok = seqlock_read_void(m_slot_locks[i], 8, [&] {
340 auto [ptr, bytes] = variant_bytes(m_data[i]);
341 if (!ptr || bytes != layer_bytes) {
343 "TextureContainer::to_image_array(staging) layer {} size mismatch", i);
344 return;
345 }
346 std::memcpy(combined.data() + i * layer_bytes, ptr, layer_bytes);
347 });
348
349 if (!ok)
350 return nullptr;
351 }
352
353 auto& loom = TextureLoom::instance();
354 auto img = loom.create_2d_array(m_width, m_height, n, m_format, nullptr);
355 if (!img)
356 return nullptr;
357 loom.upload_data(img, combined.data(), combined.size(), staging);
358 return img;
359}
#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.
std::pair< const uint8_t *, size_t > variant_bytes(const DataVariant &v)
Get a pointer to the raw bytes of a DataVariant and its size.
Definition DataUtils.cpp:95
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, ptr, and MayaFlux::Kakshya::variant_bytes().

+ Here is the call graph for this function: