use bevy_gpu_compute_core::{
TypeErasedArrayInputData, TypeErasedArrayOutputData, TypeErasedConfigInputData,
};
use super::input_lengths::InputArrayDataLengths;
#[derive(Default)]
pub struct TaskData {
config_input: Option<TypeErasedConfigInputData>,
input: Option<TypeErasedArrayInputData>,
output: Option<TypeErasedArrayOutputData>,
input_lengths: Option<InputArrayDataLengths>,
}
impl TaskData {
pub fn new() -> Self {
TaskData::default()
}
pub fn config_input(&self) -> &Option<TypeErasedConfigInputData> {
&self.config_input
}
pub fn input(&self) -> &Option<TypeErasedArrayInputData> {
&self.input
}
pub fn output(&self) -> &Option<TypeErasedArrayOutputData> {
&self.output
}
pub fn output_mut(&mut self) -> &mut Option<TypeErasedArrayOutputData> {
&mut self.output
}
pub fn input_lengths(&self) -> &Option<InputArrayDataLengths> {
&self.input_lengths
}
pub fn set_config_input(&mut self, config_input: TypeErasedConfigInputData) {
self.config_input = Some(config_input);
}
pub fn set_output(&mut self, output: TypeErasedArrayOutputData) {
self.output = Some(output);
}
pub fn clear_output(&mut self) {
self.output = None;
}
pub fn set_input_and_check_lengths_changed(&mut self, input: TypeErasedArrayInputData) -> bool {
let mut lengths_changed = false;
let lengths = InputArrayDataLengths::new(input.get_lengths().clone());
if self.input_lengths.is_none() {
self.input_lengths = Some(lengths);
lengths_changed = true;
} else {
let new_hash = self
.input_lengths
.as_mut()
.unwrap()
.update_and_return_new_hash_if_changed(lengths);
if new_hash.is_some() {
lengths_changed = true;
}
}
self.input = Some(input);
lengths_changed
}
}