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

◆ clone_to() [2/2]

std::shared_ptr< Buffers::VKBuffer > MayaFlux::Buffers::VKBuffer::clone_to ( Usage  usage)

Create a clone of this buffer with the same data and properties.

Parameters
usageUsage enum for the cloned buffer
Returns
Shared pointer to the cloned VKBuffer

The cloned buffer will have the same size, modality, dimensions, processing chain and default processor as the original. Changes to one buffer after cloning do not affect the other.

Definition at line 460 of file VKBuffer.cpp.

461{
462 auto buffer = std::make_shared<VKBuffer>(m_size_bytes, usage, m_modality);
463
464 if (auto layout = get_vertex_layout(); layout.has_value()) {
465 buffer->set_vertex_layout(layout.value());
466 }
467
468 buffer->set_processing_chain(get_processing_chain());
469 buffer->set_default_processor(get_default_processor());
470
471 if (is_host_visible()) {
472 if (buffer->is_host_visible()) {
473 auto src_ptr = static_cast<uint8_t*>(m_resources.mapped_ptr);
474 buffer->set_data({ std::vector<uint8_t>(src_ptr, src_ptr + m_size_bytes) });
475 } else {
477 std::dynamic_pointer_cast<VKBuffer>(shared_from_this()),
478 buffer,
479 nullptr);
480 }
481 } else {
482 if (buffer->is_host_visible()) {
484 buffer,
485 std::dynamic_pointer_cast<VKBuffer>(shared_from_this()),
486 get_data()[0]);
487 } else {
489 "Cloning device-local VKBuffer to another device-local VKBuffer requires external data transfer");
490 }
491 }
492
493 return buffer;
494}
#define MF_WARN(comp, ctx,...)
std::shared_ptr< NetworkGeometryBuffer > buffer
uint16_t usage
std::vector< Kakshya::DataVariant > get_data()
Read buffer contents as Kakshya DataVariant.
Definition VKBuffer.cpp:121
std::shared_ptr< Buffers::BufferProcessor > get_default_processor() const override
Get the currently attached default processor.
Definition VKBuffer.cpp:266
std::shared_ptr< Buffers::BufferProcessingChain > get_processing_chain() override
Access the buffer's processing chain.
Definition VKBuffer.cpp:271
std::optional< Kakshya::VertexLayout > get_vertex_layout() const
Get vertex layout if set.
Definition VKBuffer.hpp:513
VKBufferResources m_resources
Definition VKBuffer.hpp:657
Kakshya::DataModality m_modality
Definition VKBuffer.hpp:665
bool is_host_visible() const
Whether this VKBuffer should be host-visible.
Definition VKBuffer.hpp:373
void download_device_local(const std::shared_ptr< VKBuffer > &source, const std::shared_ptr< VKBuffer > &target, const std::shared_ptr< VKBuffer > &staging_buffer)
Download data from a device-local buffer using a staging buffer.
void upload_device_local(const std::shared_ptr< VKBuffer > &target, const std::shared_ptr< VKBuffer > &staging_buffer, const Kakshya::DataVariant &data, size_t dst_offset)
Upload data to a device-local buffer using a staging buffer.
@ BufferManagement
Buffer Management (Buffers::BufferManager, creating buffers)
@ Buffers
Buffers, Managers, processors and processing chains.

References buffer, MayaFlux::Journal::BufferManagement, MayaFlux::Journal::Buffers, MayaFlux::Buffers::download_device_local(), get_data(), get_default_processor(), get_processing_chain(), get_vertex_layout(), is_host_visible(), m_modality, m_resources, m_size_bytes, MayaFlux::Buffers::VKBufferResources::mapped_ptr, MF_WARN, MayaFlux::Buffers::upload_device_local(), and usage.

+ Here is the call graph for this function: