pub struct Writer<W> {
out: W,
flags: WriterFlags,
names: FastHashMap<NameKey, String>,
namer: Namer,
named_expressions: FastIndexMap<Handle<Expression>, String>,
ep_results: Vec<(ShaderStage, Handle<Type>)>,
required_polyfills: FastIndexSet<InversePolyfill>,
}
Fields§
§out: W
§flags: WriterFlags
§names: FastHashMap<NameKey, String>
§namer: Namer
§named_expressions: FastIndexMap<Handle<Expression>, String>
§ep_results: Vec<(ShaderStage, Handle<Type>)>
§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)
fn is_builtin_wgsl_struct(&self, module: &Module, handle: Handle<Type>) -> bool
pub fn write(&mut self, module: &Module, info: &ModuleInfo) -> Result<(), Error>
sourcefn write_struct_name(
&mut self,
module: &Module,
handle: Handle<Type>,
) -> Result<(), Error>
fn write_struct_name( &mut self, module: &Module, handle: Handle<Type>, ) -> Result<(), Error>
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>
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 theHandle
address space are immutable, andGlobalVariable
expressions for those produce the value directly, not a pointer to it. SuchGlobalVariable
expressions areOrdinary
. -
Access
andAccessIndex
areReference
when theirbase
operand 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>, ) -> 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.