• 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 /// Layout of an image.
11 ///
12 /// > **Note**: In vulkano, image layouts are mostly a low-level detail. You can ignore them,
13 /// > unless you use an unsafe function that states in its documentation that you must take care of
14 /// > an image's layout.
15 ///
16 /// In the Vulkan API, each mipmap level of each array layer is in one of the layouts of this enum.
17 ///
18 /// Unless you use some sort of high-level shortcut function, an image always starts in either
19 /// the `Undefined` or the `Preinitialized` layout.
20 /// Before you can use an image for a given purpose, you must ensure that the image in question is
21 /// in the layout required for that purpose. For example if you want to write data to an image, you
22 /// must first transition the image to the `TransferDstOptimal` layout. The `General` layout can
23 /// also be used as a general-purpose fit-all layout, but using it will result in slower operations.
24 ///
25 /// Transitioning between layouts can only be done through a GPU-side operation that is part of
26 /// a command buffer.
27 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
28 #[repr(i32)]
29 pub enum ImageLayout {
30     Undefined = ash::vk::ImageLayout::UNDEFINED.as_raw(),
31     General = ash::vk::ImageLayout::GENERAL.as_raw(),
32     ColorAttachmentOptimal = ash::vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL.as_raw(),
33     DepthStencilAttachmentOptimal = ash::vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL.as_raw(),
34     DepthStencilReadOnlyOptimal = ash::vk::ImageLayout::DEPTH_STENCIL_READ_ONLY_OPTIMAL.as_raw(),
35     ShaderReadOnlyOptimal = ash::vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL.as_raw(),
36     TransferSrcOptimal = ash::vk::ImageLayout::TRANSFER_SRC_OPTIMAL.as_raw(),
37     TransferDstOptimal = ash::vk::ImageLayout::TRANSFER_DST_OPTIMAL.as_raw(),
38     Preinitialized = ash::vk::ImageLayout::PREINITIALIZED.as_raw(),
39     PresentSrc = ash::vk::ImageLayout::PRESENT_SRC_KHR.as_raw(),
40 }
41 
42 impl From<ImageLayout> for ash::vk::ImageLayout {
43     #[inline]
from(val: ImageLayout) -> Self44     fn from(val: ImageLayout) -> Self {
45         Self::from_raw(val as i32)
46     }
47 }
48 
49 /// The set of layouts to use for an image when used in descriptor of various kinds.
50 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
51 pub struct ImageDescriptorLayouts {
52     /// The image layout to use in a descriptor as a storage image.
53     pub storage_image: ImageLayout,
54     /// The image layout to use in a descriptor as a combined image sampler.
55     pub combined_image_sampler: ImageLayout,
56     /// The image layout to use in a descriptor as a sampled image.
57     pub sampled_image: ImageLayout,
58     /// The image layout to use in a descriptor as an input attachment.
59     pub input_attachment: ImageLayout,
60 }
61