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

◆ are_tokens_compatible()

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

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 9 of file BufferUtils.cpp.

10{
11 bool preferred_sample = preferred & SAMPLE_RATE;
12 bool preferred_frame = preferred & FRAME_RATE;
13 bool current_sample = current & SAMPLE_RATE;
14 bool current_frame = current & FRAME_RATE;
15
16 // If preferred is FRAME_RATE, only FRAME_RATE is compatible
17 if (preferred_frame && !current_frame)
18 return false;
19 // If preferred is SAMPLE_RATE, FRAME_RATE can be compatible (sample can "delay" to frame)
20 if (preferred_sample && current_frame)
21 return true;
22 // If both are SAMPLE_RATE or both are FRAME_RATE, compatible
23 if ((preferred_sample && current_sample) || (preferred_frame && current_frame))
24 return true;
25
26 // Device compatibility: SAMPLE_RATE can't run on GPU, but FRAME_RATE can run on CPU
27 bool preferred_cpu = preferred & CPU_PROCESS;
28 bool preferred_gpu = preferred & GPU_PPOCESS;
29 bool current_cpu = current & CPU_PROCESS;
30 bool current_gpu = current & GPU_PPOCESS;
31
32 if (preferred_sample && current_gpu)
33 return false; // Can't run sample rate on GPU
34 if (preferred_gpu && current_cpu)
35 return false; // If preferred is GPU, but current is CPU, not compatible
36 // If preferred is CPU, but current is GPU, allow only for FRAME_RATE
37 if (preferred_cpu && current_gpu && !current_frame)
38 return false;
39
40 // Sequential/Parallel compatibility: allow if rates align
41 bool preferred_seq = preferred & SEQUENTIAL;
42 bool preferred_par = preferred & PARALLEL;
43 bool current_seq = current & SEQUENTIAL;
44 bool current_par = current & PARALLEL;
45
46 if ((preferred_seq && current_par) || (preferred_par && current_seq)) {
47 // Allow if rates align (already checked above)
48 if ((preferred_sample && current_sample) || (preferred_frame && current_frame)) {
49 return true;
50 }
51 // If preferred is SAMPLE_RATE and current is FRAME_RATE, already handled above
52 // Otherwise, not compatible
53 return false;
54 }
55
56 // If all checks pass, compatible
57 return true;
58}
@ 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: