MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Buffers::DataWriteProcessor Class Reference

Modality-aware multi-slot write processor for plain VKBuffer. More...

#include <DataWriteProcessor.hpp>

+ Inheritance diagram for MayaFlux::Buffers::DataWriteProcessor:
+ Collaboration diagram for MayaFlux::Buffers::DataWriteProcessor:

Classes

struct  PendingTexture
 

Public Member Functions

 DataWriteProcessor ()
 
bool has_pending () const noexcept
 Returns true if a snapshot has been set and not yet consumed.
 
Kakshya::GpuDataFormat last_texture_format () const noexcept
 Returns the GpuDataFormat resolved on the last texture upload.
 
void set_data (Kakshya::DataVariant variant)
 Supply a single data value for the next cycle (slot 0).
 
void set_data (std::vector< Kakshya::DataVariant > variants)
 Supply multiple data values for the next cycle.
 
void set_pixel_data (Kakshya::DataVariant variant)
 Supply pixel data for the co-resident texture on the next cycle.
 
void set_texture (std::shared_ptr< Core::VKImage > image, std::string binding)
 Supply a texture to bind on the next graphics tick.
 
void set_vertices (const void *data, size_t byte_count)
 Supply pre-packed interleaved vertex bytes for the next cycle.
 
template<typename T >
void set_vertices (std::span< const T > vertices)
 Supply typed vertex data for the next cycle.
 
void setup_pixel_target (uint32_t width, uint32_t height, Portal::Graphics::ImageFormat format, std::string binding="texSampler")
 Configure the pixel upload path for texture modalities.
 
void write_back_buffer (size_t index, Kakshya::DataVariant data)
 Write a raw back_buffers slot of the attached buffer.
 
void write_buffer (std::shared_ptr< VKBuffer > target, Kakshya::DataVariant data, size_t dst_offset=0)
 Write bytes into another VKBuffer, such as a plain descriptor-bound buffer.
 
void write_field (std::string name, Kakshya::DataVariant data)
 Write a named field of the attached buffer.
 
void write_mesh (Kakshya::MeshData data, std::string slot={})
 Write mesh geometry to the attached buffer's authoritative copy.
 
void write_pixels (Kakshya::ImageData image)
 Write the retained host pixels of the attached TextureBuffer.
 
void write_texture_pixels (Kakshya::ImageData image)
 Write pixels straight into the attached TextureBuffer's GPU image.
 
 ~DataWriteProcessor () override=default
 
- Public Member Functions inherited from MayaFlux::Buffers::BufferProcessor
virtual ProcessingToken get_processing_token () const
 Gets the current processing token for this buffer.
 
virtual bool is_compatible_with (const std::shared_ptr< Buffer > &) const
 Checks if this processor can handle the specified buffer type.
 
void process (const std::shared_ptr< Buffer > &buffer)
 Applies a computational transformation to the data in the provided buffer.
 
virtual void set_processing_token (ProcessingToken token)
 Gets the preferred processing backend for this processor.
 
virtual ~BufferProcessor ()=default
 Virtual destructor for proper cleanup of derived classes.
 

Protected Member Functions

void on_attach (const std::shared_ptr< Buffer > &buffer) override
 Called when this processor is attached to a buffer.
 
void on_detach (const std::shared_ptr< Buffer > &buffer) override
 Called when this processor is detached from a buffer.
 
void processing_function (const std::shared_ptr< Buffer > &buffer) override
 The core processing function that must be implemented by derived classes.
 
- Protected Member Functions inherited from MayaFlux::Buffers::VKBufferProcessor
void ensure_initialized (const std::shared_ptr< VKBuffer > &buffer)
 
void initialize_buffer_service ()
 
void initialize_compute_service ()
 

Private Types

using WriteFn = std::function< void(DataWriteProcessor &, const std::shared_ptr< VKBuffer > &)>
 

Private Member Functions

void enqueue_write (WriteFn fn)
 
void ensure_capacity (const std::shared_ptr< VKBuffer > &vk, size_t required)
 
void upload_primary (const std::shared_ptr< VKBuffer > &vk, std::vector< Kakshya::DataVariant > &slots)
 
void upload_raw (const std::shared_ptr< VKBuffer > &vk, Kakshya::DataVariant &slot)
 
void upload_secondary (const std::shared_ptr< VKBuffer > &vk, Kakshya::DataVariant &slot)
 
void upload_texture (const std::shared_ptr< VKBuffer > &vk, Kakshya::DataVariant &slot)
 
void upload_vertex (const std::shared_ptr< VKBuffer > &vk, std::vector< Kakshya::DataVariant > &slots)
 

Static Private Member Functions

static bool is_texture_modality (Kakshya::DataModality m) noexcept
 
static bool is_vertex_modality (Kakshya::DataModality m) noexcept
 

Private Attributes

std::vector< Kakshya::DataVariant > m_active
 
std::atomic_flag m_data_dirty
 
std::vector< Kakshya::DataVariant > m_data_pending
 
std::shared_ptr< Core::VKImage > m_gpu_texture
 
std::shared_ptr< VKBuffer > m_image_staging
 
Kakshya::GpuDataFormat m_last_texture_format { Kakshya::GpuDataFormat::VEC4_F32 }
 
Kakshya::DataModality m_modality { Kakshya::DataModality::UNKNOWN }
 
std::optional< PendingTexture > m_pending_texture
 
Kakshya::DataVariant m_pixel_active
 
std::atomic_flag m_pixel_dirty
 
Kakshya::DataVariant m_pixel_pending
 
std::shared_ptr< VKBuffer > m_staging
 
std::string m_tex_binding
 
bool m_tex_binding_confirmed {}
 
Portal::Graphics::ImageFormat m_tex_format { Portal::Graphics::ImageFormat::RGBA32F }
 
uint32_t m_tex_height {}
 
uint32_t m_tex_width {}
 
std::atomic_flag m_texture_dirty
 
Portal::Graphics::PrimitiveTopology m_topology { Portal::Graphics::PrimitiveTopology::POINT_LIST }
 
std::shared_ptr< VKBuffer > m_write_image_staging
 
std::shared_ptr< VKBuffer > m_write_staging
 
std::unique_ptr< Memory::LockFreeQueue< WriteFn, k_write_queue_capacity > > m_writes
 

Static Private Attributes

static constexpr size_t k_write_queue_capacity = 64
 

Additional Inherited Members

- Protected Attributes inherited from MayaFlux::Buffers::VKBufferProcessor
Registry::Service::BufferService * m_buffer_service = nullptr
 
Registry::Service::ComputeService * m_compute_service = nullptr
 
- Protected Attributes inherited from MayaFlux::Buffers::BufferProcessor
ProcessingToken m_processing_token { ProcessingToken::AUDIO_BACKEND }
 

Detailed Description

Modality-aware multi-slot write processor for plain VKBuffer.

Accepts one or more DataVariant values per cycle. Slot 0 is the primary upload path and is routed by the attached buffer's DataModality:

  • VERTICES_3D and single-attribute vertex modalities (VERTEX_POSITIONS_3D, VERTEX_NORMALS_3D, VERTEX_TANGENTS_3D, VERTEX_COLORS_RGB, VERTEX_COLORS_RGBA, TEXTURE_COORDS_2D): all slots are passed as an ordered channel span to as_*_vertex_access(). Full 60-byte vertices are always assembled; partial channel sets are completed from VertexAccessConfig defaults.
  • Texture modalities (IMAGE_2D, IMAGE_COLOR, TEXTURE_2D): routed through Kakshya::as_texture_access(). GpuDataFormat from the result is available via last_texture_format() for pipeline configuration.
  • All other modalities: raw bytes via DataAccess::gpu_buffer(). Zero-copy when the variant type matches the target layout.

Slot 1..N are uploaded raw via DataAccess::gpu_buffer() regardless of modality. These are intended for secondary data (e.g. a texture payload alongside vertex data) where the caller has configured the corresponding descriptor bindings on the RenderProcessor.

Modality is read from the attached VKBuffer in on_attach(). The processor warns if the supplied DataVariant is incompatible with that modality.

Dirty gating: upload occurs only when set_data() has been called since the last cycle. No stale re-upload.

Thread safety: set_data() and the graphics thread may run concurrently. Lock-free double-buffer swap via atomic_flag ensures the graphics thread never blocks on the supplier thread.

Staging: a persistent host-visible staging buffer is allocated on on_attach() when the target is device-local, and reused every cycle.

The write_* requests reach targets beyond the primary storage: another VKBuffer, a named field, a raw back_buffers slot, mesh geometry, and texture pixels. Each is a one-shot request applied at the start of the next graphics cycle, ahead of the set_* upload, in the order it was made. Each writes to the authority of its target, never to a GPU copy that its owner regenerates: meshes go to the owning MeshData or node, retained pixels to the TextureBuffer, and the rest to the GPU storage their owners read from. Attach the processor before the producers that consume the written data. Requests come from one supplier thread, as with set_data().

Intended for use with plain VKBuffer where no specialised child class exists for the data being contributed. The caller is responsible for configuring a matching RenderProcessor via VKBuffer::setup_rendering().

Definition at line 64 of file DataWriteProcessor.hpp.


The documentation for this class was generated from the following files: