MayaFlux 0.4.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 726 of file BackendResoureManager.cpp.

731{
732 if (!image || !data || !staging) {
734 "Invalid parameters for upload_image_data_with_staging");
735 return;
736 }
737
738 void* mapped = staging->get_mapped_ptr();
739 if (!mapped) {
741 "upload_image_data_with_staging: staging buffer has no mapped pointer");
742 return;
743 }
744
745 std::memcpy(mapped, data, size);
746 staging->mark_dirty_range(0, size);
747
748 auto& resources = staging->get_buffer_resources();
749 vk::MappedMemoryRange range { resources.memory, 0, VK_WHOLE_SIZE };
750
751 if (auto result = m_context.get_device().flushMappedMemoryRanges(1, &range);
752 result != vk::Result::eSuccess) {
754 "upload_image_data_with_staging: flush failed: {}", vk::to_string(result));
755 }
756
757 auto record_command = [&](vk::CommandBuffer cmd) {
758 vk::ImageMemoryBarrier barrier {};
759 barrier.oldLayout = image->get_current_layout();
760 barrier.newLayout = vk::ImageLayout::eTransferDstOptimal;
761 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
762 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
763 barrier.image = image->get_image();
764 barrier.subresourceRange = {
765 image->get_aspect_flags(), 0,
766 image->get_mip_levels(), 0,
767 image->get_array_layers()
768 };
769 barrier.srcAccessMask = vk::AccessFlagBits::eShaderRead;
770 barrier.dstAccessMask = vk::AccessFlagBits::eTransferWrite;
771
772 cmd.pipelineBarrier(
773 vk::PipelineStageFlagBits::eFragmentShader,
774 vk::PipelineStageFlagBits::eTransfer,
775 {}, 0, nullptr, 0, nullptr, 1, &barrier);
776
777 vk::BufferImageCopy region {};
778 region.imageSubresource.aspectMask = image->get_aspect_flags();
779 region.imageSubresource.layerCount = image->get_array_layers();
780 region.imageOffset = vk::Offset3D { 0, 0, 0 };
781 region.imageExtent = vk::Extent3D {
782 image->get_width(),
783 image->get_height(),
784 image->get_depth()
785 };
786
787 cmd.copyBufferToImage(
788 staging->get_buffer(),
789 image->get_image(),
790 vk::ImageLayout::eTransferDstOptimal,
791 1, &region);
792
793 barrier.oldLayout = vk::ImageLayout::eTransferDstOptimal;
794 barrier.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
795 barrier.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
796 barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead;
797
798 cmd.pipelineBarrier(
799 vk::PipelineStageFlagBits::eTransfer,
800 vk::PipelineStageFlagBits::eFragmentShader,
801 {}, 0, nullptr, 0, nullptr, 1, &barrier);
802 };
803
804 if (deferred) {
805 record_deferred_commands(record_command);
806 } else {
807 execute_immediate_commands(record_command);
808 }
809
810 image->set_current_layout(vk::ImageLayout::eShaderReadOnlyOptimal);
811
813 "upload_image_data_with_staging: {} bytes to image {}x{}",
814 size, image->get_width(), image->get_height());
815}
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
vk::CommandBuffer cmd
IO::ImageData image
Definition Decoder.cpp:57
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, and record_deferred_commands().

+ Here is the call graph for this function: