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

pub struct PipelineCache { /* fields omitted */ }

Opaque cache that contains pipeline objects.

See the documentation of the module for more info.

Methods

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 VulkanObject for PipelineCache[src]

type Object = PipelineCache

The type of the object.

impl Drop for PipelineCache[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Content for T[src]

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

impl<T> From<T> for 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.

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

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

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