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

◆ upload_image_data() [2/2]

void MayaFlux::Core::BackendResourceManager::upload_image_data ( std::shared_ptr< VKImage >  image,
const void *  data,
size_t  size,
const std::shared_ptr< Buffers::VKBuffer > &  staging,
bool  deferred = false 
)

Upload image data using a caller-supplied persistent staging buffer.

Identical to upload_image_data() but skips the per-call VkBuffer allocation. The staging buffer must be host-visible and at least size bytes. Intended for high-frequency streaming uploads.

Parameters
imageTarget VKImage.
dataSource pixel data pointer.
sizeByte count.
stagingPre-allocated host-visible staging buffer.
deferredIf true, command recording will be deferred and must be flushed

Definition at line 771 of file BackendResoureManager.cpp.

776{
777 if (!image || !data || !staging) {
779 "Invalid parameters for upload_image_data_with_staging");
780 return;
781 }
782
783 void* mapped = staging->get_mapped_ptr();
784 if (!mapped) {
786 "upload_image_data_with_staging: staging buffer has no mapped pointer");
787 return;
788 }
789
790 std::memcpy(mapped, data, size);
791 staging->mark_dirty_range(0, size);
792
793 auto& resources = staging->get_buffer_resources();
794 vk::MappedMemoryRange range { resources.memory, 0, VK_WHOLE_SIZE };
795
796 if (auto result = m_context.get_device().flushMappedMemoryRanges(1, &range);
797 result != vk::Result::eSuccess) {
799 "upload_image_data_with_staging: flush failed: {}", vk::to_string(result));
800 }
801
802 auto record_command = [&](vk::CommandBuffer cmd) {
803 vk::ImageMemoryBarrier barrier {};
804 barrier.oldLayout = image->get_current_layout();
805 barrier.newLayout = vk::ImageLayout::eTransferDstOptimal;
806 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
807 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
808 barrier.image = image->get_image();
809 barrier.subresourceRange = {
810 image->get_aspect_flags(), 0,
811 image->get_mip_levels(), 0,
812 image->get_array_layers()
813 };
814 barrier.srcAccessMask = vk::AccessFlagBits::eShaderRead;
815 barrier.dstAccessMask = vk::AccessFlagBits::eTransferWrite;
816
817 cmd.pipelineBarrier(
818 vk::PipelineStageFlagBits::eFragmentShader,
819 vk::PipelineStageFlagBits::eTransfer,
820 {}, 0, nullptr, 0, nullptr, 1, &barrier);
821
822 vk::BufferImageCopy region {};
823 region.imageSubresource.aspectMask = image->get_aspect_flags();
824 region.imageSubresource.layerCount = image->get_array_layers();
825 region.imageOffset = vk::Offset3D { 0, 0, 0 };
826 region.imageExtent = vk::Extent3D {
827 image->get_width(),
828 image->get_height(),
829 image->get_depth()
830 };
831
832 cmd.copyBufferToImage(
833 staging->get_buffer(),
834 image->get_image(),
835 vk::ImageLayout::eTransferDstOptimal,
836 1, &region);
837
838 barrier.oldLayout = vk::ImageLayout::eTransferDstOptimal;
839 barrier.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
840 barrier.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
841 barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead;
842
843 cmd.pipelineBarrier(
844 vk::PipelineStageFlagBits::eTransfer,
845 vk::PipelineStageFlagBits::eFragmentShader,
846 {}, 0, nullptr, 0, nullptr, 1, &barrier);
847 };
848
849 if (deferred) {
850 record_deferred_commands(record_command);
851 } else {
852 execute_immediate_commands(record_command);
853 }
854
855 image->set_current_layout(vk::ImageLayout::eShaderReadOnlyOptimal);
856
858 "upload_image_data_with_staging: {} bytes to image {}x{}",
859 size, image->get_width(), image->get_height());
860}
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
vk::CommandBuffer cmd
IO::ImageData image
Definition Decoder.cpp:47
bool size
void execute_immediate_commands(const std::function< void(vk::CommandBuffer)> &recorder)
Execute immediate command recording for buffer operations.
void record_deferred_commands(const std::function< void(vk::CommandBuffer)> &recorder)
Record deferred command recording for buffer operations.
vk::Device get_device() const
Get logical device.
Definition VKContext.hpp:49
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.
std::vector< double > range(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Value range (max - min) per window.
Definition Analysis.cpp:452

References cmd, MayaFlux::Journal::Core, execute_immediate_commands(), MayaFlux::Core::VKContext::get_device(), MayaFlux::Journal::GraphicsBackend, image, m_context, MF_DEBUG, MF_ERROR, record_deferred_commands(), and size.

+ Here is the call graph for this function: