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

A TextureBuffer whose image is a stack of layers, composed in one draw. More...

#include <TextureArrayBuffer.hpp>

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

Classes

struct  Push
 

Public Member Functions

void enable_layer_data ()
 Create the per-layer buffer the shader reads as layerData.
 
size_t get_layer_byte_size () const
 Bytes in one layer.
 
uint32_t get_layer_count () const
 Number of layers.
 
uint32_t get_write_head () const
 The layer the next push_layer writes.
 
bool has_layer_data () const
 Whether the per-layer buffer exists.
 
template<typename Source >
bool push_layer (const Source &source)
 Write a frame at the write head and advance it, wrapping at the last layer.
 
void set_fit (std::optional< Portal::Graphics::FitMode > fit, Portal::Graphics::FilterMode filter=Portal::Graphics::FilterMode::LINEAR)
 Choose what happens to a frame whose extent differs from the layer.
 
void set_layer_fit (uint32_t layer, std::optional< Portal::Graphics::FitMode > fit)
 Give one layer its own fit, replacing the one from set_fit for that layer.
 
void set_layer_params (uint32_t layer, const glm::vec4 &values)
 Set the params of one layer, layerData[2 * layer].
 
void set_layer_timing (uint32_t layer, const glm::vec4 &values)
 Set the timing of one layer, layerData[2 * layer + 1].
 
void set_mode (uint32_t mode)
 Set the mode number passed to the shader.
 
template<typename T >
void set_push_constants (const T &block)
 Replace the default push constants with a block of type T.
 
void set_push_constants (const void *data, size_t size)
 Replace the default push constants with the shader's own.
 
void set_weight (uint32_t layer, float weight)
 Set the weight of one layer.
 
void set_weights (std::span< const float > weights)
 Set the weights of the first layers in order.
 
void setup_processors (ProcessingToken token) override
 Setup processors with a processing token.
 
void setup_rendering (const RenderConfig &config) override
 Setup rendering with RenderProcessor.
 
bool submit_layer (uint32_t layer, const Kakshya::ImageData &image)
 Replace the frame of one layer with an image.
 
bool submit_layer (uint32_t layer, const std::shared_ptr< Core::VKImage > &image)
 Replace the frame of one layer with a GPU image, with no host read.
 
bool submit_layer (uint32_t layer, std::span< const uint8_t > pixels)
 Replace the frame of one layer with raw pixels.
 
 TextureArrayBuffer (const Kakshya::VideoStreamSpec &spec, std::optional< Portal::Graphics::FitMode > fit=Portal::Graphics::FitMode::STRETCH)
 Build from a stream spec: width, height and format of every layer, with ring_frames as the layer count.
 
 TextureArrayBuffer (uint32_t width, uint32_t height, Portal::Graphics::ImageFormat format, uint32_t layers)
 
- Public Member Functions inherited from MayaFlux::Buffers::TextureBuffer
void clear_dirty_flag ()
 
Portal::Graphics::ImageFormat get_format () const
 
std::shared_ptr< Core::VKImage > get_gpu_texture ()
 Get the GPU texture image.
 
std::shared_ptr< Core::VKImage > get_gpu_texture () const
 
uint32_t get_height () const
 
const std::vector< uint8_t > & get_pixel_data () const
 
std::vector< uint8_t > & get_pixel_data_mutable ()
 
glm::vec2 get_position () const
 
float get_rotation () const
 
glm::vec2 get_scale () const
 
std::shared_ptr< Core::VKImage > get_texture () const
 Get GPU texture image Suitable for binding to shaders via RenderProcessor::bind_texture()
 
std::shared_ptr< TextureProcessor > get_texture_processor () const
 
uint32_t get_width () const
 
bool has_texture () const
 
bool is_texture_dirty () const
 
void mark_pixels_dirty ()
 Mark pixel data as changed Use this if you modify pixel data in-place without calling set_pixel_data()
 
void mark_texture_dirty ()
 
void resize_texture (uint32_t new_width, uint32_t new_height)
 Reallocate the GPU texture at new dimensions.
 
void set_custom_vertices (const std::vector< Kakshya::TextureQuadVertex > &vertices)
 
void set_gpu_texture (std::shared_ptr< Core::VKImage > image)
 Inject a pre-existing GPU texture, bypassing TextureProcessor allocation.
 
void set_pixel_data (const void *data, size_t size)
 Replace pixel data.
 
void set_position (float x, float y)
 Set screen position (NDC or pixel coords depending on rendering setup)
 
void set_rotation (float angle_radians)
 Set rotation around center.
 
void set_scale (float width, float height)
 Set display size.
 
void setup_processors (ProcessingToken token) override
 Setup processors with a processing token.
 
 TextureBuffer (uint32_t width, uint32_t height, Portal::Graphics::ImageFormat format, const void *initial_pixel_data=nullptr)
 Create texture buffer with dimensions.
 
void use_default_quad ()
 Reset to default fullscreen quad Uses position and scale to generate quad geometry.
 
 ~TextureBuffer () override=default
 
- Public Member Functions inherited from MayaFlux::Buffers::VKBuffer
void clear () override
 Clear buffer contents.
 
void clear_pipeline_commands ()
 Clear all recorded commands (called after presentation)
 
void clear_vertex_layout ()
 Clear vertex layout.
 
std::shared_ptr< Buffer > clone_to (uint8_t dest_desc) override
 Creates a clone of this buffer for a specific channel or usage enum.
 
std::shared_ptr< VKBuffer > clone_to (Usage usage)
 Create a clone of this buffer with the same data and properties.
 
void enforce_default_processing (bool should_process) override
 Controls whether the buffer should use default processing.
 
void force_internal_usage (bool internal) override
 Set whether this buffer is for internal engine usage.
 
std::vector< std::shared_ptr< RenderProcessor > > get_additional_render_processors ()
 Get additional live render processors attached through the chain.
 
std::vector< std::pair< size_t, size_t > > get_and_clear_dirty_ranges ()
 Retrieve and clear all dirty ranges.
 
std::vector< std::pair< size_t, size_t > > get_and_clear_invalid_ranges ()
 Retrieve and clear all invalid ranges.
 
vk::Buffer & get_buffer ()
 Get VkBuffer handle (VK_NULL_HANDLE if not registered)
 
VKBufferResources & get_buffer_resources ()
 Get all buffer resources at once (mutable).
 
const VKBufferResources & get_buffer_resources () const
 Get all buffer resources at once (read-only)
 
std::vector< Kakshya::DataVariant > get_data ()
 Read buffer contents as Kakshya DataVariant.
 
std::shared_ptr< Buffers::BufferProcessor > get_default_processor () const override
 Get the currently attached default processor.
 
uint64_t get_device_address () const
 Get the Vulkan device address for this buffer (if applicable)
 
const std::vector< Kakshya::DataDimension > & get_dimensions () const
 Get the inferred data dimensions for the buffer contents.
 
EngineContext & get_engine_context ()
 
const EngineContext & get_engine_context () const
 
vk::Buffer get_index_buffer () const
 Return the raw index buffer handle.
 
size_t get_index_buffer_size () const
 Number of bytes in the index buffer.
 
void * get_mapped_ptr () const
 Get mapped host pointer (nullptr if not host-visible or unmapped)
 
vk::MemoryPropertyFlags get_memory_properties () const
 Get appropriate VkMemoryPropertyFlags for allocation based on Usage.
 
Kakshya::DataModality get_modality () const
 Get the buffer's semantic modality.
 
CommandBufferID get_pipeline_command (RenderPipelineID pipeline_id) const
 Get recorded command buffer for a pipeline.
 
PipelineContext & get_pipeline_context ()
 Access the pipeline context for custom metadata (non-const)
 
const PipelineContext & get_pipeline_context () const
 Access the pipeline context for custom metadata (const)
 
std::shared_ptr< Core::Window > get_pipeline_window (RenderPipelineID id) const
 Get the window associated with this buffer.
 
std::shared_ptr< Buffers::BufferProcessingChain > get_processing_chain () override
 Access the buffer's processing chain.
 
RenderConfig get_render_config () const
 Get the current render configuration.
 
std::unordered_map< RenderPipelineID, std::shared_ptr< Core::Window > > get_render_pipelines () const
 Get all render pipelines associated with this buffer.
 
virtual std::shared_ptr< RenderProcessor > get_render_processor () const
 Get a RenderProcessor suitable for rendering this buffer.
 
std::shared_ptr< RenderProcessor > get_render_processor (RenderPipelineID id)
 Find the attached render processor responsible for a pipeline.
 
size_t get_size () const
 Get current logical size in bytes.
 
vk::DeviceSize get_size_bytes () const
 
Usage get_usage () const
 Retrieve the declared usage intent.
 
vk::BufferUsageFlags get_usage_flags () const
 Get appropriate VkBufferUsageFlags for creation based on Usage.
 
std::optional< Kakshya::VertexLayout > get_vertex_layout () const
 Get vertex layout if set.
 
