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

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_struct_name( &mut self, module: &Module, handle: Handle<Type>, ) -> Result<(), Error>

Helper method used to write struct name

§Notes

Adds no trailing or leading whitespace

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_struct( &mut self, module: &Module, handle: Handle<Type>, members: &[StructMember], ) -> Result<(), Error>

Helper method used to write structs

§Notes

Ends in a newline

source

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

Helper method used to write non image/sampler types

§Notes

Adds no trailing or leading whitespace

source

fn write_value_type( &mut self, module: &Module, inner: &TypeInner, ) -> Result<(), Error>

Helper method used to write value types

§Notes

Adds no trailing or leading whitespace

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