use crate::ir::model::program::BufferDecl;
use crate::ir::model::types::{BufferAccess, DataType};
use crate::ir::validate::{err, ValidationError};
use rustc_hash::FxHashMap;
#[inline]
pub fn check_store(
buffer: &str,
buffers: &FxHashMap<&str, &BufferDecl>,
errors: &mut Vec<ValidationError>,
) {
if let Some(buf) = buffers.get(buffer) {
if buf.access != BufferAccess::ReadWrite && buf.access != BufferAccess::Workgroup {
errors.push(err(format!(
"store to non-writable buffer `{buffer}`. Fix: declare it with BufferAccess::ReadWrite or BufferAccess::Workgroup."
)));
}
if buf.element == DataType::Bytes {
errors.push(err(format!(
"V013: store to buffer `{buffer}` with element type `bytes` is not supported. Fix: use a typed buffer (U32/I32/F32/…) for stores; Bytes buffers are read-only opaque blobs."
)));
}
} else {
errors.push(err(format!(
"store to unknown buffer `{buffer}`. Fix: declare it in Program::buffers."
)));
}
}
#[inline]
pub fn check_load(
buffer: &str,
buffers: &FxHashMap<&str, &BufferDecl>,
errors: &mut Vec<ValidationError>,
) {
match buffers.get(buffer) {
None => {
errors.push(err(format!(
"load from unknown buffer `{buffer}`. Fix: declare it in Program::buffers."
)));
}
Some(buf) if buf.element == DataType::Bytes => {
errors.push(err(format!(
"V013: load from buffer `{buffer}` with element type `bytes` is not supported. Fix: declare the buffer with a typed element (U32/I32/F32/…) or use a dedicated bytes-extraction op."
)));
}
Some(_) => {}
}
}