[][src]Enum emu_core::compile::SpirvOrFinished

pub enum SpirvOrFinished<P: BorrowMut<[u32]>, C: Cache> {
    SpirvAndHash((Spirv<P>, u64, PhantomData<C>)),
    Finished(Arc<DeviceFnMut>),
}

Either a finished DeviceFnMut or compiled SPIR-V

You can either call finish on this to get your final compiled DeviceFnMut or you can inspect/mutate the inner SPIR-V before finishing.

let kernel: Vec<u8> = vec![
    // Magic number.           Version number: 1.0.
    0x03, 0x02, 0x23, 0x07,    0x00, 0x00, 0x01, 0x00,
    // Generator number: 0.    Bound: 0.
    0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00,
    // Reserved word: 0.
    0x00, 0x00, 0x00, 0x00,
    // OpMemoryModel.          Logical.
    0x0e, 0x00, 0x03, 0x00,    0x00, 0x00, 0x00, 0x00,
    // GLSL450.
    0x01, 0x00, 0x00, 0x00];
let spirv: Spirv<Vec<u32>> = SpirvBuilder::new()
    .set_entry_point_name("main")
    .add_param_mut::<[f32]>()
    .add_param::<[f32]>()
    .set_code_with_u8(Cursor::new(kernel))?
    .build();

// in this case, `compile` doesn't do much other than caching
// but where `Spirv` is replaced with `Glsl` or `GlslKernel`,
// actual compilation takes place here
let mut spirv_or_finished = compile::<Spirv<_>, SpirvCompile, Vec<u32>, GlobalCache>(spirv)?;
// print out the SPIR-V and finish
if let Some(code) = spirv_or_finished.get_code_mut() {
    println!("{:?}", code);
}

// the returned result is an ARC of a `DeviceFnMut`
// ARC just stands for "automatic reference counting"
// it means that there is runtime reference counting to
// ensure the compiled kernel can be safely used by multiple threads simultaneously
let finished_device_fn_mut = spirv_or_finished.finish()?;
// the above `finish` completes the compilation and in this case it
// will panic because our SPIR-V doesn't actually include a main function

Variants

SpirvAndHash((Spirv<P>, u64, PhantomData<C>))
Finished(Arc<DeviceFnMut>)

Methods

impl<P: BorrowMut<[u32]>, C: Cache> SpirvOrFinished<P, C>[src]

pub fn get_code_mut(&mut self) -> Option<&mut [u32]>[src]

Get a mutable reference to the code stored here

This is useful when inspecting or linting the bytecode somehow before finishing compilation. If you decide to pass the SPIR-V through some sort of bytecode optimizer or such, this is the place

pub fn get_name_mut(&mut self) -> Option<&mut String>[src]

Mutate the entry point name

pub fn get_params_mut(&mut self) -> Option<&mut DeviceFnMutParams>[src]

Mutate the parameters

pub fn finish(&self) -> Result<Arc<DeviceFnMut>, CompileOrNoDeviceError>[src]

Finish the compilation and return a DeviceFnMut

Auto Trait Implementations

impl<P, C> !RefUnwindSafe for SpirvOrFinished<P, C>

impl<P, C> Send for SpirvOrFinished<P, C> where
    C: Send,
    P: Send

impl<P, C> Sync for SpirvOrFinished<P, C> where
    C: Sync,
    P: Sync

impl<P, C> Unpin for SpirvOrFinished<P, C> where
    C: Unpin,
    P: Unpin

impl<P, C> !UnwindSafe for SpirvOrFinished<P, C>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> AsDeviceBoxed<T> for U where
    T: AsBytes + ?Sized,
    U: Borrow<T>, 
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.