Struct vulkano::pipeline::cache::PipelineCache [−][src]
pub struct PipelineCache { /* fields omitted */ }
Expand description
Opaque cache that contains pipeline objects.
See the documentation of the module for more info.
Implementations
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()
};
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>>,
pub fn merge<'a, I>(&self, pipelines: I) -> Result<(), OomError> where
I: IntoIterator<Item = &'a &'a Arc<PipelineCache>>,
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.
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
Auto Trait Implementations
impl RefUnwindSafe for PipelineCache
impl Send for PipelineCache
impl Sync for PipelineCache
impl Unpin for PipelineCache
impl UnwindSafe for PipelineCache
Blanket Implementations
Mutably borrows from an owned value. Read more
Builds a pointer to this type from a raw pointer.
Returns true if the size is suitable to store a type like this.
Returns the size of an individual element.