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

◆ are_tokens_compatible()

bool MayaFlux::Buffers::are_tokens_compatible ( ProcessingToken  preferred,
ProcessingToken  current 
)
inline

Determines if two processing tokens are compatible for joint execution.

Parameters
preferredThe preferred processing token configuration
currentThe current processing token configuration being evaluated
Returns
true if the tokens are compatible, false otherwise

This function implements sophisticated compatibility logic that goes beyond simple equality checking to determine if processors with different token requirements can work together in the same processing pipeline. The compatibility rules are designed to maximize processing flexibility while maintaining system stability and performance.

Rate Compatibility Rules:

  • FRAME_RATE processors require FRAME_RATE execution contexts (strict requirement)
  • SAMPLE_RATE processors can adapt to FRAME_RATE contexts (flexible upward compatibility)
  • Same-rate combinations are always compatible

Device Compatibility Rules:

  • SAMPLE_RATE processing cannot execute on GPU hardware (hardware limitation)
  • GPU-preferred processors cannot fall back to CPU execution (performance requirement)
  • CPU-preferred processors can use GPU for FRAME_RATE processing only

Concurrency Compatibility Rules:

  • Sequential/Parallel differences are acceptable if rate requirements align
  • Mismatched concurrency with incompatible rates is rejected
  • Same concurrency patterns are always compatible

This flexibility enables the system to optimize processing chains by allowing compatible processors to share execution contexts while preventing configurations that would result in poor performance or execution failures.

Definition at line 139 of file BufferUtils.hpp.

140{
141 bool preferred_sample = preferred & SAMPLE_RATE;
142 bool preferred_frame = preferred & FRAME_RATE;
143 bool current_sample = current & SAMPLE_RATE;
144 bool current_frame = current & FRAME_RATE;
145
146 // If preferred is FRAME_RATE, only FRAME_RATE is compatible
147 if (preferred_frame && !current_frame)
148 return false;
149 // If preferred is SAMPLE_RATE, FRAME_RATE can be compatible (sample can "delay" to frame)
150 if (preferred_sample && current_frame)
151 return true;
152 // If both are SAMPLE_RATE or both are FRAME_RATE, compatible
153 if ((preferred_sample && current_sample) || (preferred_frame && current_frame))
154 return true;
155
156 // Device compatibility: SAMPLE_RATE can't run on GPU, but FRAME_RATE can run on CPU
157 bool preferred_cpu = preferred & CPU_PROCESS;
158 bool preferred_gpu = preferred & GPU_PPOCESS;
159 bool current_cpu = current & CPU_PROCESS;
160 bool current_gpu = current & GPU_PPOCESS;
161
162 if (preferred_sample && current_gpu)
163 return false; // Can't run sample rate on GPU
164 if (preferred_gpu && current_cpu)
165 return false; // If preferred is GPU, but current is CPU, not compatible
166 // If preferred is CPU, but current is GPU, allow only for FRAME_RATE
167 if (preferred_cpu && current_gpu && !current_frame)
168 return false;
169
170 // Sequential/Parallel compatibility: allow if rates align
171 bool preferred_seq = preferred & SEQUENTIAL;
172 bool preferred_par = preferred & PARALLEL;
173 bool current_seq = current & SEQUENTIAL;
174 bool current_par = current & PARALLEL;
175
176 if ((preferred_seq && current_par) || (preferred_par && current_seq)) {
177 // Allow if rates align (already checked above)
178 if ((preferred_sample && current_sample) || (preferred_frame && current_frame))
179 return true;
180 // If preferred is SAMPLE_RATE and current is FRAME_RATE, already handled above
181 // Otherwise, not compatible
182 return false;
183 }
184
185 // If all checks pass, compatible
186 return true;
187}
@ SAMPLE_RATE
Processes data at audio sample rate with buffer-sized chunks.
@ CPU_PROCESS
Executes processing operations on CPU threads.
@ PARALLEL
Processes operations in parallel when possible.
@ SEQUENTIAL
Processes operations sequentially, one after another.
@ FRAME_RATE
Processes data at video frame rate.
@ GPU_PPOCESS
Executes processing operations on GPU hardware.

References CPU_PROCESS, FRAME_RATE, GPU_PPOCESS, PARALLEL, SAMPLE_RATE, and SEQUENTIAL.

Referenced by MayaFlux::Buffers::BufferProcessingChain::add_processor_direct(), MayaFlux::Buffers::BufferProcessingChain::analyze_token_compatibility(), MayaFlux::Buffers::BufferProcessingChain::enforce_chain_token_on_processors(), MayaFlux::Buffers::RootBuffer< BufferType >::is_buffer_acceptable(), MayaFlux::Buffers::ChannelProcessor::on_attach(), MayaFlux::Buffers::FinalLimiterProcessor::on_attach(), MayaFlux::Buffers::GraphicsBatchProcessor::on_attach(), MayaFlux::Buffers::PresentProcessor::on_attach(), MayaFlux::Buffers::BufferProcessingChain::optimize_for_tokens(), MayaFlux::Buffers::BufferProcessingChain::process(), MayaFlux::Buffers::BufferProcessingChain::process_non_owning(), and MayaFlux::Buffers::BufferProcessingChain::validate_all_processors().

+ Here is the caller graph for this function: