pub struct Writer<W> {
out: W,
flags: WriterFlags,
names: FastHashMap<NameKey, String>,
namer: Namer,
named_expressions: FastIndexMap<Handle<Expression>, String>,
required_polyfills: FastIndexSet<InversePolyfill>,
}Fields§
§out: W§flags: WriterFlags§names: FastHashMap<NameKey, String>§namer: Namer§named_expressions: FastIndexMap<Handle<Expression>, String>§required_polyfills: FastIndexSet<InversePolyfill>Implementations§
Source§impl<W: Write> Writer<W>
impl<W: Write> Writer<W>
pub fn new(out: W, flags: WriterFlags) -> Self
fn reset(&mut self, module: &Module)
Sourcefn is_builtin_wgsl_struct(&self, module: &Module, ty: Handle<Type>) -> bool
fn is_builtin_wgsl_struct(&self, module: &Module, ty: Handle<Type>) -> bool
Determine if ty is the Naga IR presentation of a WGSL builtin type.
Return true if ty refers to the Naga IR form of a WGSL builtin type
like __atomic_compare_exchange_result.
Even though the module may use the type, the WGSL backend should avoid emitting a definition for it, since it is predeclared in WGSL.
This also covers types like NagaExternalTextureParams, which other
backends use to lower WGSL constructs like external textures to their
implementations. WGSL can express these directly, so the types need not
be emitted.
pub fn write(&mut self, module: &Module, info: &ModuleInfo) -> Result<(), Error>
Sourcefn write_enable_declarations(&mut self, module: &Module) -> Result<(), Error>
fn write_enable_declarations(&mut self, module: &Module) -> Result<(), Error>
Helper method which writes all the enable declarations
needed for a module.
Sourcefn write_function(
&mut self,
module: &Module,
func: &Function,
func_ctx: &FunctionCtx<'_>,
) -> Result<(), Error>
fn write_function( &mut self, module: &Module, func: &Function, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>
Sourcefn write_attributes(&mut self, attributes: &[Attribute]) -> Result<(), Error>
fn write_attributes(&mut self, attributes: &[Attribute]) -> Result<(), Error>
Helper method to write a attribute
Sourcefn write_struct(
&mut self,
module: &Module,
handle: Handle<Type>,
members: &[StructMember],
) -> Result<(), Error>
fn write_struct( &mut self, module: &Module, handle: Handle<Type>, members: &[StructMember], ) -> Result<(), Error>
Helper method used to write structs Write the full declaration of a struct type.
Write out a definition of the struct type referred to by
handle in module. The output will be an instance of the
struct_decl production in the WGSL grammar.
Use members as the list of handle’s members. (This
function is usually called after matching a TypeInner, so
the callers already have the members at hand.)
fn write_type(&mut self, module: &Module, ty: Handle<Type>) -> Result<(), Error>
fn write_type_resolution( &mut self, module: &Module, resolution: &TypeResolution, ) -> Result<(), Error>
Sourcefn write_stmt(
&mut self,
module: &Module,
stmt: &Statement,
func_ctx: &FunctionCtx<'_>,
level: Level,
) -> Result<(), Error>
fn write_stmt( &mut self, module: &Module, stmt: &Statement, func_ctx: &FunctionCtx<'_>, level: Level, ) -> Result<(), Error>
Sourcefn plain_form_indirection(
&self,
expr: Handle<Expression>,
module: &Module,
func_ctx: &FunctionCtx<'_>,
) -> Indirection
fn plain_form_indirection( &self, expr: Handle<Expression>, module: &Module, func_ctx: &FunctionCtx<'_>, ) -> Indirection
Return the sort of indirection that expr’s plain form evaluates to.
An expression’s ‘plain form’ is the most general rendition of that
expression into WGSL, lacking & or * operators:
-
The plain form of
LocalVariable(x)is simplyx, which is a reference to the local variable’s storage. -
The plain form of
GlobalVariable(g)is simplyg, which is usually a reference to the global variable’s storage. However, globals in theHandleaddress space are immutable, andGlobalVariableexpressions for those produce the value directly, not a pointer to it. SuchGlobalVariableexpressions areOrdinary. -
AccessandAccessIndexareReferencewhen theirbaseoperand is a pointer. If they are applied directly to a composite value, they areOrdinary.
Note that FunctionArgument expressions are never Reference, even when
the argument’s type is Pointer. FunctionArgument always evaluates to the
argument’s value directly, so any pointer it produces is merely the value
passed by the caller.
fn start_named_expr( &mut self, module: &Module, handle: Handle<Expression>, func_ctx: &FunctionCtx<'_>, name: &str, ) -> Result<(), Error>
Sourcefn write_expr(
&mut self,
module: &Module,
expr: Handle<Expression>,
func_ctx: &FunctionCtx<'_>,
) -> Result<(), Error>
fn write_expr( &mut self, module: &Module, expr: Handle<Expression>, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>
Write the ordinary WGSL form of expr.
See write_expr_with_indirection for details.
Sourcefn write_expr_with_indirection(
&mut self,
module: &Module,
expr: Handle<Expression>,
func_ctx: &FunctionCtx<'_>,
requested: Indirection,
) -> Result<(), Error>
fn write_expr_with_indirection( &mut self, module: &Module, expr: Handle<Expression>, func_ctx: &FunctionCtx<'_>, requested: Indirection, ) -> Result<(), Error>
Write expr as a WGSL expression with the requested indirection.
In terms of the WGSL grammar, the resulting expression is a
singular_expression. It may be parenthesized. This makes it suitable
for use as the operand of a unary or binary operator without worrying
about precedence.
This does not produce newlines or indentation.
The requested argument indicates (roughly) whether Naga
Pointer-valued expressions represent WGSL references or pointers. See
Indirection for details.
fn write_const_expression( &mut self, module: &Module, expr: Handle<Expression>, arena: &Arena<Expression>, ) -> Result<(), Error>
fn write_possibly_const_expression<E>( &mut self, module: &Module, expr: Handle<Expression>, expressions: &Arena<Expression>, write_expression: E, ) -> Result<(), Error>
Sourcefn write_expr_plain_form(
&mut self,
module: &Module,
expr: Handle<Expression>,
func_ctx: &FunctionCtx<'_>,
indirection: Indirection,
) -> Result<(), Error>
fn write_expr_plain_form( &mut self, module: &Module, expr: Handle<Expression>, func_ctx: &FunctionCtx<'_>, indirection: Indirection, ) -> Result<(), Error>
Write the ‘plain form’ of expr.
An expression’s ‘plain form’ is the most general rendition of that
expression into WGSL, lacking & or * operators. The plain forms of
LocalVariable(x) and GlobalVariable(g) are simply x and g. Such
Naga expressions represent both WGSL pointers and references; it’s the
caller’s responsibility to distinguish those cases appropriately.