Struct Module
pub struct Module {
pub types: UniqueArena<Type>,
pub special_types: SpecialTypes,
pub constants: Arena<Constant>,
pub overrides: Arena<Override>,
pub global_variables: Arena<GlobalVariable>,
pub global_expressions: Arena<Expression>,
pub functions: Arena<Function>,
pub entry_points: Vec<EntryPoint>,
pub diagnostic_filters: Arena<DiagnosticFilterNode>,
pub diagnostic_filter_leaf: Option<Handle<DiagnosticFilterNode>>,
pub doc_comments: Option<Box<DocComments>>,
}
unstable-wgpu-26
only.Expand description
Shader module.
A module is a set of constants, global variables and functions, as well as the types required to define them.
Some functions are marked as entry points, to be used in a certain shader stage.
To create a new module, use the Default
implementation.
Alternatively, you can load an existing shader using one of the available front ends.
When finished, you can export modules using one of the available backends.
§Module arenas
Most module contents are stored in Arena
s. In a valid module, arena
elements only refer to prior arena elements. That is, whenever an element in
some Arena<T>
contains a Handle<T>
referring to another element the same
arena, the handle’s referent always precedes the element containing the
handle.
The elements of Module::types
may refer to Expression
s in
Module::global_expressions
, and those expressions may in turn refer back
to Type
s in Module::types
. In a valid module, there exists an order
in which all types and global expressions can be visited such that:
-
types and expressions are visited in the order in which they appear in their arenas, and
-
every element refers only to previously visited elements.
This implies that the graph of types and global expressions is acyclic. (However, it is a stronger condition: there are cycle-free arrangements of types and expressions for which an order like the one described above does not exist. Modules arranged in such a way are not valid.)
Fields§
§types: UniqueArena<Type>
Arena for the types defined in this module.
See the Module
docs for more details about this field.
special_types: SpecialTypes
Dictionary of special type handles.
constants: Arena<Constant>
Arena for the constants defined in this module.
overrides: Arena<Override>
Arena for the pipeline-overridable constants defined in this module.
global_variables: Arena<GlobalVariable>
Arena for the global variables defined in this module.
global_expressions: Arena<Expression>
Constant expressions and override expressions used by this module.
If an expression is in this arena, then its subexpressions are in this
arena too. In other words, every Handle<Expression>
in this arena
refers to an Expression
in this arena too.
See the Module
docs for more details about this field.
functions: Arena<Function>
Arena for the functions defined in this module.
Each function must appear in this arena strictly before all its callers. Recursion is not supported.
entry_points: Vec<EntryPoint>
Entry points.
diagnostic_filters: Arena<DiagnosticFilterNode>
Arena for all diagnostic filter rules parsed in this module, including those in functions and statements.
This arena contains elements of a tree of diagnostic filter rules. When nodes are built by a front-end, they refer to a parent scope
diagnostic_filter_leaf: Option<Handle<DiagnosticFilterNode>>
The leaf of all diagnostic filter rules tree parsed from directives in this module.
In WGSL, this corresponds to diagnostic(…);
directives.
See DiagnosticFilterNode
for details on how the tree is represented and used in
validation.
doc_comments: Option<Box<DocComments>>
Doc comments.
Implementations§
§impl Module
impl Module
pub fn generate_ray_desc_type(&mut self) -> Handle<Type>
pub fn generate_ray_desc_type(&mut self) -> Handle<Type>
Populate this module’s SpecialTypes::ray_desc
type.
SpecialTypes::ray_desc
is the type of the descriptor
operand of
an Initialize
RayQuery
statement. In WGSL, it is a struct type
referred to as RayDesc
.
Backends consume values of this type to drive platform APIs, so if you
change any its fields, you must update the backends to match. Look for
backend code dealing with RayQueryFunction::Initialize
.
pub fn generate_vertex_return_type(&mut self) -> Handle<Type>
pub fn generate_vertex_return_type(&mut self) -> Handle<Type>
Make sure the types for the vertex return are in the module’s type
pub fn generate_ray_intersection_type(&mut self) -> Handle<Type>
pub fn generate_ray_intersection_type(&mut self) -> Handle<Type>
Populate this module’s SpecialTypes::ray_intersection
type.
SpecialTypes::ray_intersection
is the type of a
RayQueryGetIntersection
expression. In WGSL, it is a struct type
referred to as RayIntersection
.
Backends construct values of this type based on platform APIs, so if you
change any its fields, you must update the backends to match. Look for
the backend’s handling for Expression::RayQueryGetIntersection
.
pub fn generate_predeclared_type(
&mut self,
special_type: PredeclaredType,
) -> Handle<Type>
pub fn generate_predeclared_type( &mut self, special_type: PredeclaredType, ) -> Handle<Type>
Populate this module’s SpecialTypes::predeclared_types
type and return the handle.
§impl Module
impl Module
pub fn get_or_insert_default_doc_comments(&mut self) -> &mut Box<DocComments>
§impl Module
impl Module
pub const fn to_ctx(&self) -> GlobalCtx<'_>
pub fn compare_types(&self, lhs: &TypeResolution, rhs: &TypeResolution) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Module
impl RefUnwindSafe for Module
impl Send for Module
impl Sync for Module
impl Unpin for Module
impl UnwindSafe for Module
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.