naga::back::hlsl

Struct Writer

source
pub struct Writer<'a, W> {
    out: W,
    names: FastHashMap<NameKey, String>,
    namer: Namer,
    options: &'a Options,
    entry_point_io: Vec<EntryPointInterface>,
    named_expressions: FastIndexMap<Handle<Expression>, String>,
    wrapped: Wrapped,
    written_committed_intersection: bool,
    written_candidate_intersection: bool,
    continue_ctx: ContinueCtx,
    temp_access_chain: Vec<SubAccess>,
    need_bake_expressions: NeedBakeExpressions,
}

Fields§

§out: W§names: FastHashMap<NameKey, String>§namer: Namer§options: &'a Options

HLSL backend options

§entry_point_io: Vec<EntryPointInterface>

Information about entry point arguments and result types.

§named_expressions: FastIndexMap<Handle<Expression>, String>

Set of expressions that have associated temporary variables

§wrapped: Wrapped§written_committed_intersection: bool§written_candidate_intersection: bool§continue_ctx: ContinueCtx§temp_access_chain: Vec<SubAccess>

A reference to some part of a global variable, lowered to a series of byte offset calculations.

See the storage module for background on why we need this.

Each SubAccess in the vector is a lowering of some Access or AccessIndex expression to the level of byte strides and offsets. See SubAccess for details.

This field is a member of Writer solely to allow re-use of the Vec’s dynamic allocation. The value is no longer needed once HLSL for the access has been generated.

§need_bake_expressions: NeedBakeExpressions

Implementations§

source§

impl<W: Write> Writer<'_, W>

source

pub(super) fn write_image_type( &mut self, dim: ImageDimension, arrayed: bool, class: ImageClass, ) -> Result<(), Error>

source

pub(super) fn write_wrapped_array_length_function_name( &mut self, query: WrappedArrayLength, ) -> Result<(), Error>

source

pub(super) fn write_wrapped_array_length_function( &mut self, wal: WrappedArrayLength, ) -> Result<(), Error>

Helper function that write wrapped function for Expression::ArrayLength

https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-rwbyteaddressbuffer-getdimensions

source

pub(super) fn write_wrapped_image_query_function_name( &mut self, query: WrappedImageQuery, ) -> Result<(), Error>

source

pub(super) fn write_wrapped_image_query_function( &mut self, module: &Module, wiq: WrappedImageQuery, expr_handle: Handle<Expression>, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

Helper function that write wrapped function for Expression::ImageQuery

https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-getdimensions

source

pub(super) fn write_wrapped_constructor_function_name( &mut self, module: &Module, constructor: WrappedConstructor, ) -> Result<(), Error>

source

fn write_wrapped_constructor_function( &mut self, module: &Module, constructor: WrappedConstructor, ) -> Result<(), Error>

Helper function that write wrapped function for Expression::Compose for structures.

source

pub(super) fn write_wrapped_struct_matrix_get_function_name( &mut self, access: WrappedStructMatrixAccess, ) -> Result<(), Error>

source

pub(super) fn write_wrapped_struct_matrix_get_function( &mut self, module: &Module, access: WrappedStructMatrixAccess, ) -> Result<(), Error>

Writes a function used to get a matCx2 from within a structure.

source

pub(super) fn write_wrapped_struct_matrix_set_function_name( &mut self, access: WrappedStructMatrixAccess, ) -> Result<(), Error>

source

pub(super) fn write_wrapped_struct_matrix_set_function( &mut self, module: &Module, access: WrappedStructMatrixAccess, ) -> Result<(), Error>

Writes a function used to set a matCx2 from within a structure.

source

pub(super) fn write_wrapped_struct_matrix_set_vec_function_name( &mut self, access: WrappedStructMatrixAccess, ) -> Result<(), Error>

source

pub(super) fn write_wrapped_struct_matrix_set_vec_function( &mut self, module: &Module, access: WrappedStructMatrixAccess, ) -> Result<(), Error>

Writes a function used to set a vec2 on a matCx2 from within a structure.

source

pub(super) fn write_wrapped_struct_matrix_set_scalar_function_name( &mut self, access: WrappedStructMatrixAccess, ) -> Result<(), Error>

source

pub(super) fn write_wrapped_struct_matrix_set_scalar_function( &mut self, module: &Module, access: WrappedStructMatrixAccess, ) -> Result<(), Error>

Writes a function used to set a float on a matCx2 from within a structure.

source

pub(super) fn write_special_functions( &mut self, module: &Module, ) -> Result<(), Error>

Write functions to create special types.

source

pub(super) fn write_wrapped_compose_functions( &mut self, module: &Module, expressions: &Arena<Expression>, ) -> Result<(), Error>

Helper function that writes compose wrapped functions

source

pub(super) fn write_wrapped_zero_value_functions( &mut self, module: &Module, expressions: &Arena<Expression>, ) -> Result<(), Error>

Helper function that writes zero value wrapped functions

source

pub(super) fn write_wrapped_math_functions( &mut self, module: &Module, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

source

pub(super) fn write_wrapped_functions( &mut self, module: &Module, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

Helper function that writes various wrapped functions

source

pub(super) fn write_sampler_heaps(&mut self) -> Result<(), Error>

Writes out the sampler heap declarations if they haven’t been written yet.

source

pub(super) fn write_wrapped_sampler_buffer( &mut self, key: SamplerIndexBufferKey, ) -> Result<(), Error>

Writes out the sampler index buffer declaration if it hasn’t been written yet.

source

pub(super) fn write_texture_coordinates( &mut self, kind: &str, coordinate: Handle<Expression>, array_index: Option<Handle<Expression>>, mip_level: Option<Handle<Expression>>, module: &Module, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

source

pub(super) fn write_mat_cx2_typedef_and_functions( &mut self, _: WrappedMatCx2, ) -> Result<(), Error>

source

pub(super) fn write_all_mat_cx2_typedefs_and_functions( &mut self, module: &Module, ) -> Result<(), Error>

source

pub(super) fn write_wrapped_zero_value_function_name( &mut self, module: &Module, zero_value: WrappedZeroValue, ) -> Result<(), Error>

source

fn write_wrapped_zero_value_function( &mut self, module: &Module, zero_value: WrappedZeroValue, ) -> Result<(), Error>

Helper function that write wrapped function for Expression::ZeroValue

This is necessary since we might have a member access after the zero value expression, e.g. .y (in practice this can come up when consuming SPIRV that’s been produced by glslc).

So we can’t just write (float4)0 since (float4)0.y won’t parse correctly.

Parenthesizing the expression like ((float4)0).y would work… except DXC can’t handle cases like:

tests\out\hlsl\access.hlsl:183:41: error: cannot compile this l-value expression yet
    t_1.am = (__mat4x2[2])((float4x2[2])0);
                                        ^
source§

impl<W: Write> Writer<'_, W>

source

pub(super) fn write_ray_desc_from_ray_desc_constructor_function( &mut self, module: &Module, ) -> Result<(), Error>

source

pub(super) fn write_committed_intersection_function( &mut self, module: &Module, ) -> Result<(), Error>

source

pub(super) fn write_candidate_intersection_function( &mut self, module: &Module, ) -> Result<(), Error>

source§

impl<W: Write> Writer<'_, W>

source

pub(super) fn write_storage_address( &mut self, module: &Module, chain: &[SubAccess], func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

source

fn write_storage_load_sequence<I: Iterator<Item = (TypeResolution, u32)>>( &mut self, module: &Module, var_handle: Handle<GlobalVariable>, sequence: I, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

source

pub(super) fn write_storage_load( &mut self, module: &Module, var_handle: Handle<GlobalVariable>, result_ty: TypeResolution, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

Emit code to access a Storage global’s component.

Emit HLSL to access the component of var_handle, a global variable in the Storage address space, whose type is result_ty and whose location within the global is given by self.temp_access_chain. See the storage module’s documentation for background.

source

fn write_store_value( &mut self, module: &Module, value: &StoreValue, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

source

pub(super) fn write_storage_store( &mut self, module: &Module, var_handle: Handle<GlobalVariable>, value: StoreValue, func_ctx: &FunctionCtx<'_>, level: Level, ) -> Result<(), Error>

Helper function to write down the Store operation on a ByteAddressBuffer.

source

pub(super) fn fill_access_chain( &mut self, module: &Module, cur_expr: Handle<Expression>, func_ctx: &FunctionCtx<'_>, ) -> Result<Handle<GlobalVariable>, Error>

Set temp_access_chain to compute the byte offset of cur_expr.

The cur_expr expression must be a reference to a global variable in the Storage address space, or a chain of Access and AccessIndex expressions referring to some component of such a global.

source§

impl<'a, W: Write> Writer<'a, W>

source

pub fn new(out: W, options: &'a Options) -> Self

source

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

source

fn update_expressions_to_bake( &mut self, module: &Module, func: &Function, info: &FunctionInfo, )

Helper method used to find which expressions of a given function require baking

§Notes

Clears need_bake_expressions set before adding to it

source

pub fn write( &mut self, module: &Module, module_info: &ModuleInfo, fragment_entry_point: Option<&FragmentEntryPoint<'_>>, ) -> Result<ReflectionInfo, Error>

source

fn write_modifier(&mut self, binding: &Binding) -> Result<(), Error>

source

fn write_semantic( &mut self, binding: &Option<Binding>, stage: Option<(ShaderStage, Io)>, ) -> Result<(), Error>

source

fn write_interface_struct( &mut self, module: &Module, shader_stage: (ShaderStage, Io), struct_name: String, members: Vec<EpStructMember>, ) -> Result<EntryPointBinding, Error>

source

fn write_ep_input_struct( &mut self, module: &Module, func: &Function, stage: ShaderStage, entry_point_name: &str, ) -> Result<EntryPointBinding, Error>

Flatten all entry point arguments into a single struct. This is needed since we need to re-order them: first placing user locations, then built-ins.

source

fn write_ep_output_struct( &mut self, module: &Module, result: &FunctionResult, stage: ShaderStage, entry_point_name: &str, frag_ep: Option<&FragmentEntryPoint<'_>>, ) -> Result<EntryPointBinding, Error>

Flatten all entry point results into a single struct. This is needed since we need to re-order them: first placing user locations, then built-ins.

source

fn write_ep_interface( &mut self, module: &Module, func: &Function, stage: ShaderStage, ep_name: &str, frag_ep: Option<&FragmentEntryPoint<'_>>, ) -> Result<EntryPointInterface, Error>

Writes special interface structures for an entry point. The special structures have all the fields flattened into them and sorted by binding. They are needed to emulate subgroup built-ins and to make the interfaces between VS outputs and FS inputs match.

source

fn write_ep_argument_initialization( &mut self, ep: &EntryPoint, ep_input: &EntryPointBinding, fake_member: &EpStructMember, ) -> Result<(), Error>

source

fn write_ep_arguments_initialization( &mut self, module: &Module, func: &Function, ep_index: u16, ) -> Result<(), Error>

Write an entry point preface that initializes the arguments as specified in IR.

source

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

Helper method used to write global variables

§Notes

Always adds a newline

source

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

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(super) fn write_array_size( &mut self, module: &Module, base: Handle<Type>, size: ArraySize, ) -> Result<(), Error>

source

fn write_struct( &mut self, module: &Module, handle: Handle<Type>, members: &[StructMember], span: u32, shader_stage: Option<(ShaderStage, Io)>, ) -> Result<(), Error>

Helper method used to write structs

§Notes

Ends in a newline

source

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

Helper method used to write global/structs non image/sampler types

§Notes

Adds no trailing or leading whitespace

source

pub(super) 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

pub(super) 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_function( &mut self, module: &Module, name: &str, func: &Function, func_ctx: &FunctionCtx<'_>, info: &FunctionInfo, ) -> Result<(), Error>

Helper method used to write functions

§Notes

Ends in a newline

source

fn need_workgroup_variables_initialization( &mut self, func_ctx: &FunctionCtx<'_>, module: &Module, ) -> bool

source

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

source

fn write_switch( &mut self, module: &Module, func_ctx: &FunctionCtx<'_>, level: Level, selector: Handle<Expression>, cases: &[SwitchCase], ) -> Result<(), Error>

Helper method used to write switches

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

pub(super) fn write_expr( &mut self, module: &Module, expr: Handle<Expression>, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

Helper method to write expressions

§Notes

Doesn’t add any newlines or leading/trailing spaces

source

fn sampler_binding_array_info_from_expression( &mut self, module: &Module, func_ctx: &FunctionCtx<'_>, base: Handle<Expression>, resolved: &TypeInner, ) -> Option<BindingArraySamplerInfo>

Find the BindingArraySamplerInfo from an expression so that such an access can be generated later.

source

fn write_named_expr( &mut self, module: &Module, handle: Handle<Expression>, name: String, named: Handle<Expression>, ctx: &FunctionCtx<'_>, ) -> Result<(), Error>

source

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

Helper function that write default zero initialization

source

fn write_barrier(&mut self, barrier: Barrier, level: Level) -> Result<(), Error>

Auto Trait Implementations§

§

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

§

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

§

impl<'a, W> !Send for Writer<'a, W>

§

impl<'a, W> !Sync for Writer<'a, W>

§

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

§

impl<'a, W> UnwindSafe for Writer<'a, 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.