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

◆ clear_gpu_buffer()

MAYAFLUX_API bool MayaFlux::Buffers::clear_gpu_buffer ( const std::shared_ptr< VKBuffer > &  target)

Zero a registered GPU buffer in place (auto-detects host-visible vs device-local)

Parameters
targetBuffer to clear
Returns
True if the buffer was cleared

Mapped buffers are cleared on the host. Unmapped buffers are filled on the GPU with no staging allocation, and the call blocks until the fill is done. Handles and device addresses are unchanged. Logs an error and returns false if the buffer is null or unregistered, lacks transfer destination usage, or the BufferService is unavailable. Never throws.

Definition at line 707 of file StagingUtils.cpp.

708{
709 if (!target || !target->is_initialized()) {
710 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
711 "clear_gpu_buffer: buffer is null or not registered");
712 return false;
713 }
714
715 if (target->is_host_visible() && target->get_mapped_ptr()) {
716 std::memset(target->get_mapped_ptr(), 0, target->get_size_bytes());
717 return true;
718 }
719
720 if (!(target->get_usage_flags() & vk::BufferUsageFlagBits::eTransferDst)) {
721 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
722 "clear_gpu_buffer: unmapped buffer usage lacks transfer destination");
723 return false;
724 }
725
726 auto* buffer_service = Registry::BackendRegistry::instance()
727 .get_service<Registry::Service::BufferService>();
728
729 if (!buffer_service || !buffer_service->execute_immediate) {
730 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
731 "clear_gpu_buffer: BufferService unavailable");
732 return false;
733 }
734
735 const vk::Buffer buffer = target->get_buffer_resources().buffer;
736 buffer_service->execute_immediate([buffer](void* command_buffer) {
737 vk::CommandBuffer cmd(static_cast<VkCommandBuffer>(command_buffer));
738 cmd.fillBuffer(buffer, 0, VK_WHOLE_SIZE, 0);
739 });
740
741 return true;
742}
#define MF_ERROR(comp, ctx,...)
vk::CommandBuffer cmd
std::shared_ptr< NetworkGeometryBuffer > buffer

References buffer, MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, cmd, MayaFlux::Registry::BackendRegistry::get_service(), MayaFlux::Registry::BackendRegistry::instance(), and MF_ERROR.

Referenced by MayaFlux::Buffers::VKBuffer::clear().

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