use crate::Backend;
use crate::{buffer, image, queue};
use std::mem;
use std::ops::Range;
pub unsafe trait Pod: Copy {}
macro_rules! impl_pod {
( ty = $($ty:ty)* ) => { $( unsafe impl Pod for $ty {} )* };
( ar = $($tt:expr)* ) => { $( unsafe impl<T: Pod> Pod for [T; $tt] {} )* };
}
impl_pod! { ty = isize usize i8 u8 i16 u16 i32 u32 i64 u64 f32 f64 }
impl_pod! { ar =
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
}
unsafe impl<T: Pod, U: Pod> Pod for (T, U) {}
pub fn cast_slice<A: Pod, B: Pod>(slice: &[A]) -> &[B] {
use std::slice;
let raw_len = mem::size_of::<A>().wrapping_mul(slice.len());
let len = raw_len / mem::size_of::<B>();
assert_eq!(raw_len, mem::size_of::<B>().wrapping_mul(len));
unsafe { slice::from_raw_parts(slice.as_ptr() as *const B, len) }
}
bitflags!(
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Properties: u16 {
const DEVICE_LOCAL = 0x1;
const CPU_VISIBLE = 0x2;
const COHERENT = 0x4;
const CPU_CACHED = 0x8;
const LAZILY_ALLOCATED = 0x10;
}
);
bitflags!(
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Dependencies: u32 {
const BY_REGION = 0x1;
}
);
#[allow(missing_docs)]
#[derive(Clone, Debug)]
pub enum Barrier<'a, B: Backend> {
AllBuffers(Range<buffer::Access>),
AllImages(Range<image::Access>),
Buffer {
states: Range<buffer::State>,
target: &'a B::Buffer,
families: Option<Range<queue::QueueFamilyId>>,
range: Range<Option<u64>>,
},
Image {
states: Range<image::State>,
target: &'a B::Image,
families: Option<Range<queue::QueueFamilyId>>,
range: image::SubresourceRange,
},
}
impl<'a, B: Backend> Barrier<'a, B> {
pub fn whole_buffer(target: &'a B::Buffer, states: Range<buffer::State>) -> Self {
Barrier::Buffer {
states,
target,
families: None,
range: None..None,
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct Requirements {
pub size: u64,
pub alignment: u64,
pub type_mask: u64,
}