Upload all layers as a Vulkan 2D array texture.
All layers must have been populated before calling this. Empty layers contribute zero bytes and will produce incorrect GPU data.
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
454 std::vector<uint8_t> combined(layer_bytes * n);
455 for (uint32_t i = 0; i < n; ++i) {
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
471}
#define MF_ERROR(comp, ctx,...)
Memory::SeqlockArray m_slot_locks
Portal::Graphics::ImageFormat m_format
std::vector< DataVariant > m_data
size_t byte_size() const
Total byte count of the pixel buffer.
static TextureLoom & instance()
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.