• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016 The vulkano developers
2 // Licensed under the Apache License, Version 2.0
3 // <LICENSE-APACHE or
4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT
5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>,
6 // at your option. All files in the project carrying such
7 // notice may not be copied, modified, or distributed except
8 // according to those terms.
9 
10 use std::error;
11 use std::fmt;
12 
13 use crate::device::Device;
14 use crate::image::ImageAccess;
15 use crate::VulkanObject;
16 
17 /// Checks whether a clear color image command is valid.
18 ///
19 /// # Panic
20 ///
21 /// - Panics if the destination was not created with `device`.
22 ///
check_clear_color_image<I>( device: &Device, image: &I, first_layer: u32, num_layers: u32, first_mipmap: u32, num_mipmaps: u32, ) -> Result<(), CheckClearColorImageError> where I: ?Sized + ImageAccess,23 pub fn check_clear_color_image<I>(
24     device: &Device,
25     image: &I,
26     first_layer: u32,
27     num_layers: u32,
28     first_mipmap: u32,
29     num_mipmaps: u32,
30 ) -> Result<(), CheckClearColorImageError>
31 where
32     I: ?Sized + ImageAccess,
33 {
34     assert_eq!(
35         image.inner().image.device().internal_object(),
36         device.internal_object()
37     );
38 
39     if !image.inner().image.usage().transfer_destination {
40         return Err(CheckClearColorImageError::MissingTransferUsage);
41     }
42 
43     if first_layer + num_layers > image.dimensions().array_layers() {
44         return Err(CheckClearColorImageError::OutOfRange);
45     }
46 
47     if first_mipmap + num_mipmaps > image.mipmap_levels() {
48         return Err(CheckClearColorImageError::OutOfRange);
49     }
50 
51     Ok(())
52 }
53 
54 /// Error that can happen from `check_clear_color_image`.
55 #[derive(Debug, Copy, Clone)]
56 pub enum CheckClearColorImageError {
57     /// The image is missing the transfer destination usage.
58     MissingTransferUsage,
59     /// The array layers and mipmap levels are out of range.
60     OutOfRange,
61 }
62 
63 impl error::Error for CheckClearColorImageError {}
64 
65 impl fmt::Display for CheckClearColorImageError {
66     #[inline]
fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error>67     fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
68         write!(
69             fmt,
70             "{}",
71             match *self {
72                 CheckClearColorImageError::MissingTransferUsage => {
73                     "the image is missing the transfer destination usage"
74                 }
75                 CheckClearColorImageError::OutOfRange => {
76                     "the array layers and mipmap levels are out of range"
77                 }
78             }
79         )
80     }
81 }
82