pub fn check_copy_buffer_image<B, I, P>(device: &Device, buffer: &B, image: &I,
                                        ty: CheckCopyBufferImageTy, image_offset: [u32; 3],
                                        image_size: [u32; 3], image_first_layer: u32,
                                        image_num_layers: u32, image_mipmap: u32)
                                        -> Result<(), CheckCopyBufferImageError>
    where I: ?Sized + ImageAccess,
          B: ?Sized + TypedBufferAccess<Content = [P]>,
          Format: AcceptsPixels<P> // TODO: use a trait on the image itself instead
{
    let buffer_inner = buffer.inner();
    let image_inner = image.inner();

    assert_eq!(buffer_inner.buffer.device().internal_object(),
               device.internal_object());
    assert_eq!(image_inner.image.device().internal_object(),
               device.internal_object());

    match ty {
        CheckCopyBufferImageTy::BufferToImage => {
            if !buffer_inner.buffer.usage_transfer_source() {
                return Err(CheckCopyBufferImageError::SourceMissingTransferUsage);
            }
            if !image_inner.image.usage_transfer_destination() {
                return Err(CheckCopyBufferImageError::DestinationMissingTransferUsage);
            }
        },
        CheckCopyBufferImageTy::ImageToBuffer => {
            if !image_inner.image.usage_transfer_source() {
                return Err(CheckCopyBufferImageError::SourceMissingTransferUsage);
            }
            if !buffer_inner.buffer.usage_transfer_destination() {
                return Err(CheckCopyBufferImageError::DestinationMissingTransferUsage);
            }
        },
    }

    if image.samples() != 1 {
        return Err(CheckCopyBufferImageError::UnexpectedMultisampled);
    }

    let image_dimensions = match image.dimensions().mipmap_dimensions(image_mipmap) {
        Some(d) => d,
        None => return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange),
    };

    if image_first_layer + image_num_layers > image_dimensions.array_layers() {
        return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange);
    }

    if image_offset[0] + image_size[0] > image_dimensions.width() {
        return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange);
    }

    if image_offset[1] + image_size[1] > image_dimensions.height() {
        return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange);
    }

    if image_offset[2] + image_size[2] > image_dimensions.depth() {
        return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange);
    }

    image.format().ensure_accepts()?;

    {
        let num_texels = image_size[0] * image_size[1] * image_size[2] * image_num_layers;
        let required_len = num_texels as usize * image.format().rate() as usize;
        if required_len > buffer.len() {
            return Err(CheckCopyBufferImageError::BufferTooSmall {
                           required_len: required_len,
                           actual_len: buffer.len(),
                       });
        }
    }

    // TODO: check memory overlap?

    Ok(())
}
/// Checks whether a copy buffer-image command is valid. Can check both buffer-to-image copies and
/// image-to-buffer copies.
///
/// # Panic
///
/// - Panics if the buffer and image were not created with `device`.
///
// TODO: handle compressed image formats
Checks whether a copy buffer-image command is valid. Can check both buffer-to-image copies and
image-to-buffer copies.
Checks whether a copy buffer - image command is valid . Can check both buffer - to - image copies and image - to - buffer copies .
pub fn check_copy_buffer_image<B, I, P>(device: &Device, buffer: &B, image: &I,
                                        ty: CheckCopyBufferImageTy, image_offset: [u32; 3],
                                        image_size: [u32; 3], image_first_layer: u32,
                                        image_num_layers: u32, image_mipmap: u32)
                                        -> Result<(), CheckCopyBufferImageError>
    where I: ?Sized + ImageAccess,
          B: ?Sized + TypedBufferAccess<Content = [P]>,
          Format: AcceptsPixels<P> // TODO: use a trait on the image itself instead
{
    let buffer_inner = buffer.inner();
    let image_inner = image.inner();
    assert_eq!(buffer_inner.buffer.device().internal_object(),
               device.internal_object());
    assert_eq!(image_inner.image.device().internal_object(),
               device.internal_object());
    match ty {
        CheckCopyBufferImageTy::BufferToImage => {
            if !buffer_inner.buffer.usage_transfer_source() {
                return Err(CheckCopyBufferImageError::SourceMissingTransferUsage);
            }
            if !image_inner.image.usage_transfer_destination() {
                return Err(CheckCopyBufferImageError::DestinationMissingTransferUsage);
            }
        },
        CheckCopyBufferImageTy::ImageToBuffer => {
            if !image_inner.image.usage_transfer_source() {
                return Err(CheckCopyBufferImageError::SourceMissingTransferUsage);
            }
            if !buffer_inner.buffer.usage_transfer_destination() {
                return Err(CheckCopyBufferImageError::DestinationMissingTransferUsage);
            }
        },
    }
    if image.samples() != 1 {
        return Err(CheckCopyBufferImageError::UnexpectedMultisampled);
    }
    let image_dimensions = match image.dimensions().mipmap_dimensions(image_mipmap) {
        Some(d) => d,
        None => return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange),
    };
    if image_first_layer + image_num_layers > image_dimensions.array_layers() {
        return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange);
    }
    if image_offset[0] + image_size[0] > image_dimensions.width() {
        return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange);
    }
    if image_offset[1] + image_size[1] > image_dimensions.height() {
        return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange);
    }
    if image_offset[2] + image_size[2] > image_dimensions.depth() {
        return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange);
    }
    image.format().ensure_accepts()?;
    {
        let num_texels = image_size[0] * image_size[1] * image_size[2] * image_num_layers;
        let required_len = num_texels as usize * image.format().rate() as usize;
        if required_len > buffer.len() {
            return Err(CheckCopyBufferImageError::BufferTooSmall {
                           required_len: required_len,
                           actual_len: buffer.len(),
                       });
        }
    }
    // TODO: check memory overlap?
    Ok(())
}
pub fn check_copy_buffer_image < B , I , P > ( device : & Device , buffer : & B , image : & I , ty : CheckCopyBufferImageTy , image_offset : [ u32 ; 3 ] , image_size : [ u32 ; 3 ] , image_first_layer : u32 , image_num_layers : u32 , image_mipmap : u32 ) -> Result < ( ) , CheckCopyBufferImageError > where I : ? Sized + ImageAccess , B : ? Sized + TypedBufferAccess < Content = [ P ] > , Format : AcceptsPixels < P > // TODO: use a trait on the image itself instead { let buffer_inner = buffer . inner ( ) ; let image_inner = image . inner ( ) ; assert_eq ! ( buffer_inner buffer device ( ) internal_object ( ) device internal_object ( ) ) ; assert_eq ! ( image_inner image device ( ) internal_object ( ) device internal_object ( ) ) ; match ty { CheckCopyBufferImageTy :: BufferToImage => { if ! buffer_inner . buffer . usage_transfer_source ( ) { return Err ( CheckCopyBufferImageError :: SourceMissingTransferUsage ) ; } if ! image_inner . image . usage_transfer_destination ( ) { return Err ( CheckCopyBufferImageError :: DestinationMissingTransferUsage ) ; } } , CheckCopyBufferImageTy :: ImageToBuffer => { if ! image_inner . image . usage_transfer_source ( ) { return Err ( CheckCopyBufferImageError :: SourceMissingTransferUsage ) ; } if ! buffer_inner . buffer . usage_transfer_destination ( ) { return Err ( CheckCopyBufferImageError :: DestinationMissingTransferUsage ) ; } } , } if image . samples ( ) != 1 { return Err ( CheckCopyBufferImageError :: UnexpectedMultisampled ) ; } let image_dimensions = match image . dimensions ( ) . mipmap_dimensions ( image_mipmap ) { Some ( d ) => d , None => return Err ( CheckCopyBufferImageError :: ImageCoordinatesOutOfRange ) , } ; if image_first_layer + image_num_layers > image_dimensions . array_layers ( ) { return Err ( CheckCopyBufferImageError :: ImageCoordinatesOutOfRange ) ; } if image_offset [ 0 ] + image_size [ 0 ] > image_dimensions . width ( ) { return Err ( CheckCopyBufferImageError :: ImageCoordinatesOutOfRange ) ; } if image_offset [ 1 ] + image_size [ 1 ] > image_dimensions . height ( ) { return Err ( CheckCopyBufferImageError :: ImageCoordinatesOutOfRange ) ; } if image_offset [ 2 ] + image_size [ 2 ] > image_dimensions . depth ( ) { return Err ( CheckCopyBufferImageError :: ImageCoordinatesOutOfRange ) ; } image . format ( ) . ensure_accepts ( ) ? ; { let num_texels = image_size [ 0 ] * image_size [ 1 ] * image_size [ 2 ] * image_num_layers ; let required_len = num_texels as usize * image . format ( ) . rate ( ) as usize ; if required_len > buffer . len ( ) { return Err ( CheckCopyBufferImageError :: BufferTooSmall { required_len : required_len , actual_len : buffer . len ( ) , } ) ; } } // TODO: check memory overlap? Ok ( ( ) ) }
Checks whether a copy buffer-image command is valid.
Checks whether a copy buffer - image command is valid .
device
&Device
buffer
&B
image
&I
ty
CheckCopyBufferImageTy
image_offset
[u32; 3]
image_size
[u32; 3]
image_first_layer
u32
image_num_layers
u32
image_mipmap
u32
device
&Device
buffer
&B
image
&I
ty
CheckCopyBufferImageTy
image_offset
[u32; 3]
image_size
[u32; 3]
image_first_layer
u32
image_num_layers
u32
image_mipmap
u32
panic
Panics if the buffer and image were not created with `device`.

handle compressed image formats
Panics if the buffer and image were not created with ` device ` . handle compressed image formats