pub struct Scope {
pub depth: u8,
pub operations: Vec<Instruction>,
pub locals: Vec<Variable>,
pub const_arrays: Vec<(Variable, Vec<Variable>)>,
pub layout_ref: Option<Variable>,
pub allocator: Allocator,
/* private fields */
}
Expand description
The scope is the main operation and variable container that simplify the process of reading inputs, creating local variables and adding new operations.
Notes:
This type isn’t responsible for creating shader bindings and figuring out which variable can be written to.
Fields§
§depth: u8
§operations: Vec<Instruction>
§locals: Vec<Variable>
§const_arrays: Vec<(Variable, Vec<Variable>)>
§layout_ref: Option<Variable>
§allocator: Allocator
Implementations§
Source§impl Scope
impl Scope
Sourcepub fn root() -> Self
pub fn root() -> Self
Create a scope that is at the root of a kernel definition.
A local scope can be created with the child method.
Sourcepub fn zero<I: Into<Item>>(&mut self, item: I) -> Variable
pub fn zero<I: Into<Item>>(&mut self, item: I) -> Variable
Create a variable initialized at zero.
Sourcepub fn create_with_value<E, I>(&mut self, value: E, item: I) -> Variable
pub fn create_with_value<E, I>(&mut self, value: E, item: I) -> Variable
Create a variable initialized at some value.
pub fn add_matrix(&mut self, variable: Variable)
pub fn add_slice(&mut self, slice: Variable)
Sourcepub fn create_local_mut<I: Into<Item>>(&mut self, item: I) -> Variable
pub fn create_local_mut<I: Into<Item>>(&mut self, item: I) -> Variable
Create a mutable variable of the given item type.
Sourcepub fn add_local_mut(&mut self, var: Variable)
pub fn add_local_mut(&mut self, var: Variable)
Create a mutable variable of the given item type.
Sourcepub fn create_local_restricted(&mut self, item: Item) -> Variable
pub fn create_local_restricted(&mut self, item: Item) -> Variable
Create a new restricted variable. The variable is Useful for for loops and other algorithms that require the control over initialization.
Sourcepub fn create_local(&mut self, item: Item) -> Variable
pub fn create_local(&mut self, item: Item) -> Variable
Create a new immutable variable.
Sourcepub fn read_array<I: Into<Item>>(
&mut self,
index: Id,
item: I,
position: Variable,
) -> Variable
pub fn read_array<I: Into<Item>>( &mut self, index: Id, item: I, position: Variable, ) -> Variable
Reads an input array to a local variable.
The index refers to the argument position of the array in the compute shader.
Sourcepub fn read_scalar(&mut self, index: Id, elem: Elem) -> Variable
pub fn read_scalar(&mut self, index: Id, elem: Elem) -> Variable
Reads an input scalar to a local variable.
The index refers to the scalar position for the same element type.
Sourcepub fn last_local_index(&self) -> Option<&Variable>
pub fn last_local_index(&self) -> Option<&Variable>
Retrieve the last local variable that was created.
Sourcepub fn write_global(
&mut self,
input: Variable,
output: Variable,
position: Variable,
)
pub fn write_global( &mut self, input: Variable, output: Variable, position: Variable, )
Writes a variable to given output.
Notes:
This should only be used when doing compilation.
Sourcepub fn write_global_custom(&mut self, output: Variable)
pub fn write_global_custom(&mut self, output: Variable)
Writes a variable to given output.
Notes:
This should only be used when doing compilation.
pub fn read_globals(&self) -> Vec<(Id, ReadingStrategy)>
Sourcepub fn register<T: Into<Instruction>>(&mut self, operation: T)
pub fn register<T: Into<Instruction>>(&mut self, operation: T)
Register an operation into the scope.
Sourcepub fn process(&mut self) -> ScopeProcessing
pub fn process(&mut self) -> ScopeProcessing
Returns the variables and operations to be declared and executed.
Notes:
New operations and variables can be created within the same scope without having name conflicts.
pub fn new_local_index(&self) -> u32
Create a shared variable of the given item type.
Sourcepub fn create_const_array<I: Into<Item>>(
&mut self,
item: I,
data: Vec<Variable>,
) -> Variable
pub fn create_const_array<I: Into<Item>>( &mut self, item: I, data: Vec<Variable>, ) -> Variable
Create a shared variable of the given item type.
Sourcepub fn create_local_array<I: Into<Item>>(
&mut self,
item: I,
array_size: u32,
) -> Variable
pub fn create_local_array<I: Into<Item>>( &mut self, item: I, array_size: u32, ) -> Variable
Create a local array of the given item type.