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

◆ ensure_cpu()

void MayaFlux::Kakshya::TextureContainer::ensure_cpu ( uint32_t  layer) const
private

Download a GPU-held layer into m_data before a CPU read.

Definition at line 155 of file TextureContainer.cpp.

156{
157 if (layer >= m_cpu_stale.size() || !m_cpu_stale[layer].load(std::memory_order_acquire))
158 return;
159
160 std::shared_ptr<Core::VKImage> image;
161 {
162 Memory::SerializedSeqlockWriteGuard image_guard(m_image_cache_lock);
163 image = m_layer_image_cache[layer].image;
164 }
165
166 const size_t element_count = static_cast<size_t>(m_width) * m_height * m_channels;
167
168 Memory::SerializedSeqlockWriteGuard g(m_slot_locks[layer]);
169 if (!m_cpu_stale[layer].load(std::memory_order_acquire))
170 return;
171
172 m_data[layer] = make_empty_storage(m_format, element_count);
173 auto [ptr, bytes] = variant_bytes_mutable(m_data[layer]);
174 if (image && image->is_initialized() && ptr && bytes == byte_size()) {
175 TextureLoom::instance().download_data(image, ptr, bytes, nullptr);
176 } else {
178 "TextureContainer: GPU-held layer {} could not be downloaded", layer);
179 }
180
181 m_cpu_stale[layer].store(false, std::memory_order_release);
182 m_normalised_dirty[layer].store(true, std::memory_order_release);
183}
#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.
std::vector< Portal::Graphics::ImageCacheEntry > m_layer_image_cache
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.
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_image_cache_lock, m_layer_image_cache, m_normalised_dirty, m_slot_locks, m_width, MayaFlux::Kakshya::make_empty_storage(), MF_ERROR, ptr, and MayaFlux::Kakshya::variant_bytes_mutable().

Referenced by as_float(), as_normalised_float(), as_uint16(), as_uint8(), channel_data(), ensure_cpu_all(), get_frames_typed_as(), get_raw_data(), get_region_data(), get_value_impl(), pixel_bytes(), pixel_bytes(), set_region_data(), set_value_impl(), and upload_image().

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