vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
//! Barrier placement validation.
//!
//! Workgroup barriers in GPU shaders must only appear in uniform control
//! flow: every thread in the workgroup must reach the barrier or none
//! must reach it. This module checks that barrier nodes are not placed
//! inside divergent branches, catching a class of bugs that would
//! otherwise deadlock or produce undefined behavior on the GPU.

use crate::ir::validate::{err, ValidationError};

/// Ensure a barrier is not placed inside divergent control flow.
///
/// A barrier inside an `If` or `Loop` whose condition is not uniform
/// across the workgroup is illegal in vyre. This function appends a
/// validation error when `divergent` is `true`.
///
/// # Examples
///
/// ```
/// use vyre::ir::validate::barrier::check_barrier;
/// use vyre::ir::validate::ValidationError;
///
/// let mut errors = Vec::new();
/// check_barrier(false, &mut errors);
/// assert!(errors.is_empty());
///
/// check_barrier(true, &mut errors);
/// assert!(!errors.is_empty());
/// ```
///
/// # Errors
///
/// Appends a `ValidationError` with code `V010` when `divergent` is
/// `true`.
#[inline]
pub fn check_barrier(divergent: bool, errors: &mut Vec<ValidationError>) {
    if divergent {
        errors.push(err(
            "V010: barrier may be reached by only part of a workgroup. Fix: move the barrier to uniform control flow."
                .to_string(),
        ));
    }
}