bool has_data_for_cycle () const override
 Checks if the buffer has data for the current processing cycle.
 
bool has_index_buffer () const
 True when an index buffer has been associated with this buffer.
 
bool has_render_pipeline () const
 Check if this buffer has a rendering pipeline configured.
 
bool has_vertex_layout () const
 Check if this buffer has vertex layout configured.
 
bool is_host_visible () const
 Whether this VKBuffer should be host-visible.
 
bool is_initialized () const
 Check whether Vulkan handles are present (buffer registered)
 
bool is_internal_only () const override
 Check whether this buffer is for internal engine usage.
 
bool is_processing () const override
 Query whether the buffer is currently being processed.
 
bool is_render_config_dirty () const
 Check if config has changed since last frame.
 
void mark_dirty_range (size_t offset, size_t size)
 Get device memory handle.
 
void mark_for_processing (bool has_data) override
 Marks the buffer's data availability for the current processing cycle.
 
void mark_for_removal () override
 Marks the buffer for removal from processing chains.
 
void mark_invalid_range (size_t offset, size_t size)
 Mark a range as invalid (needs download)
 
virtual void mark_render_config_dirty (bool is_dirty=true)
 Mark config as changed (processors will detect and react)
 
bool needs_default_processing () override
 Checks if the buffer should undergo default processing.
 
bool needs_depth_attachment () const
 Check if this buffer requires depth attachment for rendering.
 
bool needs_removal () const override
 Checks if the buffer should be removed from processing chains.
 
void process_default () override
 Run the buffer's default processor (if set and enabled)
 
void release_processing () override
 Release previously acquired processing lock.
 
void remove_pipeline_window (RenderPipelineID id)
 Withdraw one pipeline and request presentation of its former window.
 
void request_presentation_refresh (const std::shared_ptr< Core::Window > &window)
 Queue a composition change independently of buffer processing.
 
void resize (size_t new_size, bool preserve_data=false)
 Resize buffer and recreate GPU resources if needed.
 
void set_buffer (vk::Buffer buffer)
 Set VkBuffer handle after backend allocation.
 
void set_buffer_resources (const VKBufferResources &resources)
 Set all buffer resources at once.
 
void set_data (const std::vector< Kakshya::DataVariant > &data)
 Write data into the buffer.
 
void set_default_processor (const std::shared_ptr< BufferProcessor > &processor) override
 Set the buffer's default processor.
 
void set_index_resources (vk::Buffer buf, vk::DeviceMemory mem, size_t size)
 Store raw index buffer handles produced by the geometry upload path.
 
void set_mapped_ptr (void *ptr)
 Set mapped host pointer (for host-visible allocations)
 
void set_memory (vk::DeviceMemory memory)
 Set device memory handle after backend allocation.
 
void set_modality (Kakshya::DataModality modality)
 Update the semantic modality and re-infer dimensions.
 
void set_needs_depth_attachment (bool needs)
 Mark this buffer as requiring depth testing when rendered.
 
void set_pipeline_command (RenderPipelineID pipeline_id, CommandBufferID cmd_id)
 Store recorded command buffer for a pipeline.
 
void set_pipeline_window (RenderPipelineID id, const std::shared_ptr< Core::Window > &window)
 Associate this buffer with a window for rendering.
 
void set_processing_chain (const std::shared_ptr< BufferProcessingChain > &chain, bool force=false) override
 Replace the buffer's processing chain.
 
virtual void set_render_config (const RenderConfig &config)
 Update the render configuration and mark as dirty.
 
void set_render_processor (std::shared_ptr< RenderProcessor > rp)
 
void set_vertex_layout (const Kakshya::VertexLayout &layout)
 Set vertex layout for this buffer.
 
std::unordered_set< std::shared_ptr< Core::Window > > take_presentation_refreshes ()
 Transfer pending composition changes to the owning graphics root.
 
bool try_acquire_processing () override
 Try to acquire processing lock for this buffer.
 
 VKBuffer ()=default
 
 VKBuffer (size_t size_bytes, Usage usage, Kakshya::DataModality modality=Kakshya::DataModality::VERTICES_3D)
 Construct an unregistered VKBuffer.
 
 ~VKBuffer () override
 Virtual destructor.
 
- Public Member Functions inherited from MayaFlux::Buffers::Buffer
virtual ~Buffer ()=default
 Virtual destructor for proper resource management.
 

Static Public Attributes

static constexpr uint32_t WEIGHT_SLOTS = 30
 Layers the shipped push constant block carries weights for.
 

Private Member Functions

void bind_layer_data ()
 
void clear_layer (uint32_t layer)
 
void ensure_array ()
 
void enter_layer_mode ()
 
std::optional< Portal::Graphics::FitMode > fit_for (uint32_t layer) const
 
void flush_push ()
 
void write_layer_value (size_t index, const glm::vec4 &values)
 

Private Attributes

std::vector< uint8_t > m_blank
 
std::vector< uint8_t > m_custom_push
 
Portal::Graphics::FilterMode m_filter { Portal::Graphics::FilterMode::LINEAR }
 
std::optional< Portal::Graphics::FitMode > m_fit { Portal::Graphics::FitMode::STRETCH }
 
size_t m_layer_bytes
 
std::shared_ptr< VKBuffer > m_layer_data
 
std::unordered_map< uint32_t, std::optional< Portal::Graphics::FitMode > > m_layer_fit
 
bool m_layer_mode {}
 
std::shared_ptr< VKBuffer > m_layer_staging
 
std::vector< glm::vec4 > m_layer_values
 
uint32_t m_layers
 
Push m_push
 
Portal::Graphics::ImageCacheEntry m_source_cache
 
std::shared_ptr< VKBuffer > m_source_staging
 
uint32_t m_write_head {}
 

Additional Inherited Members

- Public Types inherited from MayaFlux::Buffers::VKBuffer
using RenderConfig = Portal::Graphics::RenderConfig
 
using Usage = Portal::Graphics::BufferUsageHint
 
- Protected Member Functions inherited from MayaFlux::Buffers::TextureBuffer
void set_texture_processor (const std::shared_ptr< TextureProcessor > &processor)
 Allow inherited classes to set the TextureProcessor directly.
 
- Protected Member Functions inherited from MayaFlux::Buffers::VKBuffer
void apply_render_config (const RenderConfig &config, const ShaderConfig &shader_config)
 Configure the internal m_render_processor from a RenderConfig.
 
void apply_render_config (std::shared_ptr< RenderProcessor > &render_processor, const RenderConfig &config, const ShaderConfig &shader_config)
 Configure a RenderProcessor, creating one if null.
 
void set_default_render_config (const RenderConfig &config)
 Called by derived classes to set their context-specific defaults.
 
- Protected Attributes inherited from MayaFlux::Buffers::VKBuffer
RenderConfig m_render_config
 
bool m_render_config_dirty {}
 
std::shared_ptr< RenderProcessor > m_render_processor
 

Detailed Description

A TextureBuffer whose image is a stack of layers, composed in one draw.

Each layer is a frame of the same size and format, bound to the fragment shader as a sampler2DArray named textureArray. What the stack means is the shader's choice: a blend, a median, a slit-scan, a delay map, a difference, a mosaic. A layer that is not written keeps its last frame, so sources at different rates can share one array.

A layer is written from raw pixels, an ImageData or a VKImage, by index or at a write head that advances on every push_layer. A frame whose extent differs from the array is dropped, or fitted into the layer with the FitMode chosen by set_fit. A fit leaves any area it does not cover with the layer's previous contents. Raw pixels must already match the layer, and are written through host storage that is uploaded once per cycle. The first VKImage, or an ImageData that needs converting, moves the buffer to writing each layer straight into the image, which keeps layers written either way intact. Every such write completes before the call returns.

A fit that does not cover the whole layer clears the layer first, so a smaller part replacing a larger one leaves nothing of it behind. Each layer may have its own fit through set_layer_fit.

The shipped shader, texture_array.frag, takes a push constant block of the layer count, a mode number whose meaning belongs to the shader, and a weight for each of the first WEIGHT_SLOTS layers. Choose a shader with setup_rendering({ .fragment_shader = ... }). Extra textures such as a delay map, or a second array, go in RenderConfig::additional_textures and bind from binding 2 by the sampler's name. A shader with its own push constants replaces the block through set_push_constants().

Two vec4 per layer reach the shader beyond the push constants once enable_layer_data is called, or set_layer_params is, before the first frame. A shader reads them with layout(set = 1, binding = 0) readonly buffer LayerData { vec4 layerData[]; }; where layerData[2 * layer] holds the params, which are the caller's to use for placement, scale, a mask or anything else, and layerData[2 * layer + 1] holds the timing, which a Chimera fills for the layers it feeds. A shader that does not declare the buffer must not enable it.

Rendering, transform and window targeting are those of TextureBuffer. Reading the buffer back through a texture read returns every layer and is not meant for this class. Write from the graphics frame clock or the thread that processes the buffer.

Definition at line 60 of file TextureArrayBuffer.hpp.


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