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

279{
280 const auto n = static_cast<uint32_t>(m_data.size());
281 if (n == 0)
282 return nullptr;
283
284 if (n == 1) {
285 std::shared_ptr<Core::VKImage> img;
287 auto [ptr, bytes] = variant_bytes(m_data[0]);
288 if (!ptr || bytes == 0)
289 return;
291 });
292 return img;
293 }
294
295 const size_t layer_bytes = byte_size();
296 std::vector<uint8_t> combined(layer_bytes * n);
297 for (uint32_t i = 0; i < n; ++i) {
298 bool ok = seqlock_read_void(m_slot_locks[i], 8, [&] {
299 auto [ptr, bytes] = variant_bytes(m_data[i]);
300 if (!ptr || bytes != layer_bytes) {
302 "TextureContainer::to_image_array layer {} has unexpected byte count ({} vs {})",
303 i, bytes, layer_bytes);
304 return;
305 }
306 std::memcpy(combined.data() + i * layer_bytes, ptr, layer_bytes);
307 });
308 if (!ok)
309 return nullptr;
310 }
311
312 return TextureLoom::instance().create_2d_array(m_width, m_height, n, m_format, combined.data());
313}
#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.
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: