pub struct Writer {Show 22 fields
physical_layout: PhysicalLayout,
logical_layout: LogicalLayout,
id_gen: IdGenerator,
capabilities_available: Option<FastHashSet<Capability>>,
capabilities_used: FastIndexSet<Capability>,
extensions_used: FastIndexSet<&'static str>,
debugs: Vec<Instruction>,
annotations: Vec<Instruction>,
flags: WriterFlags,
bounds_check_policies: BoundsCheckPolicies,
zero_initialize_workgroup_memory: ZeroInitializeWorkgroupMemoryMode,
void_type: Word,
lookup_type: FastHashMap<LookupType, Word>,
lookup_function: FastHashMap<Handle<Function>, Word>,
lookup_function_type: FastHashMap<LookupFunctionType, Word>,
constant_ids: HandleVec<Expression, Word>,
cached_constants: FastHashMap<CachedConstant, Word>,
global_variables: HandleVec<GlobalVariable, GlobalVariable>,
binding_map: BindingMap,
saved_cached: CachedExpressions,
gl450_ext_inst_id: Word,
temp_list: Vec<Word>,
}
Fields§
§physical_layout: PhysicalLayout
§logical_layout: LogicalLayout
§id_gen: IdGenerator
§capabilities_available: Option<FastHashSet<Capability>>
The set of capabilities modules are permitted to use.
This is initialized from Options::capabilities
.
capabilities_used: FastIndexSet<Capability>
The set of capabilities used by this module.
If capabilities_available
is Some
, then this is always a subset of
that.
extensions_used: FastIndexSet<&'static str>
The set of spirv extensions used.
debugs: Vec<Instruction>
§annotations: Vec<Instruction>
§flags: WriterFlags
§bounds_check_policies: BoundsCheckPolicies
§zero_initialize_workgroup_memory: ZeroInitializeWorkgroupMemoryMode
§void_type: Word
§lookup_type: FastHashMap<LookupType, Word>
§lookup_function: FastHashMap<Handle<Function>, Word>
§lookup_function_type: FastHashMap<LookupFunctionType, Word>
§constant_ids: HandleVec<Expression, Word>
Indexed by const-expression handle indexes
cached_constants: FastHashMap<CachedConstant, Word>
§global_variables: HandleVec<GlobalVariable, GlobalVariable>
§binding_map: BindingMap
§saved_cached: CachedExpressions
§gl450_ext_inst_id: Word
§temp_list: Vec<Word>
Implementations§
source§impl Writer
impl Writer
fn write_epilogue_position_y_flip( &mut self, position_id: Word, body: &mut Vec<Instruction>, ) -> Result<(), Error>
fn write_epilogue_frag_depth_clamp( &mut self, frag_depth_id: Word, body: &mut Vec<Instruction>, ) -> Result<(), Error>
fn write_entry_point_return( &mut self, value_id: Word, ir_result: &FunctionResult, result_members: &[ResultMember], body: &mut Vec<Instruction>, ) -> Result<(), Error>
source§impl Writer
impl Writer
pub fn new(options: &Options<'_>) -> Result<Self, Error>
sourcefn reset(&mut self)
fn reset(&mut self)
Reset Writer
to its initial state, retaining any allocations.
Why not just implement Recyclable
for Writer
? By design,
Recyclable::recycle
requires ownership of the value, not just
&mut
; see the trait documentation. But we need to use this method
from functions like Writer::write
, which only have &mut Writer
.
Workarounds include unsafe code (std::ptr::read
, then write
, ugh)
or something like a Default
impl that returns an oddly-initialized
Writer
, which is worse.
sourcepub(super) fn require_any(
&mut self,
what: &'static str,
capabilities: &[Capability],
) -> Result<(), Error>
pub(super) fn require_any( &mut self, what: &'static str, capabilities: &[Capability], ) -> Result<(), Error>
Indicate that the code requires any one of the listed capabilities.
If nothing in capabilities
appears in the available capabilities
specified in the Options
from which this Writer
was created,
return an error. The what
string is used in the error message to
explain what provoked the requirement. (If no available capabilities were
given, assume everything is available.)
The first acceptable capability will be added to this Writer
’s
capabilities_used
table, and an OpCapability
emitted for it in the
result. For this reason, more specific capabilities should be listed
before more general.
sourcepub(super) fn use_extension(&mut self, extension: &'static str)
pub(super) fn use_extension(&mut self, extension: &'static str)
Indicate that the code uses the given extension.
pub(super) fn get_type_id(&mut self, lookup_ty: LookupType) -> Word
pub(super) fn get_expression_lookup_type( &mut self, tr: &TypeResolution, ) -> LookupType
pub(super) fn get_expression_type_id(&mut self, tr: &TypeResolution) -> Word
pub(super) fn get_pointer_id( &mut self, handle: Handle<Type>, class: StorageClass, ) -> Word
sourcepub(super) fn get_resolution_pointer_id(
&mut self,
resolution: &TypeResolution,
class: StorageClass,
) -> Word
pub(super) fn get_resolution_pointer_id( &mut self, resolution: &TypeResolution, class: StorageClass, ) -> Word
Return a SPIR-V type for a pointer to resolution
.
The given resolution
must be one that we can represent
either as a LocalType::Pointer
or LocalType::LocalPointer
.
pub(super) fn get_uint_type_id(&mut self) -> Word
pub(super) fn get_float_type_id(&mut self) -> Word
pub(super) fn get_uint3_type_id(&mut self) -> Word
pub(super) fn get_float_pointer_type_id(&mut self, class: StorageClass) -> Word
pub(super) fn get_uint3_pointer_type_id(&mut self, class: StorageClass) -> Word
pub(super) fn get_bool_type_id(&mut self) -> Word
pub(super) fn get_bool3_type_id(&mut self) -> Word
pub(super) fn decorate( &mut self, id: Word, decoration: Decoration, operands: &[Word], )
fn write_function( &mut self, ir_function: &Function, info: &FunctionInfo, ir_module: &Module, interface: Option<FunctionInterface<'_>>, debug_info: &Option<DebugInfoInner<'_>>, ) -> Result<Word, Error>
fn write_execution_mode( &mut self, function_id: Word, mode: ExecutionMode, ) -> Result<(), Error>
fn write_entry_point( &mut self, entry_point: &EntryPoint, info: &FunctionInfo, ir_module: &Module, debug_info: &Option<DebugInfoInner<'_>>, ) -> Result<Instruction, Error>
fn make_scalar(&mut self, id: Word, scalar: Scalar) -> Instruction
fn request_type_capabilities(&mut self, inner: &TypeInner) -> Result<(), Error>
fn write_numeric_type_declaration_local( &mut self, id: Word, numeric: NumericType, )
fn write_type_declaration_local(&mut self, id: Word, local_ty: LocalType)
fn write_type_declaration_arena( &mut self, arena: &UniqueArena<Type>, handle: Handle<Type>, ) -> Result<Word, Error>
fn request_image_format_capabilities( &mut self, format: ImageFormat, ) -> Result<(), Error>
pub(super) fn get_index_constant(&mut self, index: Word) -> Word
pub(super) fn get_constant_scalar_with( &mut self, value: u8, scalar: Scalar, ) -> Result<Word, Error>
pub(super) fn get_constant_scalar(&mut self, value: Literal) -> Word
fn write_constant_scalar( &mut self, id: Word, value: &Literal, debug_name: Option<&String>, )
pub(super) fn get_constant_composite( &mut self, ty: LookupType, constituent_ids: &[Word], ) -> Word
fn write_constant_composite( &mut self, id: Word, ty: LookupType, constituent_ids: &[Word], debug_name: Option<&String>, )
pub(super) fn get_constant_null(&mut self, type_id: Word) -> Word
pub(super) fn write_constant_null(&mut self, type_id: Word) -> Word
fn write_constant_expr( &mut self, handle: Handle<Expression>, ir_module: &Module, mod_info: &ModuleInfo, ) -> Result<Word, Error>
pub(super) fn write_barrier(&mut self, flags: Barrier, block: &mut Block)
fn generate_workgroup_vars_init_block( &mut self, entry_id: Word, ir_module: &Module, info: &FunctionInfo, local_invocation_id: Option<Word>, interface: &mut FunctionInterface<'_>, function: &mut Function, ) -> Option<Word>
sourcefn write_varying(
&mut self,
ir_module: &Module,
stage: ShaderStage,
class: StorageClass,
debug_name: Option<&str>,
ty: Handle<Type>,
binding: &Binding,
) -> Result<Word, Error>
fn write_varying( &mut self, ir_module: &Module, stage: ShaderStage, class: StorageClass, debug_name: Option<&str>, ty: Handle<Type>, binding: &Binding, ) -> Result<Word, Error>
Generate an OpVariable
for one value in an EntryPoint
’s IO interface.
The Binding
s of the arguments and result of an EntryPoint
’s
Function
describe a SPIR-V shader interface. In SPIR-V, the
interface is represented by global variables in the Input
and Output
storage classes, with decorations indicating which builtin or location
each variable corresponds to.
This function emits a single global OpVariable
for a single value from
the interface, and adds appropriate decorations to indicate which
builtin or location it represents, how it should be interpolated, and so
on. The class
argument gives the variable’s SPIR-V storage class,
which should be either Input
or Output
.
fn write_global_variable( &mut self, ir_module: &Module, global_variable: &GlobalVariable, ) -> Result<Word, Error>
sourcefn decorate_struct_member(
&mut self,
struct_id: Word,
index: usize,
member: &StructMember,
arena: &UniqueArena<Type>,
) -> Result<(), Error>
fn decorate_struct_member( &mut self, struct_id: Word, index: usize, member: &StructMember, arena: &UniqueArena<Type>, ) -> Result<(), Error>
Write the necessary decorations for a struct member.
Emit decorations for the index
’th member of the struct type
designated by struct_id
, described by member
.
fn get_function_type( &mut self, lookup_function_type: LookupFunctionType, ) -> Word
fn write_physical_layout(&mut self)
fn write_logical_layout( &mut self, ir_module: &Module, mod_info: &ModuleInfo, ep_index: Option<usize>, debug_info: &Option<DebugInfo<'_>>, ) -> Result<(), Error>
pub fn write( &mut self, ir_module: &Module, info: &ModuleInfo, pipeline_options: Option<&PipelineOptions>, debug_info: &Option<DebugInfo<'_>>, words: &mut Vec<Word>, ) -> Result<(), Error>
sourcepub const fn get_capabilities_used(&self) -> &FastIndexSet<Capability>
pub const fn get_capabilities_used(&self) -> &FastIndexSet<Capability>
Return the set of capabilities the last module written used.