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

◆ cached_layer_image()

std::shared_ptr< Core::VKImage > MayaFlux::Kakshya::TextureContainer::cached_layer_image ( uint32_t  layer,
const std::shared_ptr< Buffers::VKBuffer > &  staging 
) const
private

Definition at line 361 of file TextureContainer.cpp.

363{
364 if (layer >= m_data.size()) {
366 "TextureContainer::to_image layer {} out of range ({})", layer, m_data.size());
367 return nullptr;
368 }
369
370 if (m_cpu_stale[layer].load(std::memory_order_acquire)) {
371 Memory::SerializedSeqlockWriteGuard image_guard(m_image_cache_lock);
372 return m_layer_image_cache[layer].image;
373 }
374
375 const size_t expected = byte_size();
376 auto pixels = seqlock_read(m_slot_locks[layer], 8, [&]() -> std::vector<uint8_t> {
377 auto [ptr, bytes] = variant_bytes(m_data[layer]);
378 if (!ptr || bytes != expected)
379 return {};
380 return { ptr, ptr + bytes };
381 });
382
383 if (!pixels || pixels->empty()) {
385 "TextureContainer::to_image called on empty or invalid layer {}", layer);
386 return nullptr;
387 }
388
389 const Portal::Graphics::ImageKey key {
390 .width = m_width, .height = m_height, .layers = 1, .format = m_format
391 };
392 Memory::SerializedSeqlockWriteGuard image_guard(m_image_cache_lock);
394 m_layer_image_cache[layer], key, *pixels, staging);
395}
#define MF_ERROR(comp, ctx,...)
const std::vector< float > * pixels
Definition Decoder.cpp:48
const uint8_t * ptr
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.
std::vector< Portal::Graphics::ImageCacheEntry > m_layer_image_cache
size_t byte_size() const
Total byte count of the pixel buffer.
std::shared_ptr< Core::VKImage > refresh_cached_image(ImageCacheEntry &entry, const ImageKey &key, std::span< const uint8_t > pixels, const std::shared_ptr< Buffers::VKBuffer > &staging={})
Refresh a sampled image in an owner-held cache entry.
@ 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
auto seqlock_read(const Seqlock &lock, uint32_t max_attempts, Fn &&fn) -> std::optional< std::invoke_result_t< Fn > >
Invoke a read functor under a Seqlock with a bounded retry count.
Definition SeqLock.hpp:237

References byte_size(), MayaFlux::Journal::ContainerProcessing, MayaFlux::Portal::Graphics::TextureLoom::instance(), MayaFlux::Journal::Kakshya, m_cpu_stale, m_data, m_format, m_height, m_image_cache_lock, m_layer_image_cache, m_slot_locks, m_width, MF_ERROR, pixels, ptr, MayaFlux::Portal::Graphics::TextureLoom::refresh_cached_image(), MayaFlux::Kakshya::variant_bytes(), and MayaFlux::Portal::Graphics::ImageKey::width.

Referenced by cached_array_image(), to_image(), and to_image().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: