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>
impl<W: Write> Writer<'_, W>
pub(super) fn write_image_type( &mut self, dim: ImageDimension, arrayed: bool, class: ImageClass, ) -> Result<(), Error>
pub(super) fn write_wrapped_array_length_function_name( &mut self, query: WrappedArrayLength, ) -> Result<(), Error>
sourcepub(super) fn write_wrapped_array_length_function(
&mut self,
wal: WrappedArrayLength,
) -> Result<(), Error>
pub(super) fn write_wrapped_array_length_function( &mut self, wal: WrappedArrayLength, ) -> Result<(), Error>
Helper function that write wrapped function for Expression::ArrayLength
pub(super) fn write_wrapped_image_query_function_name( &mut self, query: WrappedImageQuery, ) -> Result<(), Error>
sourcepub(super) fn write_wrapped_image_query_function(
&mut self,
module: &Module,
wiq: WrappedImageQuery,
expr_handle: Handle<Expression>,
func_ctx: &FunctionCtx<'_>,
) -> Result<(), Error>
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
pub(super) fn write_wrapped_constructor_function_name( &mut self, module: &Module, constructor: WrappedConstructor, ) -> Result<(), Error>
sourcefn write_wrapped_constructor_function(
&mut self,
module: &Module,
constructor: WrappedConstructor,
) -> Result<(), Error>
fn write_wrapped_constructor_function( &mut self, module: &Module, constructor: WrappedConstructor, ) -> Result<(), Error>
Helper function that write wrapped function for Expression::Compose
for structures.
pub(super) fn write_wrapped_struct_matrix_get_function_name( &mut self, access: WrappedStructMatrixAccess, ) -> Result<(), Error>
sourcepub(super) fn write_wrapped_struct_matrix_get_function(
&mut self,
module: &Module,
access: WrappedStructMatrixAccess,
) -> Result<(), Error>
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.
pub(super) fn write_wrapped_struct_matrix_set_function_name( &mut self, access: WrappedStructMatrixAccess, ) -> Result<(), Error>
sourcepub(super) fn write_wrapped_struct_matrix_set_function(
&mut self,
module: &Module,
access: WrappedStructMatrixAccess,
) -> Result<(), Error>
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.
pub(super) fn write_wrapped_struct_matrix_set_vec_function_name( &mut self, access: WrappedStructMatrixAccess, ) -> Result<(), Error>
sourcepub(super) fn write_wrapped_struct_matrix_set_vec_function(
&mut self,
module: &Module,
access: WrappedStructMatrixAccess,
) -> Result<(), Error>
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.
pub(super) fn write_wrapped_struct_matrix_set_scalar_function_name( &mut self, access: WrappedStructMatrixAccess, ) -> Result<(), Error>
sourcepub(super) fn write_wrapped_struct_matrix_set_scalar_function(
&mut self,
module: &Module,
access: WrappedStructMatrixAccess,
) -> Result<(), Error>
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.
sourcepub(super) fn write_special_functions(
&mut self,
module: &Module,
) -> Result<(), Error>
pub(super) fn write_special_functions( &mut self, module: &Module, ) -> Result<(), Error>
Write functions to create special types.
sourcepub(super) fn write_wrapped_compose_functions(
&mut self,
module: &Module,
expressions: &Arena<Expression>,
) -> Result<(), Error>
pub(super) fn write_wrapped_compose_functions( &mut self, module: &Module, expressions: &Arena<Expression>, ) -> Result<(), Error>
Helper function that writes compose wrapped functions
sourcepub(super) fn write_wrapped_zero_value_functions(
&mut self,
module: &Module,
expressions: &Arena<Expression>,
) -> Result<(), Error>
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
pub(super) fn write_wrapped_math_functions( &mut self, module: &Module, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>
sourcepub(super) fn write_wrapped_functions(
&mut self,
module: &Module,
func_ctx: &FunctionCtx<'_>,
) -> Result<(), Error>
pub(super) fn write_wrapped_functions( &mut self, module: &Module, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>
Helper function that writes various wrapped functions
sourcepub(super) fn write_sampler_heaps(&mut self) -> Result<(), Error>
pub(super) fn write_sampler_heaps(&mut self) -> Result<(), Error>
Writes out the sampler heap declarations if they haven’t been written yet.
sourcepub(super) fn write_wrapped_sampler_buffer(
&mut self,
key: SamplerIndexBufferKey,
) -> Result<(), Error>
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.
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>
pub(super) fn write_mat_cx2_typedef_and_functions( &mut self, _: WrappedMatCx2, ) -> Result<(), Error>
pub(super) fn write_all_mat_cx2_typedefs_and_functions( &mut self, module: &Module, ) -> Result<(), Error>
pub(super) fn write_wrapped_zero_value_function_name( &mut self, module: &Module, zero_value: WrappedZeroValue, ) -> Result<(), Error>
sourcefn write_wrapped_zero_value_function(
&mut self,
module: &Module,
zero_value: WrappedZeroValue,
) -> Result<(), Error>
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>
impl<W: Write> Writer<'_, W>
pub(super) fn write_ray_desc_from_ray_desc_constructor_function( &mut self, module: &Module, ) -> Result<(), Error>
pub(super) fn write_committed_intersection_function( &mut self, module: &Module, ) -> Result<(), Error>
pub(super) fn write_candidate_intersection_function( &mut self, module: &Module, ) -> Result<(), Error>
source§impl<W: Write> Writer<'_, W>
impl<W: Write> Writer<'_, W>
pub(super) fn write_storage_address( &mut self, module: &Module, chain: &[SubAccess], func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>
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>
sourcepub(super) fn write_storage_load(
&mut self,
module: &Module,
var_handle: Handle<GlobalVariable>,
result_ty: TypeResolution,
func_ctx: &FunctionCtx<'_>,
) -> Result<(), Error>
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.
fn write_store_value( &mut self, module: &Module, value: &StoreValue, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>
sourcepub(super) fn write_storage_store(
&mut self,
module: &Module,
var_handle: Handle<GlobalVariable>,
value: StoreValue,
func_ctx: &FunctionCtx<'_>,
level: Level,
) -> Result<(), Error>
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
.
sourcepub(super) fn fill_access_chain(
&mut self,
module: &Module,
cur_expr: Handle<Expression>,
func_ctx: &FunctionCtx<'_>,
) -> Result<Handle<GlobalVariable>, Error>
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>
impl<'a, W: Write> Writer<'a, W>
pub fn new(out: W, options: &'a Options) -> Self
fn reset(&mut self, module: &Module)
sourcefn update_expressions_to_bake(
&mut self,
module: &Module,
func: &Function,
info: &FunctionInfo,
)
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
pub fn write( &mut self, module: &Module, module_info: &ModuleInfo, fragment_entry_point: Option<&FragmentEntryPoint<'_>>, ) -> Result<ReflectionInfo, Error>
fn write_modifier(&mut self, binding: &Binding) -> Result<(), Error>
fn write_semantic( &mut self, binding: &Option<Binding>, stage: Option<(ShaderStage, Io)>, ) -> Result<(), Error>
fn write_interface_struct( &mut self, module: &Module, shader_stage: (ShaderStage, Io), struct_name: String, members: Vec<EpStructMember>, ) -> Result<EntryPointBinding, Error>
sourcefn write_ep_input_struct(
&mut self,
module: &Module,
func: &Function,
stage: ShaderStage,
entry_point_name: &str,
) -> Result<EntryPointBinding, Error>
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.
sourcefn write_ep_output_struct(
&mut self,
module: &Module,
result: &FunctionResult,
stage: ShaderStage,
entry_point_name: &str,
frag_ep: Option<&FragmentEntryPoint<'_>>,
) -> Result<EntryPointBinding, Error>
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.
sourcefn write_ep_interface(
&mut self,
module: &Module,
func: &Function,
stage: ShaderStage,
ep_name: &str,
frag_ep: Option<&FragmentEntryPoint<'_>>,
) -> Result<EntryPointInterface, Error>
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.
fn write_ep_argument_initialization( &mut self, ep: &EntryPoint, ep_input: &EntryPointBinding, fake_member: &EpStructMember, ) -> Result<(), Error>
sourcefn write_ep_arguments_initialization(
&mut self,
module: &Module,
func: &Function,
ep_index: u16,
) -> Result<(), Error>
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.
sourcefn write_global(
&mut self,
module: &Module,
handle: Handle<GlobalVariable>,
) -> Result<(), Error>
fn write_global( &mut self, module: &Module, handle: Handle<GlobalVariable>, ) -> Result<(), Error>
fn write_global_sampler( &mut self, module: &Module, handle: Handle<GlobalVariable>, global: &GlobalVariable, ) -> Result<(), Error>
sourcefn write_global_constant(
&mut self,
module: &Module,
handle: Handle<Constant>,
) -> Result<(), Error>
fn write_global_constant( &mut self, module: &Module, handle: Handle<Constant>, ) -> Result<(), Error>
pub(super) fn write_array_size( &mut self, module: &Module, base: Handle<Type>, size: ArraySize, ) -> Result<(), Error>
sourcefn write_struct(
&mut self,
module: &Module,
handle: Handle<Type>,
members: &[StructMember],
span: u32,
shader_stage: Option<(ShaderStage, Io)>,
) -> Result<(), Error>
fn write_struct( &mut self, module: &Module, handle: Handle<Type>, members: &[StructMember], span: u32, shader_stage: Option<(ShaderStage, Io)>, ) -> Result<(), Error>
sourcepub(super) fn write_global_type(
&mut self,
module: &Module,
ty: Handle<Type>,
) -> Result<(), Error>
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
sourcepub(super) fn write_type(
&mut self,
module: &Module,
ty: Handle<Type>,
) -> Result<(), Error>
pub(super) fn write_type( &mut self, module: &Module, ty: Handle<Type>, ) -> Result<(), Error>
sourcepub(super) fn write_value_type(
&mut self,
module: &Module,
inner: &TypeInner,
) -> Result<(), Error>
pub(super) fn write_value_type( &mut self, module: &Module, inner: &TypeInner, ) -> Result<(), Error>
sourcefn write_function(
&mut self,
module: &Module,
name: &str,
func: &Function,
func_ctx: &FunctionCtx<'_>,
info: &FunctionInfo,
) -> Result<(), Error>
fn write_function( &mut self, module: &Module, name: &str, func: &Function, func_ctx: &FunctionCtx<'_>, info: &FunctionInfo, ) -> Result<(), Error>
fn need_workgroup_variables_initialization( &mut self, func_ctx: &FunctionCtx<'_>, module: &Module, ) -> bool
fn write_workgroup_variables_initialization( &mut self, func_ctx: &FunctionCtx<'_>, module: &Module, ) -> Result<(), Error>
sourcefn write_switch(
&mut self,
module: &Module,
func_ctx: &FunctionCtx<'_>,
level: Level,
selector: Handle<Expression>,
cases: &[SwitchCase],
) -> Result<(), Error>
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
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>
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>
sourcepub(super) fn write_expr(
&mut self,
module: &Module,
expr: Handle<Expression>,
func_ctx: &FunctionCtx<'_>,
) -> Result<(), Error>
pub(super) fn write_expr( &mut self, module: &Module, expr: Handle<Expression>, func_ctx: &FunctionCtx<'_>, ) -> Result<(), Error>
sourcefn sampler_binding_array_info_from_expression(
&mut self,
module: &Module,
func_ctx: &FunctionCtx<'_>,
base: Handle<Expression>,
resolved: &TypeInner,
) -> Option<BindingArraySamplerInfo>
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.
fn write_named_expr( &mut self, module: &Module, handle: Handle<Expression>, name: String, named: Handle<Expression>, ctx: &FunctionCtx<'_>, ) -> Result<(), Error>
sourcepub(super) fn write_default_init(
&mut self,
module: &Module,
ty: Handle<Type>,
) -> Result<(), Error>
pub(super) fn write_default_init( &mut self, module: &Module, ty: Handle<Type>, ) -> Result<(), Error>
Helper function that write default zero initialization