naga::back::wgsl::writer

Struct Writer

Source
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>

Source

pub fn new(out: W, flags: WriterFlags) -> Self

Source

fn reset(&mut self, module: &Module)

Source

fn is_builtin_wgsl_struct(&self, module: &Module, handle: Handle<Type>) -> bool

Source

pub fn write(&mut self, module: &Module, info: &ModuleInfo) -> Result<(), Error>

Source

fn write_enable_declarations(&mut self, module: &Module) -> Result<(), Error>

Helper method which writes all the enable declarations needed for a module.

Source

fn write_function( &mut self, module: &Module, func: &Function, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

Helper method used to write functions

§Notes

Ends in a newline

Source

fn write_attributes(&mut self, attributes: &[Attribute]) -> Result<(), Error>

Helper method to write a attribute

Source

fn write_enable_dual_source_blending_if_needed( &mut self, module: &Module, ) -> Result<(), Error>

Writes all the necessary directives out

Source

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.)

Source

fn write_type(&mut self, module: &Module, ty: Handle<Type>) -> Result<(), Error>

Source

fn write_type_resolution( &mut self, module: &Module, resolution: &TypeResolution, ) -> Result<(), Error>

Source

fn write_stmt( &mut self, module: &Module, stmt: &Statement, func_ctx: &FunctionCtx<'_>, level: Level, ) -> Result<(), Error>

Helper method used to write statements

§Notes

Always adds a newline

Source

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 simply x, which is a reference to the local variable’s storage.

  • The plain form of GlobalVariable(g) is simply g, which is usually a reference to the global variable’s storage. However, globals in the Handle address space are immutable, and GlobalVariable expressions for those produce the value directly, not a pointer to it. Such GlobalVariable expressions are Ordinary.

  • Access and AccessIndex are Reference when their base operand is a pointer. If they are applied directly to a composite value, they are Ordinary.

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.

Source

fn start_named_expr( &mut self, module: &Module, handle: Handle<Expression>, func_ctx: &FunctionCtx<'_>, name: &str, ) -> Result<(), Error>

Source

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.

Source

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.

Source

fn write_const_expression( &mut self, module: &Module, expr: Handle<Expression>, arena: &Arena<Expression>, ) -> Result<(), Error>

Source

fn write_possibly_const_expression<E>( &mut self, module: &Module, expr: Handle<Expression>, expressions: &Arena<Expression>, write_expression: E, ) -> Result<(), Error>
where E: Fn(&mut Self, Handle<Expression>) -> Result<(), Error>,

Source

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.

Source

fn write_global( &mut self, module: &Module, global: &GlobalVariable, handle: Handle<GlobalVariable>, ) -> Result<(), Error>

Helper method used to write global variables

§Notes

Always adds a newline

Source

fn write_global_constant( &mut self, module: &Module, handle: Handle<Constant>, ) -> Result<(), Error>

Helper method used to write global constants

§Notes

Ends in a newline

Source

pub fn finish(self) -> W

Auto Trait Implementations§

§

impl<W> Freeze for Writer<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Writer<W>
where W: RefUnwindSafe,

§

impl<W> Send for Writer<W>
where W: Send,

§

impl<W> Sync for Writer<W>
where W: Sync,

§

impl<W> Unpin for Writer<W>
where W: Unpin,

§

impl<W> UnwindSafe for Writer<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.