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

◆ from_image_array() [1/2]

void MayaFlux::Kakshya::TextureContainer::from_image_array ( const std::shared_ptr< Core::VKImage > &  image)

Download each array layer of a Vulkan 2D array image into the corresponding layer slot.

Expects image to have array_layers == get_layer_count(). Downloads each layer via a separate blocking TextureLoom::download_data call. Resizes m_data to match if necessary.

Parameters
imageSource VKImage with array_layers >= get_layer_count().

Definition at line 278 of file TextureContainer.cpp.

279{
280 if (!image || !image->is_initialized()) {
282 "TextureContainer::from_image_array called with uninitialised image");
283 return;
284 }
285
286 const auto n = static_cast<uint32_t>(m_data.size());
287 if (image->get_array_layers() < n) {
289 "TextureContainer::from_image_array image has {} layers, container expects {}",
290 image->get_array_layers(), n);
291 return;
292 }
293
294 const size_t layer_bytes = byte_size();
295 std::vector<uint8_t> combined(layer_bytes * n);
296 TextureLoom::instance().download_data(image, combined.data(), combined.size(), nullptr);
297
298 const size_t element_count = static_cast<size_t>(m_width) * m_height * m_channels;
299 for (uint32_t i = 0; i < n; ++i) {
300 Memory::SeqlockWriteGuard g(m_slot_locks[i]);
301 m_data[i] = make_empty_storage(m_format, element_count);
302 auto [ptr, bytes] = variant_bytes_mutable(m_data[i]);
303 if (ptr && bytes == layer_bytes)
304 std::memcpy(ptr, combined.data() + i * layer_bytes, layer_bytes);
305 m_cpu_stale[i].store(false, std::memory_order_release);
306
307 m_normalised_dirty[i].store(true, std::memory_order_release);
308 }
309
311}
#define MF_ERROR(comp, ctx,...)
IO::ImageData image
Definition Decoder.cpp:47
const uint8_t * ptr
std::vector< std::atomic< bool > > m_normalised_dirty
std::vector< std::atomic< bool > > m_cpu_stale
Per layer: the GPU image in m_layer_image_cache holds the content, m_data does not.
void update_processing_state(ProcessingState state) override
Update the processing state of the container.
size_t byte_size() const
Total byte count of the pixel buffer.
void download_data(const std::shared_ptr< Core::VKImage > &image, void *data, size_t size, const std::shared_ptr< Buffers::VKBuffer > &staging, bool deferred=false, vk::ImageLayout restore_layout=vk::ImageLayout::eShaderReadOnlyOptimal, vk::PipelineStageFlags restore_stage=vk::PipelineStageFlagBits::eFragmentShader)
Download pixel data from a VKImage, reusing a caller-supplied persistent staging buffer.
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
@ READY
Container has data loaded and is ready for processing.
DataVariant make_empty_storage(ImageFormat format, size_t element_count)
Allocate a zeroed DataVariant of the alternative backing a format.
std::pair< uint8_t *, size_t > variant_bytes_mutable(DataVariant &v)
Get a mutable pointer to the raw bytes of a DataVariant and its size.

References byte_size(), MayaFlux::Journal::ContainerProcessing, MayaFlux::Portal::Graphics::TextureLoom::download_data(), image, MayaFlux::Portal::Graphics::TextureLoom::instance(), MayaFlux::Journal::Kakshya, m_channels, m_cpu_stale, m_data, m_format, m_height, m_normalised_dirty, m_slot_locks, m_width, MayaFlux::Kakshya::make_empty_storage(), MF_ERROR, ptr, MayaFlux::Kakshya::READY, update_processing_state(), and MayaFlux::Kakshya::variant_bytes_mutable().

+ Here is the call graph for this function: