Struct vulkano::pipeline::cache::PipelineCache[][src]

pub struct PipelineCache { /* fields omitted */ }

Opaque cache that contains pipeline objects.

See the documentation of the module for more info.

Implementations

impl PipelineCache[src]

pub unsafe fn with_data(
    device: Arc<Device>,
    initial_data: &[u8]
) -> Result<Arc<PipelineCache>, OomError>
[src]

Builds a new pipeline cache from existing data. The data must have been previously obtained with get_data.

The data passed to this function will most likely be blindly trusted by the Vulkan implementation. Therefore you can easily crash your application or the system by passing wrong data. Hence why this function is unsafe.

Example

This example loads a cache from a file, if it exists. See get_data for how to store the data in a file. TODO: there’s a header in the cached data that must be checked ; talk about this

use std::fs::File;
use std::io::Read;
use vulkano::pipeline::cache::PipelineCache;

let data = {
    let file = File::open("pipeline_cache.bin");
    if let Ok(mut file) = file {
        let mut data = Vec::new();
        if let Ok(_) = file.read_to_end(&mut data) {
            Some(data)
        } else { None }
    } else { None }
};

let cache = if let Some(data) = data {
    // This is unsafe because there is no way to be sure that the file contains valid data.
    unsafe { PipelineCache::with_data(device.clone(), &data).unwrap() }
} else {
    PipelineCache::empty(device.clone()).unwrap()
};

pub fn empty(device: Arc<Device>) -> Result<Arc<PipelineCache>, OomError>[src]

Builds a new empty pipeline cache.

Example

use vulkano::pipeline::cache::PipelineCache;
let cache = PipelineCache::empty(device.clone()).unwrap();

pub fn merge<'a, I>(&self, pipelines: I) -> Result<(), OomError> where
    I: IntoIterator<Item = &'a &'a Arc<PipelineCache>>, 
[src]

Merges other pipeline caches into this one.

It is self that is modified here. The pipeline caches passed as parameter are untouched.

Panic

  • Panics if self is included in the list of other pipelines.

pub fn get_data(&self) -> Result<Vec<u8>, OomError>[src]

Obtains the data from the cache.

This data can be stored and then reloaded and passed to PipelineCache::with_data.

Example

This example stores the data of a pipeline cache on the disk. See with_data for how to reload it.

use std::fs;
use std::fs::File;
use std::io::Write;

// If an error happens (eg. no permission for the file) we simply skip storing the cache.
if let Ok(data) = cache.get_data() {
    if let Ok(mut file) = File::create("pipeline_cache.bin.tmp") {
        if let Ok(_) = file.write_all(&data) {
            let _ = fs::rename("pipeline_cache.bin.tmp", "pipeline_cache.bin");
        } else {
            let _ = fs::remove_file("pipeline_cache.bin.tmp");
        }
    }
}

Trait Implementations

impl Drop for PipelineCache[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl VulkanObject for PipelineCache[src]

type Object = PipelineCache

The type of the object.

const TYPE: ObjectType[src]

The ObjectType of the internal Vulkan handle.

fn internal_object(&self) -> PipelineCache[src]

Returns a reference to the object.

Auto Trait Implementations

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> Content for T[src]

pub fn ref_from_ptr(*mut c_void, usize) -> Option<*mut T>[src]

Builds a pointer to this type from a raw pointer.

pub fn is_size_suitable(usize) -> bool[src]

Returns true if the size is suitable to store a type like this.

pub fn indiv_size() -> usize[src]

Returns the size of an individual element.

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.