Skip to main content

SpirVBackend

Struct SpirVBackend 

Source
pub struct SpirVBackend {
    pub module: SpirVModule,
    /* private fields */
}
Expand description

The SPIR-V code generation backend for OxiLean.

Translates OxiLean expressions and declarations into SPIR-V modules targeting Vulkan compute or graphics shaders.

Fields§

§module: SpirVModule

The SPIR-V module being built

Implementations§

Source§

impl SpirVBackend

Source

pub fn new() -> Self

Create a new SPIR-V backend.

Source

pub fn configure_for_vulkan(&mut self)

Enable the Shader capability and GLSL 450 memory model (typical Vulkan setup).

Source

pub fn configure_for_opencl(&mut self)

Configure for OpenCL/compute kernels.

Source

pub fn get_void_type(&mut self) -> u32

Declare or retrieve the void type.

Source

pub fn declare_int_type(&mut self, width: u32, signed: bool) -> u32

Declare a scalar integer type.

Source

pub fn declare_float_type(&mut self, width: u32) -> u32

Declare a scalar float type.

Source

pub fn declare_vector_type(&mut self, element_type_id: u32, count: u32) -> u32

Declare a vector type.

Source

pub fn declare_pointer_type( &mut self, storage_class: StorageClass, pointee_type_id: u32, ) -> u32

Declare a pointer type.

Source

pub fn declare_function_type( &mut self, return_type_id: u32, param_type_ids: Vec<u32>, ) -> u32

Declare a function type.

Source

pub fn declare_int_constant(&mut self, type_id: u32, value: u64) -> u32

Declare an integer constant.

Source

pub fn declare_float_constant(&mut self, type_id: u32, value: f32) -> u32

Declare a float constant.

Source

pub fn declare_bool_constant(&mut self, type_id: u32, value: bool) -> u32

Declare a bool constant.

Source

pub fn declare_global_variable( &mut self, name: impl Into<String>, type_id: u32, storage_class: StorageClass, decorations: Vec<Decoration>, ) -> u32

Declare a global variable.

Source

pub fn begin_function( &mut self, name: impl Into<String>, return_type_id: u32, param_type_ids: Vec<u32>, ) -> SpirVFunction

Begin building a new function.

Source

pub fn finish_function(&mut self, func: SpirVFunction)

Finalize and add a function to the module.

Source

pub fn emit_text(&self) -> String

Emit the module as SPIR-V assembly text.

Source

pub fn emit_binary_header(&self) -> Vec<u32>

Emit a minimal valid SPIR-V binary header (magic + version + generator + bound + schema).

Source

pub fn function_count(&self) -> usize

Get the number of functions in the module.

Source

pub fn lookup_symbol(&self, name: &str) -> Option<u32>

Look up a symbol by name.

Source

pub fn emit_compute_kernel( &mut self, kernel_name: impl Into<String>, local_size_x: u32, local_size_y: u32, local_size_z: u32, ) -> u32

Emit a compute shader skeleton for the given kernel name and local size.

Trait Implementations§

Source§

impl Debug for SpirVBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpirVBackend

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.