mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-26 00:34:19 +00:00
The memory pool trait is now implemented on the Arc itself
This commit is contained in:
parent
f194c5b476
commit
2c67b6d11d
@ -54,7 +54,7 @@ use OomError;
|
||||
|
||||
/// Buffer whose content is accessible by the CPU.
|
||||
#[derive(Debug)]
|
||||
pub struct CpuAccessibleBuffer<T: ?Sized, A = StdMemoryPool> where A: MemoryPool {
|
||||
pub struct CpuAccessibleBuffer<T: ?Sized, A = Arc<StdMemoryPool>> where A: MemoryPool {
|
||||
// Inner content.
|
||||
inner: UnsafeBuffer,
|
||||
|
||||
|
@ -42,7 +42,7 @@ use OomError;
|
||||
|
||||
/// Buffer whose content is accessible by the CPU.
|
||||
#[derive(Debug)]
|
||||
pub struct DeviceLocalBuffer<T: ?Sized, A = StdMemoryPool> where A: MemoryPool {
|
||||
pub struct DeviceLocalBuffer<T: ?Sized, A = Arc<StdMemoryPool>> where A: MemoryPool {
|
||||
// Inner content.
|
||||
inner: UnsafeBuffer,
|
||||
|
||||
|
@ -48,7 +48,7 @@ use sync::Sharing;
|
||||
use OomError;
|
||||
|
||||
/// Buffer that is written once then read for as long as it is alive.
|
||||
pub struct ImmutableBuffer<T: ?Sized, A = StdMemoryPool> where A: MemoryPool {
|
||||
pub struct ImmutableBuffer<T: ?Sized, A = Arc<StdMemoryPool>> where A: MemoryPool {
|
||||
// Inner content.
|
||||
inner: UnsafeBuffer,
|
||||
|
||||
|
@ -68,7 +68,7 @@ use sync::Sharing;
|
||||
///
|
||||
// TODO: forbid reading transient images outside render passes?
|
||||
#[derive(Debug)]
|
||||
pub struct AttachmentImage<F, A = StdMemoryPool> where A: MemoryPool {
|
||||
pub struct AttachmentImage<F, A = Arc<StdMemoryPool>> where A: MemoryPool {
|
||||
// Inner implementation.
|
||||
image: UnsafeImage,
|
||||
|
||||
|
@ -42,7 +42,7 @@ use sync::Sharing;
|
||||
/// but then you must only ever read from it. TODO: clarify because of blit operations
|
||||
// TODO: type (2D, 3D, array, etc.) as template parameter
|
||||
#[derive(Debug)]
|
||||
pub struct ImmutableImage<F, A = StdMemoryPool> where A: MemoryPool {
|
||||
pub struct ImmutableImage<F, A = Arc<StdMemoryPool>> where A: MemoryPool {
|
||||
image: UnsafeImage,
|
||||
view: UnsafeImageView,
|
||||
memory: A::Alloc,
|
||||
|
@ -43,7 +43,7 @@ use sync::Sharing;
|
||||
/// General-purpose image in device memory. Can be used for any usage, but will be slower than a
|
||||
/// specialized image.
|
||||
#[derive(Debug)]
|
||||
pub struct StorageImage<F, A = StdMemoryPool> where A: MemoryPool {
|
||||
pub struct StorageImage<F, A = Arc<StdMemoryPool>> where A: MemoryPool {
|
||||
// Inner implementation.
|
||||
image: UnsafeImage,
|
||||
|
||||
|
@ -7,8 +7,6 @@
|
||||
// notice may not be copied, modified, or distributed except
|
||||
// according to those terms.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use instance::MemoryType;
|
||||
use memory::DeviceMemory;
|
||||
use memory::MappedDeviceMemory;
|
||||
@ -38,7 +36,7 @@ pub unsafe trait MemoryPool: 'static + Send + Sync {
|
||||
/// - Panicks if `size` is 0.
|
||||
/// - Panicks if `alignment` is 0.
|
||||
///
|
||||
fn alloc(&Arc<Self>, ty: MemoryType, size: usize, alignment: usize, layout: AllocLayout)
|
||||
fn alloc(&self, ty: MemoryType, size: usize, alignment: usize, layout: AllocLayout)
|
||||
-> Result<Self::Alloc, OomError>;
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,13 @@ impl StdMemoryPool {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl MemoryPool for StdMemoryPool {
|
||||
unsafe impl MemoryPool for Arc<StdMemoryPool> {
|
||||
type Alloc = StdMemoryPoolAlloc;
|
||||
|
||||
fn alloc(me: &Arc<Self>, memory_type: MemoryType, size: usize, alignment: usize,
|
||||
fn alloc(&self, memory_type: MemoryType, size: usize, alignment: usize,
|
||||
layout: AllocLayout) -> Result<StdMemoryPoolAlloc, OomError>
|
||||
{
|
||||
let mut pools = me.pools.lock().unwrap();
|
||||
let mut pools = self.pools.lock().unwrap();
|
||||
|
||||
match pools.entry((memory_type.id(), layout)) {
|
||||
Entry::Occupied(entry) => {
|
||||
@ -63,12 +63,12 @@ unsafe impl MemoryPool for StdMemoryPool {
|
||||
&Pool::HostVisible(ref pool) => {
|
||||
let alloc = try!(StdHostVisibleMemoryTypePool::alloc(&pool, size, alignment));
|
||||
let inner = StdMemoryPoolAllocInner::HostVisible(alloc);
|
||||
Ok(StdMemoryPoolAlloc { inner: inner, pool: me.clone() })
|
||||
Ok(StdMemoryPoolAlloc { inner: inner, pool: self.clone() })
|
||||
},
|
||||
&Pool::NonHostVisible(ref pool) => {
|
||||
let alloc = try!(StdNonHostVisibleMemoryTypePool::alloc(&pool, size, alignment));
|
||||
let inner = StdMemoryPoolAllocInner::NonHostVisible(alloc);
|
||||
Ok(StdMemoryPoolAlloc { inner: inner, pool: me.clone() })
|
||||
Ok(StdMemoryPoolAlloc { inner: inner, pool: self.clone() })
|
||||
},
|
||||
}
|
||||
},
|
||||
@ -76,18 +76,18 @@ unsafe impl MemoryPool for StdMemoryPool {
|
||||
Entry::Vacant(entry) => {
|
||||
match memory_type.is_host_visible() {
|
||||
true => {
|
||||
let pool = StdHostVisibleMemoryTypePool::new(&me.device, memory_type);
|
||||
let pool = StdHostVisibleMemoryTypePool::new(&self.device, memory_type);
|
||||
entry.insert(Pool::HostVisible(pool.clone()));
|
||||
let alloc = try!(StdHostVisibleMemoryTypePool::alloc(&pool, size, alignment));
|
||||
let inner = StdMemoryPoolAllocInner::HostVisible(alloc);
|
||||
Ok(StdMemoryPoolAlloc { inner: inner, pool: me.clone() })
|
||||
Ok(StdMemoryPoolAlloc { inner: inner, pool: self.clone() })
|
||||
},
|
||||
false => {
|
||||
let pool = StdNonHostVisibleMemoryTypePool::new(&me.device, memory_type);
|
||||
let pool = StdNonHostVisibleMemoryTypePool::new(&self.device, memory_type);
|
||||
entry.insert(Pool::NonHostVisible(pool.clone()));
|
||||
let alloc = try!(StdNonHostVisibleMemoryTypePool::alloc(&pool, size, alignment));
|
||||
let inner = StdMemoryPoolAllocInner::NonHostVisible(alloc);
|
||||
Ok(StdMemoryPoolAlloc { inner: inner, pool: me.clone() })
|
||||
Ok(StdMemoryPoolAlloc { inner: inner, pool: self.clone() })
|
||||
},
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user