VPP  0.8
A high-level modern C++ API for Vulkan
vppImage.hpp
1 /*
2  Copyright 2016-2018 SOFT-ERG, Przemek Kuczmierczyk (www.softerg.com)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification,
6  are permitted provided that the following conditions are met:
7 
8  1. Redistributions of source code must retain the above copyright notice,
9  this list of conditions and the following disclaimer.
10 
11  2. Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 // -----------------------------------------------------------------------------
28 namespace vpp {
29 // -----------------------------------------------------------------------------
30 
54 class Img
55 {
56 public:
68  {
69  SOURCE = VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
70  TARGET = VK_IMAGE_USAGE_TRANSFER_DST_BIT,
71  SAMPLED = VK_IMAGE_USAGE_SAMPLED_BIT,
72  STORAGE = VK_IMAGE_USAGE_STORAGE_BIT,
73  COLOR = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
74  DEPTH = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
75  TRANSIENT = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT,
76  INPUT = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
77  };
78 
80  Img();
81 
111  Img (
112  const ImageInfo& imageInfo,
113  const MemProfile& memProfile,
114  const Device& hDevice,
115  VkImageLayout initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
116  const std::vector< unsigned int >& queueFamilyIndices = std::vector< unsigned int >() );
117 
142  Img (
143  const ImageInfo& imageInfo,
144  const Device& hDevice,
145  VkImage hImage );
146 
148  VkImage handle() const;
149 
151  bool valid() const;
152 
154  const Device& device() const;
155 
157  const ImageInfo& info() const;
158 
160  const VkExtent3D& extent() const;
161 
163  VkFormat format() const;
164 };
165 
166 // -----------------------------------------------------------------------------
167 
204 template<
205  class FormatT,
206  EImagePurpose PURPOSE,
207  EImageType TYPE,
208  unsigned int USAGE,
209  VkImageTiling TILING = VK_IMAGE_TILING_OPTIMAL,
210  VkSampleCountFlagBits MULTISAMPLING = VK_SAMPLE_COUNT_1_BIT,
211  bool MIPMAPPED = true,
212  bool ARRAYED = false,
213  unsigned int FLAGS = 0u >
215 {
216 };
217 
218 // -----------------------------------------------------------------------------
294 template< class AttributesT >
295 class Image : public Img
296 {
297 public:
299  typedef AttributesT attributes_type;
300 
302  typedef typename AttributesT::format_type format_type;
303 
305  Image();
306 
323  Image (
324  const VkExtent3D& extent,
325  const MemProfile& memProfile,
326  const Device& hDevice,
327  unsigned int mipLevels = 1u,
328  unsigned int arrayLevels = 1u,
329  VkImageLayout initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
330  const std::vector< unsigned int >& queueFamilyIndices = std::vector< unsigned int >() );
331 
358  Image (
359  VkFormat format,
360  const VkExtent3D& extent,
361  const MemProfile& memProfile,
362  const Device& hDevice,
363  unsigned int mipLevels = 1u,
364  unsigned int arrayLevels = 1u,
365  VkImageLayout initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
366  const std::vector< unsigned int >& queueFamilyIndices = std::vector< unsigned int >() );
367 
378  Image (
379  const VkExtent3D& extent,
380  const Device& hDevice,
381  VkImage hImage,
382  unsigned int mipLevels = 1u,
383  unsigned int arrayLevels = 1u );
384 
407  Image (
408  VkFormat format,
409  const VkExtent3D& extent,
410  const Device& hDevice,
411  VkImage hImage,
412  unsigned int mipLevels = 1u,
413  unsigned int arrayLevels = 1u );
414 
424  explicit Image ( const Img& rawImage );
425 };
426 
427 // -----------------------------------------------------------------------------
428 
429 template< class FormatT >
430 using ImgTexture1D = Image<
432  FormatT, RENDER, IMG_TYPE_1D,
433  VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT > >;
434 
435 template< class FormatT >
436 using ImgTexture2D = Image<
438  FormatT, RENDER, IMG_TYPE_2D,
439  VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT > >;
440 
441 template< class FormatT >
442 using ImgTexture3D = Image<
444  FormatT, RENDER, IMG_TYPE_3D,
445  VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT > >;
446 
447 template< class FormatT >
448 using ImgTextureCube = Image<
450  FormatT, RENDER, IMG_TYPE_CUBE_2D,
451  VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT > >;
452 
453 template< class FormatT >
454 using ImgStorage1D = Image<
456  FormatT, RENDER, IMG_TYPE_1D,
457  VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT > >;
458 
459 template< class FormatT >
460 using ImgStorage2D = Image<
462  FormatT, RENDER, IMG_TYPE_2D,
463  VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT > >;
464 
465 template< class FormatT >
466 using ImgStorage3D = Image<
468  FormatT, RENDER, IMG_TYPE_3D,
469  VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT > >;
470 
471 template< class FormatT >
472 using ImgStorageCube = Image<
474  FormatT, RENDER, IMG_TYPE_CUBE_2D,
475  VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT > >;
476 
477 template< class FormatT >
478 using ImgAttachment2D = Image<
480  FormatT, RENDER, IMG_TYPE_2D,
481  VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT > >;
482 
483 template< class FormatT >
486  FormatT, RENDER, IMG_TYPE_2D,
487  VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT > >;
488 
489 // -----------------------------------------------------------------------------
490 } // namespace vpp
491 // -----------------------------------------------------------------------------
Represents logical rendering device.
Definition: vppDevice.hpp:49
bool valid() const
Checks whether this is a valid image.
const VkExtent3D & extent() const
Retrieves image size.
VkImage handle() const
Retrieves the Vulkan handle.
Class representing generic (untyped) Vulkan image.
Definition: vppImage.hpp:54
A structure containing image parameters.
Definition: vppImageInfo.hpp:64
Allows to use an image as a destination of transfer or blit operation.
Definition: vppImage.hpp:70
The VPP namespace.
Definition: main.hpp:1
Img()
Constructs null reference.
Allows to use an image as a source of transfer or blit operation.
Definition: vppImage.hpp:69
AttributesT attributes_type
Image attributes.
Definition: vppImage.hpp:299
A template containing image attributes inside C++ type.
Definition: vppImage.hpp:214
Allows to use an image as an attachment, to be used in a rendering process.
Definition: vppImage.hpp:73
Allows to use an image as an input attachment, to provide data for a rendering process.
Definition: vppImage.hpp:76
Image()
Constructs null reference.
Allows to use an image as an attachment, to be used in a rendering process as depth buffer...
Definition: vppImage.hpp:74
AttributesT::format_type format_type
Image format.
Definition: vppImage.hpp:302
VkFormat format() const
Retrieves image format.
All images used for normal rendering.
Definition: vppImageInfo.hpp:37
const ImageInfo & info() const
Retrieves all image attributes.
Allows to optimize memory allocation for an attachment image.
Definition: vppImage.hpp:75
Class representing typed Vulkan image.
Definition: vppImage.hpp:295
Allows to use an image as a read-only texture.
Definition: vppImage.hpp:71
Abstraction of GPU-interoperable memory types.
Definition: vppDeviceMemory.hpp:39
EImagePurpose
Enumeration specifying general purpose of an image.
Definition: vppImageInfo.hpp:35
EUsageFlags
Enumeration specifying how an image may be used.
Definition: vppImage.hpp:67
const Device & device() const
Retrieves the device.
Allows to use an image as a mutable image (writable in the shader).
Definition: vppImage.hpp:72